/* ===========================================================
   alert.teinba.com — Dashboard Posizioni TradingView
   Stile "financial": bianco dominante + blu istituzionale
   =========================================================== */

:root {
  --blue-dark: #0B2545;
  --blue-primary: #1565C0;
  --blue-light: #E8F1FC;
  --blue-accent: #2E86DE;
  --white: #FFFFFF;
  --gray-bg: #F5F7FA;
  --gray-border: #E3E8EF;
  --gray-text: #5A6B7B;
  --text-dark: #16232F;
  --green: #1D8348;
  --green-bg: #E9F7EF;
  --red: #C0392B;
  --red-bg: #FDEDEC;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--gray-bg);
  font-family: var(--font);
  color: var(--text-dark);
}

/* ---------- HEADER ---------- */
.topbar {
  background: var(--blue-dark);
  color: var(--white);
  padding: 0;
  border-bottom: 3px solid var(--blue-accent);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: var(--blue-accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: var(--white);
}

.brand-text {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.brand-text span {
  color: var(--blue-accent);
  font-weight: 400;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 13px;
  color: #B9C6D6;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--white);
}

.user-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ECC71;
}

/* ---------- SUMMARY BAR ---------- */
.summary-bar {
  max-width: 1340px;
  margin: 24px auto 0;
  padding: 0 28px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.summary-card {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  padding: 18px 20px;
  border-left: 4px solid var(--blue-primary);
}

.summary-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--gray-text);
  margin-bottom: 6px;
}

.summary-card .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-dark);
}

.summary-card.green { border-left-color: var(--green); }
.summary-card.green .value { color: var(--green); }
.summary-card.red { border-left-color: var(--red); }
.summary-card.red .value { color: var(--red); }

.summary-card .value-secondary {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-text);
  margin-top: 2px;
}
.summary-card.green .value-secondary { color: var(--green); opacity: 0.85; }
.summary-card.red .value-secondary { color: var(--red); opacity: 0.85; }

/* ---------- STATUS BAR (Status Sistema + Messaggi Processati) ---------- */
.status-bar {
  max-width: 1340px;
  margin: 24px auto 0;
  padding: 0 28px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.status-card {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  padding: 18px 20px;
  border-left: 4px solid var(--blue-primary);
}

.status-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--gray-text);
  margin-bottom: 8px;
}

.status-value {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-word {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--text-dark);
}

.status-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--gray-text);
}

/* dot indicatore */
.status-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green {
  background: #34C759;
  box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.6);
  animation: dot-pulse-green 2s infinite;
}

.dot-red {
  background: #E53935;
  box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.6);
  animation: dot-pulse-red 1s infinite;
}

@keyframes dot-pulse-green {
  0%   { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(52, 199, 89, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0); }
}

@keyframes dot-pulse-red {
  0%   { box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(229, 57, 53, 0); }
  100% { box-shadow: 0 0 0 0 rgba(229, 57, 53, 0); }
}

/* colorazione box status */
.status-card.ok { border-left-color: #34C759; }
.status-card.ok .status-word { color: #1E7E34; }
.status-card.error {
  border-left-color: #E53935;
  background: linear-gradient(135deg, #FEF3F3 0%, #FFFFFF 60%);
}
.status-card.error .status-word { color: #B71C1C; }
.status-card.neutral { border-left-color: var(--blue-primary); }

/* ---------- CONTAINER ---------- */
.container {
  max-width: 1340px;
  margin: 0 auto;
  padding: 28px;
}

/* ---------- SECTION ---------- */
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 32px 0 14px;
}

.section-title h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--blue-dark);
  margin: 0;
}

.section-title .icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  background: var(--blue-light);
  color: var(--blue-primary);
}

.asset-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.asset-tab {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--gray-border);
  background: var(--white);
  color: var(--gray-text);
}

.asset-tab.active {
  background: var(--blue-primary);
  border-color: var(--blue-primary);
  color: var(--white);
}

/* ---------- TABLE CARD ---------- */
.email-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.email-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--blue-accent, #2E86DE);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}
.email-btn:hover:not(:disabled) {
  background: #256FBF;
}
.email-btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.email-icon {
  font-size: 14px;
}
.email-status {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--gray-text, #667);
}
.email-status.success {
  color: #1E8E3E;
}
.email-status.error {
  color: #C62828;
}

.table-card {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 22px;
  box-shadow: 0 1px 3px rgba(16, 42, 67, 0.04);
}

.table-card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--blue-light);
}

.table-card-header .title {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table-card-header .count {
  font-size: 12px;
  color: var(--blue-primary);
  font-weight: 600;
  background: var(--white);
  padding: 3px 10px;
  border-radius: 12px;
}

/* Wrapper che permette lo scroll orizzontale della tabella su schermi piccoli
   senza rompere gli angoli arrotondati/overflow del .table-card. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

/* Layout fisso: le colonne AZIONI e CRYPTO restano allineate verticalmente
   anche se il contenuto (es. ticker "ADAUSDT" vs "MN") ha lunghezza diversa.
   min-width garantisce leggibilità: sotto quella soglia il wrapper
   .table-scroll attiva lo scroll orizzontale invece di comprimere le colonne. */
table.positions-table {
  table-layout: fixed;
  min-width: 900px;
}

table.positions-table.closed-table {
  min-width: 560px;
}

table.log-table {
  min-width: 640px;
}

table.positions-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.positions-table td.ticker-cell {
  overflow: visible;
}

table.positions-table th {
  white-space: nowrap;
}

thead th {
  background: var(--white);
  color: var(--gray-text);
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--gray-border);
  font-weight: 700;
}

thead th.num { text-align: right; }

th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover {
  color: var(--blue-primary);
}
.sort-arrow {
  font-size: 9px;
  margin-left: 3px;
  display: inline-block;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-border);
  color: var(--text-dark);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFBFD; }

tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }

.ticker-cell {
  font-weight: 700;
  color: var(--blue-dark);
  white-space: nowrap;
  overflow: visible;
}

.strategy-tag {
  display: block;
  font-size: 11px;
  color: var(--gray-text);
  font-weight: 400;
  margin-top: 2px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.badge-buy { background: var(--green-bg); color: var(--green); }
.badge-sell { background: var(--red-bg); color: var(--red); }
.badge-strong {
  background: #FFC107;
  color: #5C4400;
  white-space: nowrap;
}

/* Riga evidenziata: titolo con 2+ segnali concordanti nella stessa direzione
   da strategie diverse (STRONG BUY / STRONG SELL). */
tr.row-strong {
  background: #FFF9E0;
}
tr.row-strong:hover {
  background: #FFF3C4;
}
tr.row-strong td {
  border-bottom-color: #FCE9A8;
}

/* Riga "extra" di un gruppo STRONG (posizione storica che ha contribuito
   al segnale forte): nascosta di default, mostrata solo su espansione. */
tr.row-group-extra {
  background: #FFFDF3;
}
tr.row-group-extra td {
  border-bottom-color: #FCE9A8;
}

/* Badge nazionale a sinistra del ticker (IT/USA): usiamo un badge testuale
   colorato invece dell'emoji bandiera, che su molti sistemi/font non viene
   renderizzata come icona ma come testo "IT"/"US" senza colore. */
.flag-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.3px;
  vertical-align: middle;
}
.flag-badge.flag-it {
  background: var(--green-bg);
  color: var(--green);
}
.flag-badge.flag-us {
  background: var(--red-bg);
  color: var(--red);
}

/* Controllo per espandere/collassare le posizioni raggruppate sotto uno
   STRONG BUY/SELL: mostra quante righe aggiuntive sono nascoste. */
.expand-toggle {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 10px;
  background: #E8EEF7;
  color: var(--blue-primary);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  vertical-align: middle;
  white-space: nowrap;
}
.expand-toggle:hover {
  background: #D6E2F2;
}
.expand-toggle.expanded {
  background: #FCE9A8;
  color: #5C4400;
}

.perf {
  font-weight: 700;
}

.perf.positive { color: var(--green); }
.perf.negative { color: var(--red); }

.asset-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  margin-right: 8px;
  color: var(--white);
  vertical-align: middle;
}

.asset-icon.stock { background: var(--blue-primary); }
.asset-icon.crypto { background: #8E44AD; }

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--gray-text);
  font-size: 13px;
}

/* ---------- LOGIN PAGE ---------- */
.login-wrap {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--blue-dark) 0%, #123A6B 60%, #1B4C8C 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.login-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(120deg, rgba(255,255,255,0.03) 0px, rgba(255,255,255,0.03) 1px, transparent 1px, transparent 60px);
}

.login-card {
  position: relative;
  background: var(--white);
  border-radius: 14px;
  padding: 44px 48px;
  width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.login-logo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: var(--blue-primary);
  color: var(--white);
  font-weight: 700;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--blue-dark);
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--gray-text);
  margin-bottom: 26px;
}

.login-widget-holder {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

.login-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--red-bg);
  color: var(--red);
  border-radius: 8px;
  font-size: 12px;
}

.login-footer-note {
  margin-top: 24px;
  font-size: 11px;
  color: #9AABBB;
}

/* ---------- FOOTER ---------- */
.footer {
  max-width: 1180px;
  margin: 10px auto 30px;
  padding: 0 28px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--gray-text);
  border-top: 1px solid var(--gray-border);
  padding-top: 16px;
}

/* ---------- COLONNA STRATEGIA (Alert Name) ---------- */
.strategy-cell {
  color: var(--gray-text);
  font-size: 12.5px;
  font-weight: 500;
}

/* ---------- TAG TIMEFRAME ---------- */
.tf-tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  background: #E8F1FC;
  color: #1565C0;
  letter-spacing: 0.3px;
}

/* ================= TABS ================= */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  border-bottom: 2px solid var(--gray-border);
  flex-wrap: wrap;
}
.tab-btn {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-text);
  padding: 12px 20px;
  border-radius: 8px 8px 0 0;
  position: relative;
  bottom: -2px;
  border-bottom: 2px solid transparent;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tab-btn:hover {
  color: #1565C0;
  background: #F4F8FE;
}
.tab-btn.active {
  color: #0B2545;
  border-bottom-color: #1565C0;
  background: #E8F1FC;
}
.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: #D9E7F8;
  color: #1565C0;
  font-size: 12px;
  font-weight: 700;
}
.tab-btn.active .tab-count {
  background: #1565C0;
  color: #fff;
}

/* ---------- TAB PANELS ---------- */
.tab-panel {
  display: none;
  animation: fadeIn .2s ease;
}
.tab-panel.active {
  display: block;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ================= LOG TABLE ================= */
.log-table code {
  font-family: 'SFMono-Regular', Menlo, Consolas, 'Courier New', monospace;
  font-size: 12.5px;
  color: #0B2545;
  background: #F4F6F9;
  padding: 3px 8px;
  border-radius: 5px;
  display: inline-block;
  word-break: break-word;
  line-height: 1.5;
}
.log-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.log-ok {
  background: #E4F7EA;
  color: #1E8E3E;
}
.log-err {
  background: #FDE7E7;
  color: #C62828;
}
.log-info {
  background: #E8EEF9;
  color: #2C5CB0;
}
.log-date {
  font-size: 12.5px;
  color: var(--gray-text);
  white-space: nowrap;
}
.log-msg {
  max-width: 640px;
}
.log-note {
  margin-top: 6px;
  font-size: 12px;
  color: #C62828;
  font-weight: 600;
}
.log-note-info {
  color: #2C5CB0;
}

/* ===========================================================
   RESPONSIVE / MOBILE
   =========================================================== */

/* Tablet e schermi medi: da 4/3 colonne a 2 colonne nelle barre riepilogo */
@media (max-width: 900px) {
  .topbar-inner {
    padding: 14px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar-right {
    gap: 10px;
    font-size: 12px;
  }

  .status-bar {
    grid-template-columns: repeat(2, 1fr);
    padding: 0 16px;
    gap: 12px;
  }
  .summary-bar {
    grid-template-columns: repeat(2, 1fr);
    padding: 0 16px;
    gap: 12px;
  }
  .container {
    padding: 16px;
  }
}

/* Smartphone: tutte le card riepilogo diventano 1 colonna, impilate */
@media (max-width: 600px) {
  .topbar-inner {
    padding: 12px 14px;
  }
  .brand-text {
    font-size: 16px;
  }
  .topbar-right span {
    display: none; /* "Ultimo aggiornamento" nascosto: poco spazio su mobile */
  }
  .topbar-right {
    gap: 8px;
  }

  .status-bar,
  .summary-bar {
    grid-template-columns: 1fr;
    padding: 0 12px;
    gap: 10px;
    margin-top: 16px;
  }

  .status-card,
  .summary-card {
    padding: 14px 16px;
  }

  .status-word {
    font-size: 20px;
  }
  .summary-card .value {
    font-size: 22px;
  }

  .container {
    padding: 12px;
  }

  /* Tab: più compatte e su una riga scrollabile se necessario */
  .tabs {
    gap: 2px;
    margin-bottom: 16px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .tab-btn {
    padding: 10px 14px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .table-card-header {
    padding: 12px 14px;
  }
  .table-card-header .title {
    font-size: 12px;
  }

  /* Le tabelle scorrono in orizzontale invece di comprimersi: restano
     leggibili anche su schermi piccoli (l'utente può scrollare o ruotare
     il telefono in orizzontale per vedere tutte le colonne). */
  thead th {
    padding: 8px 10px;
    font-size: 10px;
  }
  tbody td {
    padding: 10px 10px;
    font-size: 12.5px;
  }

  .footer {
    padding: 0 14px;
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }
}
