:root {
    --bg: #0f1117;
    --surface: #181c27;
    --surface2: #1e2335;
    --border: rgba(255,255,255,0.07);
    --border2: rgba(255,255,255,0.12);
    --text: #e8eaf0;
    --muted: #7b82a0;
    --accent: #4f8ef7;
    --accent-dim: rgba(79,142,247,0.12);
    --green: #3ecf8e;
    --green-dim: rgba(62,207,142,0.12);
    --amber: #f5a623;
    --amber-dim: rgba(245,166,35,0.10);
    --red: #f06565;
    --red-dim: rgba(240,101,101,0.10);
    --purple: #a78bfa;
    --purple-dim: rgba(167,139,250,0.10);
    --radius: 10px;
    --radius-sm: 6px;
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
  }

  [data-theme="light"] {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface2: #f1f5f9;
    --border: #e2e8f0;
    --border2: #cbd5e1;
    --text: #0f172a;
    --muted: #64748b;
    --accent: #3b82f6;
    --accent-dim: rgba(59, 130, 246, 0.12);
    --green: #10b981;
    --green-dim: rgba(16, 185, 129, 0.12);
    --amber: #f59e0b;
    --amber-dim: rgba(245, 158, 11, 0.10);
    --red: #ef4444;
    --red-dim: rgba(239, 68, 68, 0.10);
    --purple: #8b5cf6;
    --purple-dim: rgba(139, 92, 246, 0.10);
  }

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

  body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
  }

  /* ── Layout ── */
  .app { display: flex; min-height: 100vh; }

  .sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }

  .logo {
    padding: 0 20px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
  }
  .logo-mark {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .logo-icon {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
  }
  .logo-icon svg { width: 18px; height: 18px; }
  .logo-text { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.2; }
  .logo-sub  { font-size: 11px; color: var(--muted); }

  .nav-section { padding: 0 12px; margin-bottom: 8px; }
  .nav-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; padding: 0 8px; margin-bottom: 4px; }

  .nav-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border: none; background: none; width: 100%; text-align: left;
  }
  .nav-item:hover { background: var(--surface2); color: var(--text); }
  .nav-item.active { background: var(--accent-dim); color: var(--accent); }
  .nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }

  .sidebar-footer {
    margin-top: auto;
    padding: 16px 20px 0;
    border-top: 1px solid var(--border);
  }
  .conn-status {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--muted);
  }
  .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
  .dot.ok  { background: var(--green); box-shadow: 0 0 6px var(--green); }
  .dot.err { background: var(--red); }

  /* ── Main ── */
  .main {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
  }

  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky; top: 0; z-index: 10;
  }
  .page-title { font-size: 16px; font-weight: 600; }
  .page-sub   { font-size: 12px; color: var(--muted); margin-top: 1px; }

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

  .btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500;
    cursor: pointer; border: none;
    transition: opacity 0.15s, transform 0.1s;
  }
  .btn:active { transform: scale(0.97); }
  .btn-ghost {
    background: var(--surface2);
    color: var(--muted);
    border: 1px solid var(--border2);
  }
  .btn-ghost:hover { color: var(--text); }
  .btn-primary { background: var(--accent); color: #fff; }
  .btn-primary:hover { opacity: 0.88; }
  .btn svg { width: 14px; height: 14px; }

  .content { padding: 28px; }

  /* ── Cards ── */
  .stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
  }

  .stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .stat-card-info {
    display: flex;
    flex-direction: column;
  }
  .stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
  }
  .stat-card.blue::before  { background: var(--accent); }
  .stat-card.green::before { background: var(--green); }
  .stat-card.amber::before { background: var(--amber); }
  .stat-card.purple::before{ background: var(--purple); }

  .stat-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .stat-icon svg { width: 22px; height: 22px; }
  .stat-icon.blue   { background: var(--accent-dim); color: var(--accent); }
  .stat-icon.green  { background: var(--green-dim);  color: var(--green);  }
  .stat-icon.amber  { background: var(--amber-dim);  color: var(--amber);  }
  .stat-icon.purple { background: var(--purple-dim); color: var(--purple); }

  .stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; margin-bottom: 2px; color: var(--text); }
  .stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }

  /* ── Section ── */
  .section { margin-bottom: 28px; }
  .section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
  }
  .section-title { font-size: 14px; font-weight: 600; }
  .section-sub   { font-size: 12px; color: var(--muted); margin-top: 2px; }

  /* ── Backup List ── */
  .backup-list { display: flex; flex-direction: column; gap: 8px; }

  .backup-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    display: flex; align-items: center; gap: 14px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
  }
  .backup-item:hover { border-color: var(--border2); background: var(--surface2); }
  .backup-item.expanded { border-color: var(--accent); }

  .backup-date-block {
    min-width: 52px; text-align: center;
    background: var(--surface2); border-radius: 8px;
    padding: 8px 6px;
    border: 1px solid var(--border);
  }
  .backup-date-day   { font-size: 20px; font-weight: 700; line-height: 1; }
  .backup-date-month { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

  .backup-info { flex: 1; min-width: 0; }
  .backup-name { font-size: 13px; font-weight: 600; font-family: var(--mono); margin-bottom: 3px; }
  .backup-meta { font-size: 12px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }

  .badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px; font-weight: 500;
  }
  .badge-green  { background: var(--green-dim);  color: var(--green); }
  .badge-amber  { background: var(--amber-dim);  color: var(--amber); }
  .badge-blue   { background: var(--accent-dim); color: var(--accent); }
  .badge-red    { background: var(--red-dim);    color: var(--red); }

  .backup-actions { display: flex; gap: 6px; }

  /* ── Expandable table detail ── */
  .table-detail {
    display: none;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
  }
  .table-detail.show { display: block; }

  .table-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
  }

  .table-chip {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px;
  }
  .table-chip-name { font-size: 12px; font-family: var(--mono); color: var(--text); }
  .table-chip-meta { font-size: 11px; color: var(--muted); }
  .table-chip-files { display: flex; gap: 4px; margin-top: 4px; }

  .file-tag {
    font-size: 10px; font-family: var(--mono);
    padding: 1px 6px; border-radius: 4px; font-weight: 600;
  }
  .file-tag.csv { background: var(--green-dim);  color: var(--green); }
  .file-tag.sql { background: var(--accent-dim); color: var(--accent); }

  /* ── Timeline ── */
  .timeline { display: flex; flex-direction: column; }
  .tl-item {
    display: flex; gap: 14px;
    padding-bottom: 20px;
    position: relative;
  }
  .tl-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 11px; top: 24px; bottom: 0;
    width: 1px; background: var(--border);
  }
  .tl-dot {
    width: 24px; height: 24px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
  }
  .tl-dot.ok    { background: var(--green-dim);  border: 1px solid var(--green);  color: var(--green); }
  .tl-dot.warn  { background: var(--amber-dim);  border: 1px solid var(--amber);  color: var(--amber); }
  .tl-dot.err   { background: var(--red-dim);    border: 1px solid var(--red);    color: var(--red); }

  .tl-body { flex: 1; }
  .tl-title { font-size: 13px; font-weight: 500; }
  .tl-time  { font-size: 11px; color: var(--muted); margin-top: 1px; }
  .tl-desc  { font-size: 12px; color: var(--muted); margin-top: 4px; }

  /* ── Config Panel ── */
  .config-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 14px;
  }
  .config-card h3 { font-size: 13px; font-weight: 600; margin-bottom: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-size: 11px; }

  .form-row { margin-bottom: 14px; }
  .form-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: block; }
  .form-input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text);
    font-size: 13px;
    font-family: var(--mono);
    outline: none;
    transition: border-color 0.15s;
  }
  .form-input:focus { border-color: var(--accent); }
  .form-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

  .form-row-inline { display: flex; gap: 10px; }
  .form-row-inline .form-row { flex: 1; }

  .code-block {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--green);
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.7;
    position: relative;
  }
  .copy-btn-small {
    position: absolute; top: 8px; right: 8px;
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 11px;
    color: var(--muted);
    cursor: pointer;
  }
  .copy-btn-small:hover { color: var(--text); }

  /* ── Loading / Empty ── */
  .loading {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 48px 0; color: var(--muted);
    gap: 12px;
  }
  .spinner {
    width: 28px; height: 28px;
    border: 2px solid var(--border2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .empty {
    text-align: center;
    padding: 40px 0;
    color: var(--muted);
  }
  .empty-icon { font-size: 32px; margin-bottom: 10px; }
  .empty-title { font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 4px; }

  /* ── Views ── */
  .view { display: none; }
  .view.active { display: block; }

  /* ── Responsive ── */
  .hamburger-btn { display: none; }
  .sidebar-overlay { display: none; }

  @media (max-width: 768px) {
    .hamburger-btn { display: inline-flex; }
    .sidebar { 
      position: fixed;
      left: -260px;
      top: 0;
      bottom: 0;
      width: 260px;
      z-index: 100;
      transition: left 0.3s ease;
      display: flex;
    }
    .sidebar.show-mobile { left: 0; }
    
    .sidebar-overlay {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.5);
      z-index: 90;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.3s ease;
    }
    .sidebar-overlay.show {
      display: block;
      opacity: 1;
      pointer-events: auto;
    }

    .content { padding: 16px; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
  }

  /* ── Chart mini ── */
  .chart-bar-row {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 8px;
  }
  .chart-bar-label { font-size: 12px; font-family: var(--mono); color: var(--muted); min-width: 90px; }
  .chart-bar-track {
    flex: 1; height: 6px;
    background: var(--surface2);
    border-radius: 3px; overflow: hidden;
  }
  .chart-bar-fill {
    height: 100%; border-radius: 3px;
    background: var(--accent);
    transition: width 0.6s ease;
  }
  .chart-bar-val { font-size: 12px; color: var(--muted); min-width: 40px; text-align: right; }

  /* Pulse animation for "latest" badge */
  @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
  .badge-live { animation: pulse 2s ease infinite; }

  /* ── Modal ── */
  .modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s;
  }
  .modal-overlay.show { opacity: 1; pointer-events: auto; }
  .modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%; max-width: 500px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    transform: translateY(10px);
    transition: transform 0.2s;
  }
  .modal-overlay.show .modal { transform: translateY(0); }
  .modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
  .modal-title { font-size: 16px; font-weight: 600; }
  .modal-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 20px; }
  .modal-close:hover { color: var(--text); }

  .divider { height: 1px; background: var(--border); margin: 20px 0; }

  select.form-input { cursor: pointer; }
