:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --line: #ccd6e0;
  --text: #17212b;
  --muted: #5f6f82;
  --blue: #0876c9;
  --blue-dark: #055b9b;
  --cyan: #0f9aad;
  --amber: #f1a600;
  --red: #c7362f;
  --green: #16845b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  font-size: 14px;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 28px;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
}

.brand {
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: .5px;
}

.topbar-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar-nav::-webkit-scrollbar { display: none; }

.topbar-nav a {
  color: #eaf5ff;
  padding: 8px 12px;
  border-radius: 4px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-nav a.active,
.topbar-nav a:hover {
  background: rgba(255, 255, 255, .18);
  text-decoration: none;
}

.security {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #dff1ff;
}

.security form { margin: 0; }
.user-role-badge {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 12px;
  padding: 2px 10px;
  white-space: nowrap;
}
.security button {
  min-height: 28px;
  border: 1px solid rgba(255, 255, 255, .4);
  border-radius: 4px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
}

.shell {
  max-width: 1680px;
  margin: 0 auto;
  padding: 20px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1, h2 {
  margin: 0;
  line-height: 1.2;
}

h1 { font-size: 24px; }
h2 { font-size: 17px; }
p { margin: 6px 0 0; color: var(--muted); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--blue-dark);
  font-weight: 700;
  cursor: pointer;
}

.button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.button.muted { color: var(--muted); }

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metrics.compact { grid-template-columns: repeat(5, minmax(130px, 1fr)); }

.metric {
  min-height: 98px;
  padding: 16px;
  border: 1px solid #1b91d8;
  border-left: 8px solid var(--cyan);
  border-radius: 4px;
  background: var(--surface);
}

.metric.warning { border-left-color: var(--amber); }
.metric.money { border-left-color: var(--green); }

.metric span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  color: var(--blue);
  font-size: 25px;
  line-height: 1.1;
}

.metric em {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-style: normal;
}

/* New KPI Cards for Reporting Dashboard */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  padding: 20px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  text-decoration: none;
}

.kpi-card span {
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

.kpi-card strong {
  font-size: 32px;
  line-height: 1.1;
  color: var(--text);
  margin-bottom: 8px;
}

.kpi-card em {
  font-size: 13px;
  font-style: normal;
  color: var(--muted);
}

.kpi-card.blue { border-left: 6px solid var(--blue); }
.kpi-card.blue strong { color: var(--blue-dark); }

.kpi-card.green { border-left: 6px solid var(--green); }
.kpi-card.green strong { color: var(--green); }

.kpi-card.red { border-left: 6px solid var(--red); }
.kpi-card.red strong { color: var(--red); }

.kpi-card.amber { border-left: 6px solid var(--amber); }
.kpi-card.amber strong { color: var(--amber); }

.kpi-card.outline {
  border: 1px solid var(--line);
  box-shadow: none;
  background: #f8fafc;
}
.kpi-card.outline:hover { transform: none; box-shadow: none; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(25, 40, 55, .06);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.filters {
  display: grid;
  grid-template-columns: 2fr repeat(5, minmax(140px, 1fr)) auto auto;
  gap: 10px;
  margin-bottom: 16px;
}

input, select, textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
}

textarea { resize: vertical; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 9px;
  vertical-align: top;
}

th {
  background: #dbe3ea;
  color: #111;
  font-weight: 800;
  white-space: nowrap;
}

td { line-height: 1.35; }
.num { text-align: right; white-space: nowrap; }
.preline { white-space: pre-line; line-height: 1.5; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.badge, .status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.ok { background: #e8f6ef; color: var(--green); }
.badge.risk { background: #fff4d8; color: #996300; }
.status { background: #e9f3fb; color: var(--blue-dark); }

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border-left: 3px solid var(--blue);
  background: #f7fafc;
  color: var(--text);
}

.timeline-item small { color: var(--muted); }

.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px 14px;
  margin: 14px 0 0;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 700;
}

.detail-list dd { margin: 0; }

.stack-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.stack-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 700;
}

.money-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.money-row div {
  padding: 14px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.money-row span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.money-row strong {
  display: block;
  margin-top: 7px;
  color: var(--blue-dark);
  font-size: 19px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #e7edf3;
}

.login-box {
  width: min(420px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 18px 60px rgba(24, 38, 52, .16);
}

.login-brand {
  color: var(--blue);
  font-size: 30px;
  font-weight: 900;
  margin-bottom: 14px;
}

.login-box small {
  display: block;
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.4;
}

.alert {
  margin: 14px 0;
  padding: 10px 12px;
  border: 1px solid #efb2ae;
  border-radius: 4px;
  background: #fff0ef;
  color: var(--red);
  font-weight: 700;
}

/* ── data-table: luôn scroll ngang ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}
.data-table th, .data-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
  white-space: nowrap;
}
.data-table th {
  background: #1a5276;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}
.data-table td { font-size: 13px; line-height: 1.4; white-space: normal; }
.data-table tbody tr:hover td { background: #f0f6fb; }
.panel > .data-table,
section > .data-table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Hamburger ── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 38px; height: 38px;
  padding: 6px;
  border: none;
  background: rgba(255,255,255,.15);
  border-radius: 6px;
  cursor: pointer;
  margin-left: auto;
}
.hamburger span {
  display: block;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: all .25s;
}
.hamburger.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-footer-mobile { display: none; }
.btn-logout-mobile {
  margin-top: 6px;
  width: 100%;
  padding: 10px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

/* ── Tablet (≤ 960px) ── */
@media (max-width: 960px) {
  .topbar { padding: 10px 16px; gap: 12px; }
  .brand { font-size: 18px; }
  .security { display: none; }
  .hamburger { display: flex; }

  .topbar-nav {
    display: none;
    position: fixed;
    top: 58px; left: 0; right: 0;
    background: #055b9b;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px 16px;
    z-index: 999;
    box-shadow: 0 6px 20px rgba(0,0,0,.25);
    max-height: calc(100vh - 58px);
    overflow-y: auto;
  }
  .topbar-nav.open { display: flex; }
  .topbar-nav a {
    display: block;
    padding: 12px 14px;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    border-radius: 6px;
  }
  .topbar-nav a.active,
  .topbar-nav a:hover { background: rgba(255,255,255,.18); }
  .nav-footer-mobile {
    display: block;
    margin-top: 10px;
    border-top: 1px solid rgba(255,255,255,.2);
    padding-top: 10px;
  }

  .shell { padding: 12px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-head > div { display: flex; flex-wrap: wrap; gap: 8px; }
  h1 { font-size: 20px; }
  h2 { font-size: 15px; }

  .metrics, .metrics.compact { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, 1fr); }
  .money-row { grid-template-columns: repeat(2, 1fr); }

  table, .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap { overflow-x: auto; }
}

/* ── Phone portrait (≤ 540px) ── */
@media (max-width: 540px) {
  .topbar { padding: 8px 12px; min-height: 52px; }
  .brand { font-size: 16px; }
  .shell { padding: 8px; }

  h1 { font-size: 18px; }
  h2 { font-size: 14px; }

  .metrics, .metrics.compact { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .money-row { grid-template-columns: 1fr; }
  .detail-list { grid-template-columns: 1fr; gap: 6px; }
  .detail-list dt { font-size: 12px; color: var(--muted); }
  .panel { padding: 12px; }
  .panel-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .page-head { gap: 8px; }

  .button { min-height: 38px; padding: 8px 12px; font-size: 13px; }

  /* Bảng trên điện thoại: chữ nhỏ hơn, cell gọn hơn */
  th, td { padding: 6px 7px; font-size: 12px; }
  .data-table th, .data-table td { padding: 7px 8px; font-size: 12px; }
}

/* ══════════════════════════════════════════════════════════
   Utility responsive grids
   ══════════════════════════════════════════════════════════ */
.resp-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}
.resp-grid-2-tight {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}
.resp-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

@media (max-width: 640px) {
  .resp-grid-2        { grid-template-columns: 1fr; gap: 14px; }
  .resp-grid-2-tight  { grid-template-columns: 1fr; gap: 10px; }
  .resp-grid-3        { grid-template-columns: 1fr 1fr; gap: 10px; }
}
@media (max-width: 400px) {
  .resp-grid-3        { grid-template-columns: 1fr; }
}

/* Sync modal config grid — stack on narrow phones */
.sync-config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 420px) {
  .sync-config-grid { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════════════
   Notebook — responsive layout
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .nb-shell {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: unset !important;
    height: auto !important;
    overflow: visible !important;
  }
  .nb-sidebar {
    height: 270px !important;
    border-right: none !important;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
  }
  .nb-main {
    flex: 1;
    height: calc(100vh - 330px) !important;
    min-height: 400px;
  }
}

@media (max-width: 540px) {
  .nb-shell { height: auto !important; }
  .nb-sidebar { height: 220px !important; }
  .nb-main {
    height: calc(100vh - 280px) !important;
    min-height: 350px;
  }
  .nb-editor-head { padding: 10px 12px 8px; gap: 6px; flex-wrap: wrap; }
  .nb-title-input { font-size: 15px; }
  .nb-toolbar { padding: 5px 10px; gap: 3px; }
  .nb-content { padding: 12px 14px; }
  .nb-files-panel { padding: 10px 12px 12px; }
  audio { max-width: 100% !important; height: 36px !important; }
  .nb-new-btn { font-size: 13px; padding: 9px 10px; }
  .nb-cat-chip { font-size: 11px; padding: 4px 8px; }
}

/* ══════════════════════════════════════════════════════════
   Import page panels — touch-friendly buttons
   ══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .import-section-panel { padding: 16px !important; }
}
