/* ================================================================
   PORTFOLIO TRACKER — DARK THEME STYLESHEET
   ================================================================ */

:root {
  /* Color palette */
  --bg-base:       #0d0e11;
  --bg-surface:    #13151a;
  --bg-elevated:   #1a1d26;
  --bg-input:      #1e2130;
  --bg-hover:      #252940;
  --border:        #2a2e3e;
  --border-strong: #3a3f56;

  --text-primary:  #e8eaf0;
  --text-secondary:#9499b0;
  --text-muted:    #5c6180;

  --accent:        #4f80f7;
  --accent-hover:  #6694ff;

  /* Chart series colors */
  --color-value:    #4f80f7;
  --color-deposits: #f7c04f;
  --color-profit:   #4fcf8c;
  --color-loss:     #f74f4f;

  /* Spacing */
  --radius:    8px;
  --radius-sm: 4px;
  --topbar-h:  52px;
}

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

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Screens ──────────────────────────────────────────────── */
.screen { width: 100%; min-height: 100%; }

/* ── Auth screen ──────────────────────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 32px;
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.auth-error {
  background: rgba(247, 79, 79, 0.12);
  border: 1px solid rgba(247, 79, 79, 0.3);
  border-radius: var(--radius-sm);
  color: #f74f4f;
  font-size: 13px;
  padding: 10px 12px;
  margin-bottom: 16px;
}

/* ── Top bar ──────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.topbar-brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.topbar-actions { display: flex; gap: 6px; align-items: center; }

.topbar-action-label {
  font-size: 12px;
  margin-left: 4px;
}

/* ── Dashboard layout ─────────────────────────────────────── */
#app-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.dashboard {
  display: grid;
  grid-template-columns: 28% 1fr 220px;
  grid-template-rows: 1fr;
  height: calc(100vh - var(--topbar-h));
  margin-top: var(--topbar-h);
  overflow: hidden;
  gap: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  padding: 12px 10px;
  gap: 8px;
}

.panel-left { overflow-y: auto; }
.panel-center { border-right: none; flex: 1; }
.panel-summary {
  overflow-y: auto;
  padding: 14px 14px;
  border-right: none;
  border-left: 1px solid var(--border);
}

.individual-charts-shell {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  height: 100%;
}

.individual-charts-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 12px 14px;
  text-align: left;
}

.individual-charts-toggle-title {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.individual-charts-toggle-subtitle {
  display: block;
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 12px;
}

.individual-charts-toggle-icon {
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  margin-right: 4px;
  flex-shrink: 0;
}

.individual-charts-shell.is-open .individual-charts-toggle-icon {
  transform: rotate(225deg);
}

.individual-charts-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1;
}

/* ── Chart sections ───────────────────────────────────────── */
.chart-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 6px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chart-section-tall {
  flex: 1;
  height: 100%;
}

.chart-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.chart-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chart-latest {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.chart-container {
  flex: 1;
  min-height: 0;
  height: 100%;
  min-height: 140px;
}

.chart-legend {
  display: flex;
  gap: 12px;
  margin-top: 4px;
  flex-shrink: 0;
}

.legend-item {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-item::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 2px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-value::before   { background: var(--color-value); }
.legend-deposits::before { background: var(--color-deposits); }
.legend-profit::before  { background: var(--color-profit); }

/* ── Summary panel ────────────────────────────────────────── */
.summary-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.summary-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}

.summary-block-last { margin-bottom: 0; }

.summary-block-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 0;
}

.summary-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.summary-value {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.summary-value.positive { color: var(--color-profit); }
.summary-value.negative { color: var(--color-loss); }

.summary-date {
  font-size: 12px;
  color: var(--text-secondary);
}

.summary-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 8px;
  line-height: 1.7;
}

/* ── Loading overlay ──────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 14, 17, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: opacity 0.2s;
}

.loading-overlay.hidden { display: none; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Operations drawer ────────────────────────────────────── */
.ops-panel {
  position: fixed;
  inset: 0;
  z-index: 500;
  pointer-events: none;
}

.ops-panel:not(.hidden) { pointer-events: all; }

.ops-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.25s;
}

.ops-panel:not(.hidden) .ops-backdrop { opacity: 1; }

.ops-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: 440px;
  max-width: 100vw;
  height: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.ops-panel:not(.hidden) .ops-drawer { transform: translateX(0); }

.ops-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ops-title {
  font-size: 16px;
  font-weight: 700;
}

.ops-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ops-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  transition: color 0.15s, border-color 0.15s;
}

.ops-tab:hover { color: var(--text-primary); }
.ops-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.ops-tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.ops-section { margin-bottom: 16px; }
.ops-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.ops-divider { border-top: 1px solid var(--border); padding-top: 16px; }

.ops-status {
  border-radius: var(--radius-sm);
  font-size: 12px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

.ops-status.success {
  background: rgba(79, 207, 140, 0.1);
  border: 1px solid rgba(79, 207, 140, 0.3);
  color: #4fcf8c;
}

.ops-status.error {
  background: rgba(247, 79, 79, 0.1);
  border: 1px solid rgba(247, 79, 79, 0.3);
  color: #f74f4f;
}

.ops-status.info {
  background: rgba(79, 128, 247, 0.1);
  border: 1px solid rgba(79, 128, 247, 0.3);
  color: #4f80f7;
}

.ops-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

/* File drop zone */
.file-drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(79, 128, 247, 0.06);
}

.file-input-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.file-drop-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  pointer-events: none;
}

.file-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.import-file-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.import-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.import-file-item .file-name { color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-file-item .file-size { flex-shrink: 0; margin-left: 8px; }

/* Deposits list */
.deposits-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.deposit-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
}

.deposit-account {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  background: var(--bg-hover);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--text-secondary);
}

.deposit-date { color: var(--text-secondary); }
.deposit-note { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deposit-amount { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--color-deposits); text-align: right; }
.deposit-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  border-radius: 3px;
  transition: color 0.15s;
}
.deposit-delete:hover { color: var(--color-loss); }

/* Import history */
.import-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
}

.import-history-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
}

.import-history-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}

.import-history-filename { color: var(--text-primary); font-weight: 500; }
.import-history-account  { font-size: 11px; background: var(--bg-hover); border-radius: 3px; padding: 1px 5px; color: var(--text-secondary); margin-left: 6px; }
.import-history-date     { color: var(--text-muted); font-size: 11px; }
.import-history-stats    { color: var(--text-secondary); }
.import-history-status   { font-size: 11px; font-weight: 600; }
.import-history-status.success { color: var(--color-profit); }
.import-history-status.failed  { color: var(--color-loss); }

/* Form 2-column row */
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ops-form { display: flex; flex-direction: column; }

/* ── Shared form elements ─────────────────────────────────── */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.field-input,
.field-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  padding: 9px 12px;
  appearance: none;
  transition: border-color 0.15s;
}

.field-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239499b0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}

.field-input:focus,
.field-select:focus {
  outline: none;
  border-color: var(--accent);
}

.field-input::placeholder { color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  transition: opacity 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 7px 10px;
}

.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-icon { border-radius: var(--radius-sm); }

.btn-full { width: 100%; }

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ================================================================
   RESPONSIVE — Tablet (≤1100px)
   ================================================================ */
@media (max-width: 1100px) {
  .dashboard {
    grid-template-columns: 38% 1fr;
    grid-template-rows: auto auto;
  }

  .panel-left   { grid-column: 1; grid-row: 1; border-right: 1px solid var(--border); }
  .panel-center { grid-column: 2; grid-row: 1; border-right: none; }
  .panel-summary {
    grid-column: 1 / 3;
    grid-row: 2;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 180px;
  }

  .summary-block { flex: 1; min-width: 140px; margin-bottom: 0; }
  .summary-heading { width: 100%; }
}

/* ================================================================
   RESPONSIVE — Mobile (≤700px)
   ================================================================ */
@media (max-width: 700px) {
  body, html { overflow: auto; }

  #app-screen {
    height: auto;
    min-height: 100dvh;
  }

  .topbar-action-label { display: none; }

  .dashboard {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - var(--topbar-h));
    overflow: visible;
    margin-top: var(--topbar-h);
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 8px;
    flex-shrink: 0;
  }

  .panel-center {
    order: 1;
    border-bottom: 1px solid var(--border);
    min-height: calc(100dvh - var(--topbar-h));
    padding-bottom: 8px;
  }
  .panel-summary {
    order: 2;
    border-left: none;
    border-top: none;
    padding: 12px 10px;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 8px;
    max-height: none;
    overflow: visible;
  }
  .panel-left {
    order: 3;
    flex-direction: column;
    gap: 8px;
    overflow: visible;
  }

  .summary-heading,
  .summary-block {
    width: 100%;
  }

  .individual-charts-toggle {
    display: flex;
  }

  .individual-charts-body {
    display: none;
    flex: none;
  }

  .individual-charts-shell.is-open .individual-charts-body {
    display: flex;
  }

  .chart-section-tall {
    min-height: calc(100dvh - var(--topbar-h) - 18px);
  }

  .chart-section-tall .chart-container {
    min-height: 0;
    height: auto !important;
  }

  .chart-container {
    height: 220px !important;
    min-height: 220px;
  }

  .ops-drawer { width: 100%; }

  .form-row-2 { grid-template-columns: 1fr; }
}
