/* ===== AssetDesk Design System ===== */
:root {
  --bg: #09090b;
  --surface: #131317;
  --surface-hover: #1a1a20;
  --card: rgba(255,255,255,0.04);
  --card-hover: rgba(255,255,255,0.07);
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border: rgba(255,255,255,0.08);
  --border-focus: rgba(99,102,241,0.4);
  --primary: #818cf8;
  --primary-dim: rgba(99,102,241,0.15);
  --good: #34d399;
  --good-dim: rgba(52,211,153,0.15);
  --warn: #fbbf24;
  --warn-dim: rgba(251,191,36,0.15);
  --danger: #f87171;
  --danger-dim: rgba(248,113,113,0.15);
  --gain: #e8637a;
  --gain-dim: rgba(232,99,122,0.12);
  --loss: #5bc9a3;
  --loss-dim: rgba(91,201,163,0.12);
  --accent: #a78bfa;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: #a5b4fc; }

/* ===== Topbar ===== */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 0 32px;
  background: rgba(9,9,11,0.85);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===== Tab Nav ===== */
nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

nav a {
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
  position: relative;
}

nav a:hover { color: var(--text); background: var(--card); }

nav a.active {
  color: var(--text);
  background: var(--card);
}

.userbar {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
}

.userbar select {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.userbar a { font-size: 13px; }

/* ===== Container ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px;
}

/* ===== Hero Section ===== */
.hero {
  text-align: center;
  padding: 32px 0 28px;
}

.hero-label {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.hero-value {
  font-size: 52px;
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.hero-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}

.hero-change.up { background: var(--primary-dim); color: var(--primary); }
.hero-change.down { background: var(--danger-dim); color: var(--danger); }

/* ===== Sub Metrics ===== */
.sub-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 32px;
}

.sub-metric {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.sub-metric:hover {
  background: var(--card-hover);
  border-color: rgba(255,255,255,0.15);
  transform: translateY(-1px);
}

.sub-metric .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.sub-metric .value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.sub-metric.good .value { /* income - neutral */ }
.sub-metric.warn .value { color: var(--warn); }
.sub-metric.danger .value { color: var(--danger); }

/* ===== Expandable Sections ===== */
.expand-sections {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.expand-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.2s;
}

.expand-section:hover { border-color: rgba(255,255,255,0.15); }

.expand-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
}

.expand-header h3 {
  font-size: 13.5px;
  font-weight: 500;
}

.expand-arrow {
  width: 20px;
  height: 20px;
  transition: transform 0.25s;
  color: var(--text-muted);
}

.expand-section.open .expand-arrow { transform: rotate(180deg); }

.expand-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.expand-section.open .expand-body { max-height: 300px; overflow-y: auto; }

.expand-body table {
  width: 100%;
  border-collapse: collapse;
}

.expand-body td {
  padding: 8px 18px;
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.expand-body td:first-child { color: var(--text-secondary); }
.expand-body td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ===== Page Header ===== */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
}

.page-head h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.page-head .subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-accent {
  background: linear-gradient(135deg, #e8637a, #f59e5b);
  color: #fff;
}

.btn-accent:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-ghost {
  background: var(--card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

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

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

.btn-danger:hover {
  background: var(--danger-dim);
  border-color: rgba(248,113,113,0.3);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  font-size: 16px;
}

/* ===== Tables ===== */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrap th {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.table-wrap td {
  padding: 12px 16px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table-wrap tbody tr {
  transition: background 0.1s;
}

.table-wrap tbody tr:hover { background: var(--card-hover); }

.table-wrap tbody tr:last-child td { border-bottom: none; }

.table-wrap td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

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

.table-wrap .empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.table-wrap .empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
  opacity: 0.3;
}

/* ===== Expandable Row ===== */
.expandable-row { cursor: pointer; }

.detail-row { display: none; }

.detail-row.open { display: table-row; }

.detail-row td {
  padding: 16px;
  background: rgba(255,255,255,0.02);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px 24px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-item .dl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.detail-item .dv { font-size: 13.5px; }

.row-expand-icon {
  display: inline-block;
  transition: transform 0.2s;
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}

tr.open .row-expand-icon { transform: rotate(90deg); }

/* ===== Drawer ===== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-panel {
  width: 520px;
  max-width: 92vw;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 28px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.drawer-overlay.open .drawer-panel { transform: translateX(0); }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.drawer-head h2 {
  font-size: 18px;
  font-weight: 600;
}

.drawer-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--card);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.drawer-close:hover { background: var(--card-hover); color: var(--text); }

/* ===== Form in Drawer ===== */
.drawer-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.drawer-form input,
.drawer-form select {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.drawer-form input:focus,
.drawer-form select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

.drawer-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.drawer-form .form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.drawer-form .checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-direction: row;
  font-size: 13px;
  color: var(--text);
}

.drawer-form .checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* ===== Income Stats Bar ===== */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

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

.stat-item .sl { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.stat-item .sv { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

.stat-item.good .sv { /* income - neutral */ }
.stat-item.accent .sv { color: var(--accent); }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-bar input[type="date"] {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.filter-bar input[type="date"]:focus { border-color: var(--primary); }

/* ===== Flash Messages ===== */
.flash-wrap {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.flash {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
}

.flash.success { background: var(--good-dim); color: var(--good); border: 1px solid rgba(52,211,153,0.2); }
.flash.error { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(248,113,113,0.2); }

/* ===== Login Card ===== */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 56px);
  padding: 40px 20px;
}

.login-card {
  width: 400px;
  max-width: 100%;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
  text-align: center;
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.login-card input {
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.login-card input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

.login-card button {
  height: 44px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.15s;
  font-family: inherit;
}

.login-card button:hover { opacity: 0.9; }

.login-card .alt-link {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 16px;
}

/* ===== Quick Add Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 480px;
  max-width: 94vw;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px;
  transform: translateY(10px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open .modal-card { transform: translateY(0); }

.modal-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.modal-form input,
.modal-form select {
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.modal-form input:focus,
.modal-form select:focus { border-color: var(--primary); }

.modal-form .form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.modal-form .form-msg {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  display: none;
}

.modal-form .form-msg.success { background: var(--good-dim); color: var(--good); display: block; }
.modal-form .form-msg.error { background: var(--danger-dim); color: var(--danger); display: block; }

/* ===== OCR Zone ===== */
.ocr-zone {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 12px;
  transition: border-color 0.15s, background 0.15s;
  font-size: 13px;
  color: var(--text-muted);
}

.ocr-zone:hover {
  border-color: var(--primary);
  background: var(--primary-dim);
}

.ocr-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Multi-user selector ===== */
.user-switch form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-switch select {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
  outline: none;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .container { padding: 16px 12px; }
  .topbar { padding: 0 12px; gap: 12px; }
  .topbar .userbar { font-size: 12px; }
  nav { gap: 2px; }
  nav a { padding: 4px 8px; font-size: 12px; }
  .hero { padding: 20px 0 16px; }
  .hero-value { font-size: 36px; }
  .sub-metrics, .expand-sections { grid-template-columns: 1fr !important; }
  .stats-bar { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .drawer-panel { width: 100%; padding: 20px; }
  .drawer-form .form-row { grid-template-columns: 1fr; }
  .modal-card { padding: 20px; }
  .page-head { flex-direction: column; gap: 10px; }
  .page-head h1 { font-size: 20px; }
  .table-wrap td, .table-wrap th { padding: 8px 10px; font-size: 12px; }
}

@media (max-width: 600px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 10px; gap: 8px; }
  .brand { font-size: 15px; }
  nav { order: 3; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  nav a { padding: 5px 10px; font-size: 13px; white-space: nowrap; }
  .hero-value { font-size: 28px; }
  .hero-label { font-size: 11px; }
  .sub-metric { padding: 12px 14px; }
  .sub-metric .value { font-size: 18px; }
  .sub-metric .label { font-size: 11px; }
  .stats-bar { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-item { padding: 10px 12px; }
  .stat-item .sv { font-size: 16px; }
  .container { padding: 12px 8px; }
  .page-head { margin-bottom: 16px; }
  .expand-header h3 { font-size: 12px; }
  .expand-header { padding: 10px 14px; }
  .expand-body td { padding: 6px 14px; font-size: 12px; }
  .modal-card { max-width: 100vw; border-radius: 16px; padding: 16px; }
}
