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

:root {
  --blue: #1c5ea8;
  --blue-dark: #123a5e;
  --blue-light: #e8f1fb;
  --green: #1a7f4e;
  --red: #b3261e;
  --orange: #b3690f;
  --bg: #f2f5f8;
  --card: #ffffff;
  --border: #dde3ea;
  --text: #1f2937;
  --muted: #6b7280;
  --sidebar-w: 224px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Sarabun', sans-serif; background: var(--bg); color: var(--text); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #123a5e 0%, #1c5ea8 100%); }
.login-wrap { padding: 16px; }
.login-card { background: #fff; border-radius: 14px; padding: 36px 30px; width: 100%; max-width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,0.25); }
.login-logo { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.login-logo .truck { font-size: 26px; }
.login-logo h1 { font-size: 22px; margin: 0; color: var(--blue-dark); letter-spacing: -0.5px; }
.login-card p.sub { margin: 4px 0 20px; color: var(--muted); font-size: 13px; }
.demo-hint { background: var(--blue-light); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--blue-dark); margin-top: 14px; }

label { display: block; font-size: 13px; margin: 10px 0 4px; color: var(--muted); }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 14px; background: #fff; }
button { font-family: inherit; cursor: pointer; }

.btn { padding: 8px 15px; border-radius: 8px; border: none; font-size: 13.5px; font-weight: 600; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; margin-top: 18px; }
.error-msg { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--blue-dark);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 210;
  transition: transform 0.25s ease;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 35, 0.5);
  z-index: 200;
}
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--blue-dark);
  padding: 4px 6px;
  margin-right: 4px;
}
.topbar-left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.sidebar .brand { padding: 18px 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.sidebar .brand .truck { font-size: 20px; }
.sidebar .brand h1 { font-size: 16px; margin: 0; }
.sidebar nav { padding: 10px 0; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; font-size: 13.5px; color: rgba(255,255,255,0.78); cursor: pointer; border-left: 3px solid transparent; }
.nav-item .ico { width: 18px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.1); color: #fff; border-left-color: #ffb020; font-weight: 600; }
.nav-section-label { padding: 14px 16px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: rgba(255,255,255,0.45); }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 12px 22px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.topbar .page-title { font-size: 16px; font-weight: 600; color: var(--blue-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who { font-size: 13px; color: var(--muted); display: flex; align-items: center; white-space: nowrap; }
.topbar .who button { margin-left: 12px; }

.content { padding: 20px 22px; max-width: 1200px; width: 100%; }
.page { display: none; }
.page.active { display: block; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.card h2 { font-size: 15.5px; margin: 0 0 14px; color: var(--blue-dark); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
tr.profit-pos td.num.profit { color: var(--green); font-weight: 600; }
tr.profit-neg td.num.profit { color: var(--red); font-weight: 600; }
.tfoot-total td { font-weight: 700; background: #fafbfc; }

.actions-row { display: flex; gap: 6px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { min-width: 130px; }
.filters label { margin: 0 0 4px; }
.hidden { display: none !important; }

/* Dashboard */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.stat-card .label { font-size: 12px; color: var(--muted); }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 4px; color: var(--blue-dark); }
.stat-card .value.pos { color: var(--green); }
.stat-card .value.neg { color: var(--red); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-blue { background: var(--blue-light); color: var(--blue-dark); }
.badge-green { background: #e6f4ec; color: var(--green); }
.badge-red { background: #fbe9e7; color: var(--red); }
.badge-orange { background: #fdf0e0; color: var(--orange); }
.badge-gray { background: #eef0f2; color: var(--muted); }

/* Calendar */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar .dow { font-size: 12px; color: var(--muted); text-align: center; padding-bottom: 4px; font-weight: 600; }
.calendar .day-cell { min-height: 74px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px; font-size: 12px; background: #fff; }
.calendar .day-cell.empty { background: transparent; border: none; }
.calendar .day-num { font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.calendar .day-cell.today .day-num { color: var(--blue); }
.calendar .booking-chip { background: var(--blue-light); color: var(--blue-dark); border-radius: 5px; padding: 1px 5px; font-size: 10.5px; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.calendar-nav .month-label { font-weight: 600; color: var(--blue-dark); min-width: 140px; text-align: center; }

.subtabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.subtab { padding: 8px 14px; font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.subtab.active { color: var(--blue-dark); border-bottom-color: var(--blue); font-weight: 600; }
.subpage { display: none; }
.subpage.active { display: block; }

/* ---------- Mobile ---------- */
@media (max-width: 880px) {
  .hamburger-btn { display: inline-flex; align-items: center; justify-content: center; }

  .sidebar { transform: translateX(-100%); box-shadow: 4px 0 24px rgba(0,0,0,0.25); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }

  .main { margin-left: 0; }

  .topbar { padding: 10px 14px; }
  .topbar .page-title { font-size: 15px; }
  .topbar .who #whoAmI { display: none; }
  .topbar .who button { margin-left: 0; font-size: 12.5px; }

  .content { padding: 14px; }
  .card { padding: 14px; }

  .grid { grid-template-columns: 1fr; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .stat-card .value { font-size: 18px; }

  .filters { gap: 8px; }
  .filters .field { min-width: 0; flex: 1 1 45%; }

  table { font-size: 12px; }
  th, td { padding: 6px 8px; }

  .calendar { gap: 4px; }
  .calendar .day-cell { min-height: 46px; padding: 3px 4px; font-size: 10.5px; }
  .calendar .booking-chip { font-size: 9px; padding: 1px 3px; }
  .calendar-nav .month-label { min-width: 0; flex: 1; }

  .login-card { padding: 28px 22px; }
}

@media (max-width: 420px) {
  .stat-cards { grid-template-columns: 1fr 1fr; }
  .calendar .dow { font-size: 10px; }
}
