:root {
  --bg: #0a0f18;
  --surface: #121a2b;
  --surface-2: #1a2540;
  --border: #2a3a5c;
  --text: #eef3ff;
  --text-muted: #9aa8cc;
  --accent: #3d7cff;
  --accent-hover: #528bff;
  --positive: #2fd8a3;
  --negative: #ff8a9d;
  --warn: #ffd267;
  --radius: 12px;
  --tap: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
}

@media (max-width: 719px) {
  :root {
    --radius: 8px;
    --tap: 40px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 14px 28px;
}

.top-nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.top-nav a {
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
}

.top-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--accent);
}

.page-header {
  margin-bottom: 12px;
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 4.5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
  max-width: 42ch;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

@media (max-width: 719px) {
  .container {
    padding: 6px 8px 12px;
  }

  .page-header {
    margin-bottom: 6px;
  }

  h1 {
    font-size: 1.125rem;
    margin-bottom: 2px;
  }

  .subtitle {
    font-size: 0.75rem;
    line-height: 1.3;
    max-width: none;
  }

  .card {
    padding: 8px 10px;
  }
}

/* —— Linguetta form —— */
.form-panel {
  margin-bottom: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.form-panel > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.form-panel > summary::-webkit-details-marker {
  display: none;
}

.form-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 10px 16px;
  background: linear-gradient(180deg, #243056 0%, var(--surface-2) 100%);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

@media (max-width: 719px) {
  .form-panel {
    margin-bottom: 8px;
  }

  .form-tab {
    gap: 8px;
    min-height: 40px;
    padding: 6px 10px;
    font-size: 0.8125rem;
  }

  .form-drawer {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .form-grid {
    gap: 10px;
  }

  label {
    gap: 3px;
    font-size: 0.625rem;
  }

  input {
    min-height: 40px;
    padding: 8px 10px;
    border-radius: 8px;
  }

  .btn {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 0.875rem;
    border-radius: 8px;
  }
}

.form-tab__chevron {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.form-panel[open] .form-tab__chevron {
  transform: rotate(45deg);
  margin-top: -4px;
}

.form-tab__label {
  flex: 1;
}

.form-drawer {
  border: none;
  border-radius: 0;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  padding-bottom: 16px;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid label.form-field--wide {
    grid-column: span 2;
  }

  .form-actions {
    grid-column: span 2;
  }
}

@media (min-width: 960px) {
  .form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
  }

  .form-grid label.form-field--wide {
    grid-column: span 2;
  }

  .form-actions {
    grid-column: span 1;
    justify-self: stretch;
  }
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

label input {
  text-transform: none;
  font-weight: 500;
  letter-spacing: normal;
}

input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: #0d1424;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-actions {
  display: flex;
  align-items: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

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

.btn--primary:active {
  transform: scale(0.98);
}

@media (min-width: 720px) {
  .btn--primary {
    width: auto;
    min-width: 140px;
  }
}

.btn--block-sm {
  width: 100%;
}

@media (min-width: 640px) {
  .btn--block-sm {
    width: auto;
    min-width: 160px;
  }
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

@media (max-width: 719px) {
  .toolbar {
    gap: 6px;
    margin-bottom: 8px;
    padding: 8px 10px;
  }

  .toolbar--sticky {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  }

  .toolbar__status {
    font-size: 0.6875rem;
    line-height: 1.25;
  }
}

@media (min-width: 640px) {
  .toolbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.toolbar--sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.toolbar__status {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  word-break: break-word;
}

@media (min-width: 640px) {
  .toolbar__status {
    text-align: right;
    max-width: 55%;
  }
}

.table-wrap {
  padding: 0;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.watchlist-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.watchlist-table th,
.watchlist-table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.watchlist-table th {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.watchlist-table tbody tr:hover {
  background: rgba(61, 124, 255, 0.06);
}

.watchlist-table a {
  color: #9ec5ff;
  font-weight: 600;
  text-decoration: none;
  word-break: break-word;
}

.watchlist-table a:hover {
  text-decoration: underline;
}

.ext-link-line {
  margin-top: 4px;
  font-size: 0.75rem;
}

.pre-market-line {
  margin-top: 4px;
  font-size: 0.75rem;
  line-height: 1.25;
  color: var(--text-muted);
}

.current-price-cell .now-price {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.current-price-cell .now-price__label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.current-price-cell .price-now {
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.positive {
  color: var(--positive);
  font-weight: 600;
}

.negative {
  color: var(--negative);
  font-weight: 600;
}

.error {
  color: var(--warn);
  font-size: 0.8125rem;
  margin-top: 6px;
  line-height: 1.35;
}

@media (max-width: 719px) {
  .error {
    font-size: 0.6875rem;
    margin-top: 4px;
    line-height: 1.25;
  }
}

.inline-edit {
  width: 100%;
  max-width: 120px;
  min-height: 44px;
  padding: 10px 8px;
  font-size: 16px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-actions .btn {
  min-height: 44px;
  padding: 10px 14px;
  font-size: 0.875rem;
}

@media (max-width: 719px) {
  .inline-edit {
    min-height: 38px;
    padding: 6px 8px;
  }

  .row-actions {
    gap: 6px;
  }

  .row-actions .btn {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 0.75rem;
  }
}

.save-btn {
  background: #2a6fd6;
  color: #fff;
}

.delete-btn {
  background: transparent;
  color: var(--negative);
  border: 1px solid var(--border);
}

.delete-btn:hover {
  border-color: var(--negative);
  background: rgba(255, 138, 157, 0.08);
}

/* —— Card layout mobile (leggibile, niente tabella schiacciata) —— */
@media (max-width: 719px) {
  .table-scroll {
    overflow-x: visible;
  }

  .watchlist-table {
    min-width: 0;
  }

  .watchlist-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .watchlist-table tbody tr {
    display: block;
    margin-bottom: 8px;
    padding: 8px 8px 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }

  .watchlist-table tbody td {
    display: grid;
    grid-template-columns: minmax(76px, 32%) 1fr;
    gap: 4px 8px;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid rgba(42, 58, 92, 0.45);
    font-size: 0.875rem;
    line-height: 1.25;
  }

  .watchlist-table tbody td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  .watchlist-table tbody td::before {
    content: attr(data-label);
    font-size: 0.5625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    line-height: 1.15;
  }

  .watchlist-table tbody td.row-actions-cell {
    grid-template-columns: 1fr;
    padding-top: 6px;
  }

  .watchlist-table tbody td.row-actions-cell::before {
    display: none;
  }

  .inline-edit {
    max-width: none;
  }

  .row-actions {
    width: 100%;
  }

  .row-actions .btn {
    flex: 1;
    min-width: calc(50% - 4px);
  }
}

.currency-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

.currency-pill--usd {
  background: #14301f;
  color: #6dcea0;
}

.currency-pill--fx {
  background: #3a2410;
  color: #e0a85c;
}
