:root {
    --paper: #F6F1EF;
    --surface: #FFFFFF;
    --surface-alt: #FBF6F4;
    --ink: #2B2024;
    --ink-soft: #6B5A60;
    --ink-faint: #9C8890;
    --border: #E7DAD8;
    --accent: #9C2F52;
    --accent-soft: #F1DEE4;
    --accent-ink: #6E1F3A;
    --good: #2F7D5B;
    --good-soft: #DCEFE4;
    --warn: #B8722A;
    --warn-soft: #F5E4CF;
    --info: #3C6E9C;
    --info-soft: #DDEAF3;
    --shadow: 0 1px 2px rgba(43,32,36,0.06), 0 8px 24px -12px rgba(43,32,36,0.18);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --paper: #221A1E;
      --surface: #2C2226;
      --surface-alt: #33272C;
      --ink: #F4E8EC;
      --ink-soft: #C9AEB6;
      --ink-faint: #8A6E76;
      --border: #4A3A3F;
      --accent: #E5799C;
      --accent-soft: #4A2733;
      --accent-ink: #FCD8E3;
      --good: #6FCB9F;
      --good-soft: #1E3A2C;
      --warn: #E3A65C;
      --warn-soft: #3E2E1A;
      --info: #7FB3E0;
      --info-soft: #1E3247;
      --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);
    }
  }

  :root[data-theme="dark"] {
    --paper: #221A1E;
    --surface: #2C2226;
    --surface-alt: #33272C;
    --ink: #F4E8EC;
    --ink-soft: #C9AEB6;
    --ink-faint: #8A6E76;
    --border: #4A3A3F;
    --accent: #E5799C;
    --accent-soft: #4A2733;
    --accent-ink: #FCD8E3;
    --good: #6FCB9F;
    --good-soft: #1E3A2C;
    --warn: #E3A65C;
    --warn-soft: #3E2E1A;
    --info: #7FB3E0;
    --info-soft: #1E3247;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
  }

  .mono {
    font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
    font-variant-numeric: tabular-nums;
  }

  .wrap {
    max-width: 1080px;
    margin: 0 auto;
    padding: 28px 20px 64px;
    display: flex;
    flex-direction: column;
    gap: 22px;
  }

  /* ---- Top bar ---- */
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
  }

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

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: -0.02em;
    flex-shrink: 0;
  }

  .brand h1 {
    margin: 0;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.02em;
    text-wrap: balance;
  }

  .brand p {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--ink-soft);
  }

  .kpis {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }

  .kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 7px 12px;
    display: flex;
    align-items: baseline;
    gap: 6px;
    box-shadow: var(--shadow);
  }

  .kpi .num {
    font-weight: 800;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
  }

  .kpi .lbl {
    font-size: 11.5px;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  /* ---- Account rail ---- */
  .rail {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .acct-card {
    flex: 0 0 auto;
    width: 300px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
    appearance: none;
  }

  .acct-card:hover {
    border-color: var(--ink-faint);
  }

  .acct-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .acct-card.active {
    border-color: var(--accent);
    box-shadow: var(--shadow), 0 0 0 1px var(--accent) inset;
  }

  .acct-panels {
    display: flex;
    flex-direction: column;
    gap: 22px;
  }

  .acct-panels[hidden] {
    display: none;
  }

  .acct-top {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    flex-shrink: 0;
  }

  .acct-name {
    font-weight: 700;
    font-size: 14.5px;
    line-height: 1.25;
  }

  .acct-handle {
    font-size: 12.5px;
    color: var(--ink-soft);
  }

  .status-dot {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--good);
    font-weight: 600;
  }

  .status-dot::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--good);
  }

  .status-dot.warn { color: var(--warn); }
  .status-dot.warn::before { background: var(--warn); }

  .acct-stats {
    display: flex;
    gap: 14px;
  }

  .acct-stats div {
    display: flex;
    flex-direction: column;
  }

  .acct-stats .num {
    font-weight: 800;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
  }

  .acct-stats .lbl {
    font-size: 11px;
    color: var(--ink-faint);
  }

  .add-acct {
    flex: 0 0 auto;
    width: 300px;
    border: 1.5px dashed var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    color: var(--ink-soft);
  }

  .add-acct strong {
    color: var(--ink);
    font-size: 14px;
  }

  .add-acct span {
    font-size: 12.5px;
    line-height: 1.5;
  }

  /* ---- Shell layout (sidebar + content) ---- */
  .shell {
    display: flex;
    align-items: flex-start;
    gap: 20px;
  }

  .sidenav {
    flex: 0 0 268px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding-bottom: 4px;
  }

  .sidenav .acct-card,
  .sidenav .add-acct {
    width: 100%;
  }

  .main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 22px;
  }

  .nav-overview {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 12px 16px;
    box-shadow: var(--shadow);
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
    appearance: none;
    font-weight: 700;
    font-size: 14px;
  }

  .nav-overview:hover { border-color: var(--ink-faint); }
  .nav-overview:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .nav-overview.active {
    border-color: var(--accent);
    box-shadow: var(--shadow), 0 0 0 1px var(--accent) inset;
    color: var(--accent-ink);
  }

  .nav-overview .nav-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--info-soft);
    color: var(--info);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
  }

  .nav-divider {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-faint);
    padding: 6px 4px 0;
  }

  /* ---- Overview table ---- */
  .ov-table-frame {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
  }

  .ov-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 760px;
    font-size: 13px;
  }

  .ov-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-alt);
    text-align: left;
    padding: 9px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
    border-bottom: 1px solid var(--border);
  }

  .ov-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
  }

  .ov-table tbody tr:last-child td { border-bottom: none; }
  .ov-table tbody tr { cursor: pointer; }
  .ov-table tbody tr:hover { background: var(--surface-alt); }

  .ov-acct {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .ov-acct .avatar {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }

  .ov-name { font-weight: 700; font-size: 13px; }
  .ov-handle { font-size: 11.5px; color: var(--ink-soft); }

  @media (max-width: 860px) {
    .shell { flex-direction: column; }
    .sidenav {
      position: static;
      max-height: none;
      flex-direction: row;
      overflow-y: visible;
      overflow-x: auto;
      width: 100%;
    }
    .sidenav .acct-card,
    .sidenav .add-acct,
    .nav-overview {
      flex: 0 0 260px;
      width: 260px;
    }
  }

  /* ---- Panels ---- */
  .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  .panel-head {
    padding: 16px 18px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
  }

  .panel-head h2 {
    margin: 0;
    font-size: 15.5px;
    font-weight: 800;
    letter-spacing: -0.01em;
  }

  .panel-head .sub {
    margin: 2px 0 0;
    font-size: 12.5px;
    color: var(--ink-soft);
  }

  .panel-body {
    padding: 16px 18px 20px;
  }

  /* ---- Schedule table ---- */
  .search-row {
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .search-row input {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
    color: var(--ink);
    width: 220px;
    font-family: inherit;
  }

  .search-row input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
  }

  .table-frame {
    overflow-x: auto;
    max-height: 480px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
  }

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

  thead th {
    position: sticky;
    top: 0;
    background: var(--surface-alt);
    text-align: left;
    padding: 9px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
    border-bottom: 1px solid var(--border);
    z-index: 1;
  }

  tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
  }

  tbody tr:last-child td { border-bottom: none; }
  tbody tr:hover { background: var(--surface-alt); }

  .cap-cell {
    max-width: 360px;
  }

  .cap-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tags {
    display: flex;
    gap: 6px;
    margin-top: 3px;
  }

  .pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
  }

  .pill-info { background: var(--info-soft); color: var(--info); }
  .pill-accent { background: var(--accent-soft); color: var(--accent-ink); }
  .pill-good { background: var(--good-soft); color: var(--good); }

  .today-row td { background: var(--accent-soft); }

  /* ---- Assets ---- */
  .asset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
  }

  .asset-stat .num {
    font-size: 28px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
  }

  .asset-stat .lbl {
    font-size: 12.5px;
    color: var(--ink-soft);
    margin-top: 2px;
  }

  .bar-track {
    height: 10px;
    border-radius: 999px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    overflow: hidden;
    margin: 12px 0 6px;
  }

  .bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px 0 0 999px;
  }

  .bar-caption {
    font-size: 12px;
    color: var(--ink-soft);
    display: flex;
    justify-content: space-between;
  }

  .path-box {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--ink-soft);
    word-break: break-all;
    margin-top: 10px;
  }

  .note-box {
    background: var(--accent-soft);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 12.5px;
    color: var(--accent-ink);
    line-height: 1.5;
  }

  /* ---- Performance ---- */
  .perf-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .perf-row {
    display: grid;
    grid-template-columns: 1fr 140px 60px;
    align-items: center;
    gap: 12px;
  }

  .perf-title {
    font-size: 13px;
    font-weight: 600;
  }

  .perf-meta {
    font-size: 11.5px;
    color: var(--ink-faint);
    margin-top: 2px;
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .perf-chart {
    height: 22px;
    border-radius: 6px;
    background: var(--surface-alt);
    position: relative;
    overflow: hidden;
  }

  .perf-chart-fill {
    position: absolute;
    inset: 0 auto 0 0;
    background: linear-gradient(90deg, var(--info-soft), var(--info));
    border-radius: 6px;
  }

  .perf-views {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
  }

  .lock-icon { color: var(--warn); }

  /* ---- Notes ---- */
  .note-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .note-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    background: var(--surface-alt);
    border-radius: 10px;
    border: 1px solid var(--border);
  }

  .note-item .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
  }

  .dot-good { background: var(--good); }
  .dot-info { background: var(--info); }
  .dot-warn { background: var(--warn); }

  .note-item p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
  }

  .note-item time {
    display: block;
    font-size: 11.5px;
    color: var(--ink-faint);
    margin-top: 3px;
  }

  footer {
    text-align: center;
    font-size: 12px;
    color: var(--ink-faint);
    padding-top: 8px;
  }

  @media (max-width: 640px) {
    .asset-grid { grid-template-columns: 1fr; }
    .perf-row { grid-template-columns: 1fr 90px 50px; }
  }

  /* ---- Forms, buttons, modal (trang dong: dang nhap + them/sua/xoa) ---- */
  body.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
  }

  .login-card {
    max-width: 360px;
    width: 100%;
    padding: 28px 24px;
  }

  .login-card h1 {
    margin: 0 0 4px;
    font-size: 19px;
    font-weight: 800;
  }

  .login-card .hint {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--ink-soft);
  }

  .error-msg {
    color: var(--accent);
    font-size: 13px;
    margin: 0 0 10px;
  }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  textarea,
  select {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--ink);
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
  }

  textarea { resize: vertical; min-height: 60px; }

  input:focus-visible,
  textarea:focus-visible,
  select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
  }

  label {
    display: block;
    font-size: 12.5px;
    color: var(--ink-soft);
    margin: 10px 0 4px;
  }

  label:first-child { margin-top: 0; }

  button {
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    padding: 8px 14px;
    cursor: pointer;
  }

  button:hover { border-color: var(--accent); }

  button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
  }

  button.primary:hover { opacity: 0.92; }

  button.danger {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--accent);
  }

  button.small {
    padding: 4px 10px;
    font-size: 12px;
  }

  .btn-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
  }

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

  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(43, 32, 36, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 50;
  }

  .modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
  }

  .modal h3 {
    margin: 0 0 4px;
    font-size: 16px;
  }

  .modal-close {
    float: right;
    padding: 4px 8px;
  }

  .empty-hint {
    font-size: 13px;
    color: var(--ink-faint);
    padding: 8px 0;
  }
