@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* { box-sizing: border-box; }
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e3e5ea;
  --text: #171a24;
  --muted: #6b7078;
  --primary: #2c4373;
  --primary-dark: #1f325a;
  --primary-soft: #eef1f8;
  --danger: #b3413a;
  --danger-bg: #fbebe9;
  --success: #1f7a52;
  --success-bg: #e8f5ee;
  --warn: #9a6a1a;
  --warn-bg: #fbf1de;
  --sidebar-bg: #12172a;
  --sidebar-text: #9aa1b8;
  --sidebar-text-active: #ffffff;
  --radius: 12px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; }

/* ---------- Auth screens ---------- */
.center-box {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  background: linear-gradient(180deg, #eef1f7 0%, var(--bg) 60%);
}
.center-box h1 { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.center-box .subtitle { color: var(--muted); font-size: 13px; margin-top: -12px; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 34px 32px;
  box-shadow: 0 1px 2px rgba(15,18,30,0.04), 0 12px 32px rgba(15,18,30,0.08);
  width: 380px;
  border: 1px solid var(--border);
}
.card h2 { margin: 0 0 20px; font-size: 17px; font-weight: 700; }
.field-label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; display: block; }
.card input {
  width: 100%;
  padding: 11px 13px;
  margin: 0 0 18px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  font-family: var(--font);
  transition: border-color .15s, box-shadow .15s;
  background: #fbfbfc;
  color: var(--text);
}
.card input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft); }
.card input::placeholder { color: #a8adb8; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, transform .05s;
  letter-spacing: -0.005em;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.secondary:hover { background: #e2e7f3; }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.danger:hover { background: #f6d9d6; }
.btn.small { padding: 6px 12px; font-size: 12px; border-radius: 7px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.error { color: var(--danger); font-size: 13px; margin: -12px 0 14px; min-height: 16px; }

/* ---------- App shell (sidebar) ---------- */
.app-shell { display: flex; width: 100%; min-height: 100vh; }
.sidebar {
  width: 236px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  flex-shrink: 0;
}
.sidebar .brand { color: #fff; font-weight: 700; font-size: 15px; padding: 4px 10px 26px; display: flex; align-items: center; gap: 9px; letter-spacing: -0.01em; }
.sidebar .brand .dot { width: 8px; height: 8px; border-radius: 50%; background: #5b7cd6; box-shadow: 0 0 0 4px rgba(91,124,214,.22); }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 9px; margin-bottom: 2px;
  cursor: pointer; font-size: 13px; font-weight: 500;
  color: var(--sidebar-text);
}
.nav-item .ic { width: 16px; height: 16px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; opacity: .85; }
.nav-item .ic svg { width: 16px; height: 16px; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(91,124,214,.18); color: #fff; }
.nav-item.active .ic { opacity: 1; }
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer .who { font-size: 11.5px; color: var(--sidebar-text); padding: 6px 12px 10px; }

.main-area { flex: 1; min-width: 0; overflow-y: auto; }
.page-header {
  padding: 24px 32px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.page-header h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.page-header p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
.content { padding: 28px 32px; max-width: 1280px; }

/* ---------- Stat cards ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-card .label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 23px; font-weight: 700; margin-top: 8px; letter-spacing: -0.01em; }
.stat-card .value.danger { color: var(--danger); }
.stat-card .value.success { color: var(--success); }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #fafafc; font-weight: 600; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; }
tbody tr:hover { background: #fafbfd; }
tbody tr:last-child td { border-bottom: none; }
code { background: #f1f2f5; padding: 2px 7px; border-radius: 5px; font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace; color: var(--text); }

.tag { padding: 3px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.tag.truthu { background: var(--danger-bg); color: var(--danger); }
.tag.hoanvi { background: var(--success-bg); color: var(--success); }
.tag.dadu { background: #eef0f4; color: var(--muted); }
.badge { padding: 3px 9px; border-radius: 6px; font-size: 11px; font-weight: 600; background: #eef0f4; color: var(--muted); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.periods-list { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.period-chip {
  padding: 7px 15px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}
.period-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.period-chip:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="text"], .toolbar input:not([type]) {
  padding: 9px 13px; border: 1.5px solid var(--border); border-radius: 9px; font-size: 13px; min-width: 260px; background: #fff; font-family: var(--font);
}
.toolbar input:focus { outline: none; border-color: var(--primary); }
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-group select {
  padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 9px; font-size: 13px; background: #fff; font-family: var(--font); color: var(--text); cursor: pointer;
}
.filter-group select:focus { outline: none; border-color: var(--primary); }
.period-chip .chip-actions { display: inline-flex; gap: 6px; margin-left: 8px; opacity: 0; transition: opacity .1s; }
.period-chip:hover .chip-actions { opacity: 1; }
.period-chip.active .chip-actions { opacity: 1; }
.period-chip .chip-actions button { border: none; background: transparent; cursor: pointer; color: inherit; font-size: 12px; padding: 0; line-height: 1; opacity: .75; }
.period-chip .chip-actions button:hover { opacity: 1; }
.period-chip { display: inline-flex; align-items: center; }

/* ---------- Driver cards ---------- */
.driver-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 14px;
}
.driver-card .period-title { font-size: 14.5px; font-weight: 700; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.driver-card .row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.driver-card .row:last-child { border-bottom: none; }
.driver-card .label { color: var(--muted); }
.driver-card .value { font-weight: 600; font-variant-numeric: tabular-nums; }
.driver-card .value.neg { color: var(--danger); }
.driver-card .value.pos { color: var(--success); }

.hint { color: #9298a3; font-size: 12px; margin-top: 6px; }
.section-title { font-size: 15px; font-weight: 700; margin: 0 0 14px; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-size: 13px; }

.empty-state { text-align: center; padding: 64px 20px; color: var(--muted); font-size: 13.5px; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--sidebar-bg); color: #fff; padding: 12px 18px; border-radius: 9px;
  font-size: 13px; opacity: 0; transition: opacity .2s, transform .2s; transform: translateY(6px);
  box-shadow: 0 10px 24px rgba(0,0,0,.2); max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(12,14,24,.5);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.active { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 28px; width: 400px; max-height: 82vh; overflow-y: auto; }
.modal h3 { margin: 0 0 18px; font-size: 16px; font-weight: 700; }
.modal-close-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

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

/* ---------- Responsive: điện thoại ---------- */
@media (max-width: 780px) {
  .card { width: 100%; max-width: 360px; padding: 26px 22px; }

  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 10px 12px;
    gap: 4px;
  }
  .sidebar .brand { padding: 4px 10px 4px 4px; flex-shrink: 0; }
  .nav-item { margin-bottom: 0; flex-shrink: 0; white-space: nowrap; }
  .sidebar-footer { margin-top: 0; padding-top: 0; border-top: none; border-left: 1px solid rgba(255,255,255,.08); padding-left: 8px; flex-shrink: 0; }
  .sidebar-footer .who { display: none; }

  .page-header { padding: 16px 16px; flex-direction: column; align-items: flex-start; gap: 10px; }
  .content { padding: 16px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 18px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input[type="text"], .toolbar input:not([type]) { min-width: 0; width: 100%; }

  .table-wrap { overflow-x: auto; }
  table { font-size: 12px; }
  th, td { padding: 8px 10px; }

  .driver-card { padding: 18px 20px; }
  .modal { width: 92vw !important; padding: 22px; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* Kéo-thả file Excel vào trang */
body.drag-over::after {
  content: 'Thả file Excel vào đây để import';
  position: fixed;
  inset: 0;
  background: rgba(44, 67, 115, 0.92);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  pointer-events: none;
  border: 4px dashed #fff;
}
