:root {
  color-scheme: dark;
  --bg: #131722;
  --panel: #1a1e2a;
  --panel-2: #20253280;
  --border: #2a2e39;
  --text: #d9dce4;
  --muted: #8b90a0;
  --accent: #4c8dff;
  --accent-text: #0b1020;
  --up: #26a69a;
  --down: #ef5350;
  --wl-bull: #3987e5;
  --wl-bear: #d95926;
  --ok: #2bb673;
  --warn: #e0a030;
  --bad: #ef5350;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panel-2: #f0f2f680;
    --border: #dfe2ea;
    --text: #161a25;
    --muted: #646a7a;
    --accent: #1f5fe0;
    --accent-text: #ffffff;
    --up: #089981;
    --down: #e0393e;
    --wl-bull: #2a78d6;
    --wl-bear: #eb6834;
    --ok: #12905a;
    --warn: #a8700c;
    --bad: #d0282d;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f0f2f680;
  --border: #dfe2ea;
  --text: #161a25;
  --muted: #646a7a;
  --accent: #1f5fe0;
  --accent-text: #ffffff;
  --up: #089981;
  --down: #e0393e;
  --wl-bull: #2a78d6;
  --wl-bear: #eb6834;
  --ok: #12905a;
  --warn: #a8700c;
  --bad: #d0282d;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.mono {
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ pulsanti e campi */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--muted);
}

.btn:focus-visible,
input:focus-visible,
select:focus-visible,
.tab:focus-visible,
.chart-head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
}

.btn[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

.pill.ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
}

.pill.warn {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 45%, transparent);
}

/* ------------------------------------------------------------------ accesso */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.login-card h1 {
  font-size: 22px;
}

.login-card input {
  padding: 10px;
}

.login-card .btn {
  padding: 10px;
  margin-top: 6px;
}

.error {
  margin: 0;
  color: var(--bad);
}

/* ------------------------------------------------------------------ struttura */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  white-space: nowrap;
}

.brand svg {
  width: 20px;
  height: 20px;
  fill: var(--wl-bull);
  stroke: var(--wl-bull);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-right: auto;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
}

#feedText {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

#countdown {
  flex: none;
}

.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.ok {
  background: var(--ok);
}

.dot.warn {
  background: var(--warn);
}

.dot.bad {
  background: var(--bad);
}

.actions {
  display: flex;
  gap: 6px;
}

.tabs {
  display: none;
  gap: 4px;
  padding: 6px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.app.focus .tabs {
  display: flex;
}

.tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.tab[aria-current="true"] {
  color: var(--text);
  border-color: var(--border);
  background: var(--bg);
}

.tab .mark {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
}

.charts {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 1px;
  background: var(--border);
  overflow: hidden;
}

.chart {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app.focus .charts {
  grid-template-columns: minmax(0, 1fr);
}

.app.focus .chart:not(.current) {
  display: none;
}

.chart-head {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 10px;
  padding: 6px 10px 2px;
  cursor: pointer;
}

.chart-head .sym {
  font-weight: 700;
  font-size: 14px;
}

.chart-head .price {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.chart-head .chg {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.chart-head .chg.up {
  color: var(--up);
}

.chart-head .chg.down {
  color: var(--down);
}

.chart-head .stats {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin: 0 3px 0 8px;
}

.swatch.bull {
  background: var(--wl-bull);
}

.swatch.bear {
  background: var(--wl-bear);
}

.chart-legend {
  min-height: 18px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-legend b {
  color: var(--text);
  font-weight: 500;
}

.chart-legend .tag {
  margin-left: 8px;
  font-weight: 600;
}

.chart-legend .tag.bull {
  color: var(--wl-bull);
}

.chart-legend .tag.bear {
  color: var(--wl-bear);
}

.chart-body {
  flex: 1;
  min-height: 0;
  position: relative;
}

.chart-body .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}

/* ------------------------------------------------------------------ calcolo dell'ordine */
.main-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.main-col .charts {
  flex: 1;
}

.ticket {
  flex: none;
  max-height: 55%;
  overflow-y: auto;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.app:not(.focus) .ticket {
  display: none;
}

.ticket-start,
.ticket-guide {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.ticket-start .muted {
  flex: 1 1 220px;
  font-size: 13px;
}

.ticket-guide .guide-text {
  flex: 1 1 200px;
  font-weight: 600;
}

.step {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Mentre si indicano i prezzi il cursore è un mirino: ogni tocco fissa un prezzo. */
.chart-body.placing * {
  cursor: crosshair !important;
}

.btn.buy {
  border-color: var(--up);
  color: var(--up);
  font-weight: 600;
}

.btn.sell {
  border-color: var(--down);
  color: var(--down);
  font-weight: 600;
}

.ticket-form {
  display: grid;
  gap: 8px;
}

.ticket-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ticket-head {
  flex-wrap: wrap;
}

.ticket-head strong {
  margin-right: auto;
}

.ticket-head strong.buy {
  color: var(--up);
}

.ticket-head strong.sell {
  color: var(--down);
}

.ticket-fields {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.ticket-fields label {
  display: grid;
  gap: 3px;
  font-size: 12px;
  color: var(--muted);
}

.ticket-fields input {
  width: 100%;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.ticket-out {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 6px;
}

.copy {
  appearance: none;
  display: grid;
  gap: 1px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
}

.copy:hover {
  border-color: var(--muted);
}

.copy:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.copy small {
  font-size: 11px;
  color: var(--muted);
}

.copy b {
  font-size: 16px;
  font-weight: 600;
}

.copy.lots b {
  font-size: 20px;
}

.ticket-sum {
  flex-basis: 100%;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ticket-msgs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.ticket-msgs:empty {
  display: none;
}

.ticket-msgs li {
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 13px;
  background: color-mix(in srgb, var(--bad) 16%, transparent);
}

.ticket-msgs li.warning {
  background: color-mix(in srgb, var(--warn) 18%, transparent);
}

/* Mentre si prepara un ordine il dito sul grafico sposta le linee, non la pagina. */
.chart-body.drafting,
.chart-body.drafting * {
  touch-action: none !important;
}

.chart-body.over-line * {
  cursor: ns-resize !important;
}

/* ------------------------------------------------------------------ notizie ad alto impatto */
.newsbar {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bad) 10%, var(--panel));
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
  overflow-x: auto;
  cursor: pointer;
  scrollbar-width: none;
}

.newsbar::-webkit-scrollbar {
  display: none;
}

.newsbar-title {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
}

.news-chip {
  flex: none;
  color: var(--muted);
}

.news-chip.hit {
  color: var(--text);
}

.news-chip b {
  font-variant-numeric: tabular-nums;
}

.news-chip.hit b {
  color: var(--bad);
}

.news-chip.out {
  opacity: 0.7;
}

.news-chip + .news-chip {
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.head-news {
  padding: 0 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bad) 20%, transparent);
  color: var(--bad);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.head-news.out {
  opacity: 0.7;
}

.chart-legend .tag.news {
  color: var(--bad);
}

.news {
  flex: none;
  max-height: 42%;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
}

.news-list {
  list-style: none;
  margin: 0;
  padding: 0 0 4px;
  overflow-y: auto;
}

.news-day {
  padding: 6px 12px 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.news-item {
  display: grid;
  grid-template-columns: 44px 36px 1fr;
  align-items: baseline;
  gap: 0 6px;
  padding: 3px 12px;
  font-size: 13px;
}

.news-item .time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.news-item .cur {
  font-weight: 700;
  color: var(--bad);
}

.news-item.holiday .cur {
  color: var(--muted);
}

.news-item .detail {
  grid-column: 3;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.news-item.past {
  opacity: 0.55;
}

.pill.bad {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
}

button.pill {
  appearance: none;
  background: transparent;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

button.pill:hover {
  border-color: var(--muted);
}

/* ------------------------------------------------------------------ registro alert */
.alerts {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--panel);
}

.alerts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.alerts-head h2 {
  font-size: 14px;
}

.alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.alert {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 2px 8px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.alert:hover {
  background: var(--panel-2);
}

.alert.fresh {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.alert .arrow.bull {
  color: var(--wl-bull);
}

.alert .arrow.bear {
  color: var(--wl-bear);
}

.alert .sym {
  font-weight: 700;
}

.alert .time {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.alert .detail {
  grid-column: 2 / 4;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.alert .state {
  font-weight: 600;
}

.alert .state.sent {
  color: var(--ok);
}

.alert .state.revoked {
  color: var(--warn);
}

.empty {
  padding: 16px 12px;
  margin: 0;
}

/* ------------------------------------------------------------------ impostazioni */
.sheet {
  width: min(560px, 100vw);
  max-height: min(92vh, 100dvh);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
}

.sheet[open] {
  display: flex;
  flex-direction: column;
}

.sheet::backdrop {
  background: #0009;
}

.sheet-head,
.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.sheet-head {
  border-bottom: 1px solid var(--border);
}

.sheet-head h2 {
  font-size: 16px;
}

.sheet-foot {
  border-top: 1px solid var(--border);
}

.sheet-foot p {
  margin: 0;
}

.sheet-body {
  overflow-y: auto;
  padding: 4px 16px 12px;
}

.sheet-body section {
  display: grid;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.sheet-body section:last-child {
  border-bottom: 0;
}

.sheet-body h3 {
  font-size: 14px;
}

.sheet-body p {
  margin: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.inline input[type="number"] {
  width: 72px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.windows {
  display: grid;
  gap: 8px;
}

.window {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.days {
  display: flex;
  gap: 3px;
}

.day {
  appearance: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.day[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.window .hours {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.window .remove {
  margin-left: auto;
}

/* La settimana a colpo d'occhio: una riga per giorno, 24 ore da sinistra a destra. */
.week {
  display: grid;
  gap: 3px;
}

.week-row,
.week-axis {
  display: grid;
  grid-template-columns: 16px 1fr;
  align-items: center;
  gap: 8px;
}

.week-axis div {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.week-day {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.week-track {
  position: relative;
  height: 10px;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.week-track i {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent);
}

.check.indent {
  margin-left: 24px;
}

.sheet-body input[type="time"] {
  min-width: 96px;
}

.sheet-body .row input[type="number"] {
  width: 64px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  appearance: none;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.note {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  overflow-wrap: anywhere;
}

.note a {
  color: var(--accent);
}

.note code {
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(480px, calc(100vw - 32px));
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 6px 24px #0006;
  z-index: 20;
}

/* ------------------------------------------------------------------ schermi stretti */
.only-narrow {
  display: none;
}

@media (max-width: 1100px) {
  .charts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .only-narrow {
    display: inline-block;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .alerts {
    display: none;
    border-left: 0;
  }

  .app.show-alerts .alerts {
    display: flex;
  }

  .app.show-alerts .main-col {
    display: none;
  }

  .ticket-fields {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .news {
    max-height: 50%;
  }

  .charts {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: 300px;
    overflow-y: auto;
  }

  .app.focus .charts {
    grid-auto-rows: minmax(0, 1fr);
    overflow: hidden;
  }

  .status .muted,
  .status .sep {
    display: none;
  }

  .topbar {
    gap: 8px;
  }

  .btn {
    padding: 7px 9px;
  }
}

@media (max-width: 480px) {
  .brand span {
    display: none;
  }

  #viewToggle {
    display: none;
  }

  .sheet {
    width: 100vw;
    max-width: 100vw;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
    margin: 0;
  }
}
