/* ─────────────────────────────────────────
   DESIGN TOKENS
───────────────────────────────────────── */
:root {
  --bg:          #080d1a;
  --bg-card:     #0d1526;
  --bg-sidebar:  #060b16;
  --bg-hover:    #111e35;
  --bg-input:    #0a1020;
  --border:      #1a2d4a;
  --border-light:#243d5e;

  --text:        #c8d6e8;
  --text-muted:  #5c7a99;
  --text-dim:    #384f68;

  --accent:      #2d7af0;
  --accent-glow: rgba(45,122,240,0.15);
  --positive:    #00c896;
  --negative:    #ff4254;
  --warning:     #f0a22d;
  --info:        #38bdf8;

  --sidebar-w:   240px;
  --topbar-h:    56px;
  --radius:      8px;
  --radius-lg:   12px;
}

/* ─────────────────────────────────────────
   RESET & BASE
───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; cursor: pointer; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
select option { background: var(--bg-card); }

/* ─────────────────────────────────────────
   LAYOUT
───────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
}

/* ─────────────────────────────────────────
   SIDEBAR
───────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  font-family: 'Syne', sans-serif;
  font-size: 15px;
  letter-spacing: -0.2px;
}
.logo-icon {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}
.logo-text { color: var(--text-muted); }
.logo-text strong { color: var(--text); font-weight: 700; }

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section-label {
  padding: 14px 20px 4px;
  font-size: 10px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-dim);
  font-family: 'Syne', sans-serif;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  font-size: 13.5px;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  transition: all .15s;
  cursor: pointer;
}
.nav-item:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.nav-item.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
}
.nav-item .nav-icon {
  width: 16px;
  text-align: center;
  font-size: 13px;
  opacity: .7;
}
.nav-item.nav-add {
  color: var(--text-dim);
  font-size: 12px;
}
.nav-item.nav-add:hover { color: var(--accent); }

.sidebar-footer {
  padding: 16px 14px;
  border-top: 1px solid var(--border);
}

.btn-refresh {
  width: 100%;
  padding: 9px 14px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all .15s;
}
.btn-refresh:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}
.refresh-status {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  min-height: 16px;
}

/* ─────────────────────────────────────────
   MAIN AREA
───────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title {
  font-family: 'Syne', sans-serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  flex: 1;
}

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

.menu-toggle {
  display: none;
  font-size: 18px;
  color: var(--text-muted);
  padding: 4px 8px;
}

.content-area {
  padding: 24px;
  flex: 1;
}

/* ─────────────────────────────────────────
   CARDS
───────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text);
}

/* ─────────────────────────────────────────
   DASHBOARD
───────────────────────────────────────── */
.dashboard-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.stat-card .stat-label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  margin-bottom: 8px;
}
.stat-card .stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.5px;
}
.stat-card .stat-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

.depot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.depot-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  cursor: pointer;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.depot-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity .2s;
}
.depot-card:hover {
  border-color: var(--border-light);
  transform: translateY(-1px);
}
.depot-card:hover::before { opacity: 1; }

.depot-card-name {
  font-family: 'Syne', sans-serif;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}
.depot-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.depot-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.depot-stat-label {
  font-size: 10.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 3px;
}
.depot-stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 500;
}

/* ─────────────────────────────────────────
   TABLES
───────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  white-space: nowrap;
}

th {
  padding: 9px 12px;
  text-align: right;
  font-family: 'Syne', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,.2);
  cursor: default;
  user-select: none;
}
th:first-child, th.left { text-align: left; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text-muted); }

td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid rgba(26,45,74,.6);
  color: var(--text);
  vertical-align: middle;
}
td:first-child, td.left { text-align: left; }

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

.mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.pos { color: var(--positive); }
.neg { color: var(--negative); }
.warn { color: var(--warning); }
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }

.trend-up   { color: var(--positive); font-size: 11px; }
.trend-up2  { color: #4dba7c; font-size: 11px; }
.trend-down2{ color: #d06060; font-size: 11px; }
.trend-down { color: var(--negative); font-size: 11px; }

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
  font-family: 'Syne', sans-serif;
  letter-spacing: .4px;
}
.tag-buy    { background: rgba(0,200,150,.12); color: var(--positive); border: 1px solid rgba(0,200,150,.25); }
.tag-sell   { background: rgba(255,66,84,.12); color: var(--negative); border: 1px solid rgba(255,66,84,.25); }
.tag-warn   { background: rgba(240,162,45,.12); color: var(--warning); border: 1px solid rgba(240,162,45,.25); }
.tag-info   { background: rgba(56,189,248,.12); color: var(--info);    border: 1px solid rgba(56,189,248,.25); }

.div-warning {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(240,162,45,.1);
  border: 1px solid rgba(240,162,45,.3);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--warning);
  font-size: 11px;
}

/* ─────────────────────────────────────────
   STOCK NAME CELL
───────────────────────────────────────── */
.stock-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 140px;
}
.stock-name { font-weight: 500; font-size: 13px; }
.stock-symbol {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--text-dim);
}

/* ─────────────────────────────────────────
   BUTTONS
───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 500;
  transition: all .15s;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.btn-primary:hover { background: #3d8bf5; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--text);
}
.btn-danger {
  background: rgba(255,66,84,.1);
  border: 1px solid rgba(255,66,84,.3);
  color: var(--negative);
}
.btn-danger:hover { background: rgba(255,66,84,.2); }

.btn-icon {
  padding: 5px 8px;
  font-size: 13px;
  border-radius: 5px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-light); }

.action-group {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

/* ─────────────────────────────────────────
   DEPOT DETAIL HEADER
───────────────────────────────────────── */
.depot-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

.depot-summary {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}

.depot-sum-item .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  margin-bottom: 4px;
}
.depot-sum-item .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 500;
}

/* ─────────────────────────────────────────
   TRANSACTIONS EXPANDABLE
───────────────────────────────────────── */
.trans-row td {
  background: rgba(6, 11, 22, 0.6) !important;
  font-size: 12px;
}
.trans-row.hidden { display: none; }

.trans-mini-table {
  width: 100%;
  border-collapse: collapse;
}
.trans-mini-table td, .trans-mini-table th {
  padding: 6px 10px;
  font-size: 11.5px;
  border-bottom: 1px solid rgba(26,45,74,.4);
}
.trans-mini-table th {
  font-size: 10px;
  color: var(--text-dim);
  padding: 4px 10px;
}
.trans-mini-table tr:last-child td { border-bottom: none; }

.expand-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 0 4px;
  transition: color .15s;
}
.expand-btn:hover { color: var(--accent); }

/* ─────────────────────────────────────────
   WATCHLIST
───────────────────────────────────────── */
.drawdown-bar {
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
}
.drawdown-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--warning);
  transition: width .3s;
}
.drawdown-fill.reached { background: var(--positive); }

/* ─────────────────────────────────────────
   MODAL
───────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 22, 0.85);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,.7);
}

.modal-lg { max-width: 750px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-family: 'Syne', sans-serif;
  font-size: 15px;
  font-weight: 700;
}
.modal-close {
  color: var(--text-muted);
  font-size: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* ─────────────────────────────────────────
   FORMS
───────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: .3px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
.form-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ─────────────────────────────────────────
   IMPORT
───────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .2s;
  margin-bottom: 20px;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
}
.upload-zone input[type=file] { display: none; }

.mapping-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.mapping-table td, .mapping-table th {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.mapping-table th {
  background: rgba(0,0,0,.2);
  font-family: 'Syne', sans-serif;
  font-size: 10px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.mapping-table select { padding: 5px 8px; font-size: 12px; }

/* ─────────────────────────────────────────
   TOAST
───────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  animation: slideIn .2s ease;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.toast-success { background: rgba(0,200,150,.12); border: 1px solid rgba(0,200,150,.3); color: var(--positive); }
.toast-error   { background: rgba(255,66,84,.12);  border: 1px solid rgba(255,66,84,.3);  color: var(--negative); }
.toast-info    { background: rgba(45,122,240,.12); border: 1px solid rgba(45,122,240,.3); color: var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ─────────────────────────────────────────
   EMPTY STATES
───────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 13px; margin-bottom: 16px; }

/* ─────────────────────────────────────────
   LOADING
───────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text-dim);
  gap: 12px;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.spinning { animation: spin .7s linear infinite; display: inline-block; }

/* ─────────────────────────────────────────
   SECTION SEPARATOR
───────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-title {
  font-family: 'Syne', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ─────────────────────────────────────────
   RESPONSIVE
───────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main {
    margin-left: 0;
  }
  .menu-toggle { display: block; }
  .content-area { padding: 16px; }
  .dashboard-header { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* ─────────────────────────────────────────
   SCROLLBAR
───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
