:root {
  color-scheme: dark;
  --bg: #0a0d12;
  --panel: #121821;
  --panel-2: #18212d;
  --line: #273242;
  --text: #edf2f7;
  --muted: #8f9bad;
  --accent: #6ee7b7;
  --accent-2: #34d399;
  --danger: #fb7185;
  --warning: #fbbf24;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

/*
 * Garantisce che l'attributo HTML "hidden" prevalga
 * sulle regole display:grid, display:flex, ecc.
 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: radial-gradient(circle at top left, #14261f 0, var(--bg) 34%);
  color: var(--text);
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(430px, 100%);
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(18, 24, 33, 0.94);
  box-shadow: 0 24px 80px #0008;
}

.auth-card h1 {
  font-size: 2rem;
  line-height: 1.1;
  margin: 0.3rem 0 1rem;
}

.stack {
  display: grid;
  gap: 1rem;
}

.stack label,
.search {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.86rem;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0c1118;
  color: var(--text);
  padding: 0.75rem;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

.primary,
.ghost,
.tab,
.nav-item {
  border: 0;
  border-radius: 9px;
  padding: 0.72rem 1rem;
}

.primary {
  background: var(--accent);
  color: #07130f;
  font-weight: 800;
}

.primary:hover {
  background: var(--accent-2);
}

.ghost,
.tab,
.nav-item {
  background: transparent;
  color: var(--muted);
}

.ghost:hover,
.tab.active,
.nav-item.active,
.nav-item:hover {
  background: var(--panel-2);
  color: var(--text);
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  margin: 1.5rem 0;
}

.tab {
  border-radius: 8px 8px 0 0;
}

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--line);
  background: #0c1118e8;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  font-size: 1.2rem;
  font-weight: 900;
}

.environment {
  margin-left: 0.5rem;
  color: var(--accent);
  font-size: 0.7rem;
}

.account-strip {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.credit-pill {
  background: #193027;
  border: 1px solid #28543f;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  min-height: calc(100vh - 68px);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 1rem;
  background: #0c1118;
}

.sidebar nav {
  display: grid;
  gap: 0.35rem;
}

.nav-item {
  text-align: left;
}

.content {
  padding: 1.5rem;
  min-width: 0;
}

.panel-section {
  max-width: 1500px;
  margin: 0 auto;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.65rem;
}

.search {
  width: 220px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 0.78rem 0.85rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.84rem;
}

th {
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #101620;
  position: sticky;
  top: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.score {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.score.high {
  color: var(--accent);
}

.score.low {
  color: var(--danger);
}

.status {
  display: inline-block;
  padding: 0.25rem 0.48rem;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 0.7rem;
}

.status.completed {
  color: var(--accent);
}

.status.error {
  color: var(--danger);
}

.actions {
  display: flex;
  gap: 0.35rem;
}

.actions button:not(.icon-button) {
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
}

.cards {
  display: grid;
  gap: 1rem;
}

.watchlist-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 1rem;
}

.watchlist-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.watchlist-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.ticker-chip {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  background: var(--panel-2);
  border-radius: 999px;
  padding: 0.4rem 0.65rem;
}

.ticker-chip button {
  border: 0;
  background: transparent;
  color: var(--danger);
  padding: 0;
}

.inline-form {
  display: flex;
  gap: 0.5rem;
}

.inline-form input {
  min-width: 220px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  width: min(450px, calc(100% - 2rem));
}

dialog::backdrop {
  background: #000b;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  max-width: 380px;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px #0008;
}

.toast.error {
  border-color: var(--danger);
}

#dashboard-table {
  table-layout: auto;
  width: 100%;
}

#dashboard-table th,
#dashboard-table td {
  vertical-align: middle;
}

#dashboard-table th {
  padding: 0;
}

#dashboard-table td {
  padding: 0.76rem 0.72rem;
  font-size: 0.9rem;
}

#dashboard-table th:first-child,
#dashboard-table td:first-child {
  width: 72px;
  min-width: 72px;
}

#dashboard-table .ticker-cell {
  font-weight: 800;
}

#dashboard-table .company-column,
#dashboard-table .company-cell {
  width: 170px;
  min-width: 140px;
  max-width: 170px;
}

#dashboard-table .company-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#dashboard-table .price-column,
#dashboard-table .price-cell {
  width: 90px;
  min-width: 90px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#dashboard-table .score-column,
#dashboard-table .score-cell {
  width: 112px;
  min-width: 112px;
  text-align: center;
}

#dashboard-table .actions-column,
#dashboard-table .actions {
  width: 88px;
  min-width: 88px;
  text-align: center;
}

.sort-button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.68rem 0.72rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.sort-button:hover,
.sort-button.active {
  background: var(--panel-2);
  color: var(--text);
}

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

.company-column .sort-button {
  justify-content: flex-start;
}

.price-column .sort-button {
  justify-content: flex-end;
}

.score-column .sort-button {
  justify-content: center;
}

.sort-indicator {
  min-width: 0.65rem;
  color: var(--accent);
  font-size: 0.57rem;
}

.score-cell {
  font-variant-numeric: tabular-nums;
}

.score-cell .score {
  display: block;
  font-size: 0.94rem;
  line-height: 1.05;
}

.score-date {
  display: block;
  min-height: 0.65rem;
  margin-top: 0.26rem;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  overflow: visible;
}

.icon-button {
  position: relative;
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  border-color: var(--accent);
  background: var(--panel-2);
  color: var(--accent);
}

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

.icon-button svg {
  display: block;
  pointer-events: none;
}

.action-tooltip {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 30;
  width: max-content;
  max-width: 220px;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #070b10;
  color: var(--text);
  box-shadow: 0 8px 25px #000a;
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.2;
  text-transform: none;
  letter-spacing: normal;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease,
    visibility 120ms ease;
}

.icon-button:hover .action-tooltip,
.icon-button:focus-visible .action-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

@media (max-width: 850px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0.5rem;
  }

  .sidebar nav {
    display: flex;
    overflow: auto;
  }

  .content {
    padding: 1rem;
  }

  .topbar {
    height: auto;
    min-height: 68px;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
  }

  .account-strip {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .account-strip #user-email {
    display: none;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }

  .inline-form {
    width: 100%;
  }

  .inline-form input {
    min-width: 0;
  }

  .auth-card {
    padding: 1.4rem;
  }
}