/* ===========================================================
   alpaca.teinba.com — Dashboard Ordini Alpaca
   Stesso look&feel "financial" di alert.teinba.com:
   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;
  --orange: #D97A1A;
  --orange-bg: #FDF0E1;
  --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);
}

/* Sfondo pagina colorato in base all'ambiente attivo, per riconoscere subito
   a colpo d'occhio se si sta operando in Paper (demo) o Live (denaro reale).
   La topbar resta invariata (blu istituzionale) in entrambi i casi. */
body.env-paper {
  background: #FFF9E3;
}
body.env-live {
  background: #E8F8EE;
}

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

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

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

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

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

.env-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-left: 6px;
  vertical-align: middle;
}
.env-badge.paper { background: rgba(234,179,8,0.18); color: #F4C430; border: 1px solid #F4C430; }
.env-badge.live { background: rgba(229,57,53,0.18); color: #FF6B6B; border: 1px solid #FF6B6B; }

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

/* Fallback esplicito per renderer che non supportano bene "gap" sui figli
   diretti in flex (es. wkhtmltoimage/WebKit datato) */
.topbar-right > * {
  margin-right: 16px;
}
.topbar-right > *:last-child {
  margin-right: 0;
}

/* ---------- Status Account chip nella topbar ---------- */
.account-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  color: var(--white);
  font-weight: 600;
}

.account-chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.account-chip .dot.dot-green { background: #34C759; }
.account-chip .dot.dot-red { background: #E53935; }

.notional-chip {
  font-size: 12.5px;
  color: #B9C6D6;
}
.notional-chip strong { color: var(--white); }

/* ---------- Bottoni azione critica (CLOSE ALL / STOP) nella topbar ---------- */
.action-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-btn {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
  font-family: var(--font);
}
.action-btn:hover { filter: brightness(1.1); }
.action-btn:active { transform: scale(0.97); }

.btn-close-all {
  background: #E53935;
  color: #FFFFFF;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15) inset;
}
.btn-close-all:hover { background: #FF3B30; }

.btn-stop {
  background: var(--orange);
  color: #FFFFFF;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15) inset;
}
.btn-stop:hover { background: #E8871E; }

.btn-stop.active {
  background: #F4C430;
  color: #16232F;
  box-shadow: 0 0 0 2px #FFFFFF inset, 0 0 10px rgba(244,196,48,0.7);
  animation: pulse-stop 1.8s infinite;
}

@keyframes pulse-stop {
  0%, 100% { box-shadow: 0 0 0 2px #FFFFFF inset, 0 0 6px rgba(244,196,48,0.5); }
  50% { box-shadow: 0 0 0 2px #FFFFFF inset, 0 0 14px rgba(244,196,48,0.9); }
}

/* Banner di avviso quando il flusso ordini e' fermo (STOP attivo) */
.stop-banner {
  max-width: 1340px;
  margin: 14px auto 0;
  padding: 12px 20px;
  background: #FFF6D8;
  border: 1px solid #F4C430;
  border-radius: 10px;
  color: #7A5B00;
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.stop-banner .dot-blink {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #D97A1A;
  animation: blink-dot 1s infinite;
  flex-shrink: 0;
}
@keyframes blink-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* ---------- SUMMARY BAR (5 box in una riga) ---------- */
.summary-bar {
  max-width: 1340px;
  margin: 24px auto 0;
  padding: 0 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.summary-card {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  padding: 16px 18px;
  border-left: 4px solid var(--blue-primary);
  flex: 1 1 0;
  min-width: 180px;
}

.summary-card .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-text);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-card .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.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.orange { border-left-color: var(--orange); }

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

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

/* ================= 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-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); }
}

/* ---------- TABLE CARD ---------- */
.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;
  display: flex;
  align-items: center;
}

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

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

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

table.positions-table {
  min-width: 900px;
}
table.positions-table.closed-table {
  min-width: 700px;
}
table.log-table {
  min-width: 640px;
}

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;
  white-space: nowrap;
}

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

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;
}

.strategy-cell {
  color: var(--gray-text);
  font-size: 12.5px;
  font-weight: 500;
}

.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;
}

.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); }

.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; }

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

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.status-pill.accepted,
.status-pill.filled { background: var(--green-bg); color: var(--green); }
.status-pill.pending,
.status-pill.new { background: var(--orange-bg); color: var(--orange); }
.status-pill.error,
.status-pill.rejected,
.status-pill.canceled { background: var(--red-bg); color: var(--red); }
.status-pill.other { background: #EEF1F5; color: var(--gray-text); }

.error-note {
  color: var(--red);
  font-size: 11px;
  margin-top: 2px;
  display: block;
}

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

/* ---------- FOOTER ---------- */
.footer {
  max-width: 1340px;
  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;
  flex-wrap: wrap;
  gap: 6px;
}

a { color: var(--blue-primary); }

/* ================= SWITCH PAPER/LIVE (predisposizione) ================= */
.env-switch-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 20px;
}
.env-switch-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-text);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.env-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  background: #EEF1F5;
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.env-switch-option {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: default;
  color: var(--gray-text);
  transition: all .15s ease;
}
.env-switch-option.active.paper {
  background: #F4C430;
  color: #5C4400;
}
.env-switch-option.active.live {
  background: var(--red);
  color: var(--white);
}
.env-switch-note {
  font-size: 11.5px;
  color: var(--gray-text);
}
.env-switch-note strong { color: var(--text-dark); }

/* ===========================================================
   RESPONSIVE / MOBILE
   =========================================================== */
@media (max-width: 1100px) {
  .summary-card {
    flex: 1 1 30%;
  }
}

@media (max-width: 900px) {
  .topbar-inner {
    padding: 14px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar-right {
    gap: 10px;
    font-size: 12px;
  }
  .summary-bar {
    padding: 0 16px;
    gap: 12px;
  }
  .summary-card {
    flex: 1 1 45%;
  }
  .container {
    padding: 16px;
  }
}

@media (max-width: 600px) {
  .topbar-inner {
    padding: 12px 14px;
  }
  .brand-text {
    font-size: 16px;
  }
  .summary-bar {
    padding: 0 12px;
    gap: 10px;
    margin-top: 16px;
  }
  .summary-card {
    flex: 1 1 100%;
    padding: 14px 16px;
  }
  .summary-card .value {
    font-size: 20px;
  }
  .container {
    padding: 12px;
  }
  .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;
  }
  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;
  }
}
