/* DMS Design System — Clean + Modern + Glassmorphism-inspired (Doc 4) */

:root {
  --navy: #0f1e3d;
  --navy-soft: #16294f;
  --accent: #2563eb;
  --accent-soft: #eaf0ff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --text: #1a2233;
  --text-muted: #6b7686;
  --bg: #f4f6fb;
  --card-bg: rgba(255, 255, 255, 0.72);
  --border: rgba(15, 30, 61, 0.08);
  --radius: 14px;
  --shadow: 0 8px 30px rgba(15, 30, 61, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }

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

.sidebar {
  width: 250px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-soft) 100%);
  color: #cfd8ee;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 22px; color: #fff; font-weight: 700; font-size: 18px; }
.sidebar .brand img.brand-logo { width: 34px; height: 34px; flex-shrink: 0; }
.sidebar .brand small { display: block; font-weight: 400; font-size: 11px; color: #97a4c4; }

.sidebar nav {
  flex: 1;
  overflow-y: auto;
  /* Thin, theme-matched scrollbar instead of the default bulky browser one. */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
  padding-right: 4px;
}
.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-track { background: transparent; }
.sidebar nav::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.18);
  border-radius: 10px;
}
.sidebar nav::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, 0.32); }
.sidebar .nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  color: #cfd8ee;
  font-size: 14px;
  margin-bottom: 2px;
}
.sidebar .nav-item.active, .sidebar .nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar .nav-section-label {
  padding: 14px 12px 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7683a8;
}
.sidebar .nav-section-label:first-of-type { padding-top: 6px; }

.support-session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: linear-gradient(90deg, #7c2d12, #92400e);
  color: #fff8ee;
  font-size: 13px;
}
.support-session-banner form { margin: 0; }
.support-session-banner button {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
.support-session-banner button:hover { background: rgba(255,255,255,0.25); }

.sidebar .footer-user {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 14px;
  font-size: 13px;
  color: #97a4c4;
}
.sidebar .footer-user strong { color: #fff; display: block; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-title { display: flex; align-items: center; gap: 12px; }
.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
}
.topbar-search {
  flex: 1;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #eef1f8;
  border-radius: 10px;
  padding: 8px 14px;
  margin: 0 20px;
}
.topbar-search-icon { color: var(--text-muted); font-size: 14px; }
.topbar-search input { flex: 1; border: none; background: transparent; outline: none; font-size: 13.5px; }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.topbar-date {
  font-size: 12.5px;
  color: var(--text-muted);
  background: #eef1f8;
  padding: 7px 12px;
  border-radius: 8px;
  white-space: nowrap;
}
.topbar-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #eef1f8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
}
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar .user .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #1d4fd1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.topbar .user strong { display: block; font-size: 14px; }
.topbar .user span { color: var(--text-muted); }

.content { padding: 26px 28px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi-card .label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-card .value { font-size: 24px; font-weight: 700; }
.kpi-card .sub { font-size: 12px; color: var(--success); margin-top: 6px; }

.placeholder-note {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--accent-soft);
  border: 1px dashed #c3d3ff;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 20px;
}

/* ---------- Auth pages (legacy fallback, kept for any other simple auth screens) ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top left, #1c3568, var(--navy) 60%);
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(16px);
  border-radius: 18px;
  padding: 34px 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--text-muted); font-size: 13px; margin: 0 0 22px; }

/* ---------- Login page: full-bleed background + book-style flip card ---------- */
.login-body { margin: 0; min-height: 100vh; overflow-x: hidden; }

.login-bg {
  position: fixed;
  inset: 0;
  background-color: var(--navy);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 0;
}
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.login-stage {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  perspective: 1800px;
}

.flip-card {
  width: 100%;
  max-width: 420px;
}
.flip-card-inner {
  position: relative;
  width: 100%;
  min-height: 460px;
  transition: transform 0.7s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
}
.flip-card.is-flipped .flip-card-inner { transform: rotateY(180deg); }

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-back { transform: rotateY(180deg); }

.login-glass {
  height: 100%;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 22px;
  padding: 34px 32px;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.45);
  color: #fff;
}

.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand img { width: 40px; height: 40px; }
.login-brand strong { display: block; font-size: 17px; letter-spacing: 0.02em; }
.login-brand small { display: block; font-size: 11px; color: rgba(255,255,255,0.75); }

.login-glass h1 { font-size: 21px; margin: 0 0 4px; color: #fff; }
.login-glass p.sub { color: rgba(255,255,255,0.78); font-size: 13px; margin: 0 0 20px; line-height: 1.5; }

.field-glass label { color: rgba(255,255,255,0.9); }
.field-glass input {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
}
.field-glass input::placeholder { color: rgba(255,255,255,0.5); }
.field-glass input:focus { border-color: #7dabff; box-shadow: 0 0 0 3px rgba(125,171,255,0.25); }

.login-row { display: flex; align-items: center; justify-content: space-between; margin: -6px 0 16px; }
.flip-link { color: rgba(255,255,255,0.85); font-size: 12.5px; text-decoration: underline; }
.flip-link:hover { color: #fff; }

.reset-help-list { padding-left: 18px; margin: 0 0 20px; font-size: 12.5px; color: rgba(255,255,255,0.85); line-height: 1.6; }

.login-glass .alert-error { background: rgba(220,38,38,0.18); color: #ffd7d7; border: 1px solid rgba(220,38,38,0.4); }

.login-glass .powered-by { text-align: center; font-size: 11.5px; color: rgba(255,255,255,0.6); margin-top: 18px; }
.login-glass .powered-by a { color: rgba(255,255,255,0.85); font-weight: 600; }

@media (max-width: 480px) {
  .flip-card-inner { min-height: 500px; }
  .login-glass { padding: 26px 20px; }
}
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text); font-weight: 600; }
.field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid #d7deee;
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field select { width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid #d7deee; font-size: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .two-col { grid-template-columns: 1fr; } }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-align: center;
}
.btn:hover { background: #1d4fd1; }

.alert { padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fdecec; color: var(--danger); border: 1px solid #f5c2c2; }
.alert-success { background: #eafaf0; color: var(--success); border: 1px solid #bfe8cd; }

.powered-by { text-align: center; font-size: 12px; color: #97a4c4; margin-top: 18px; }
.powered-by a { color: #cfd8ee; font-weight: 600; }

/* ---------- Tables ---------- */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th { text-align: left; color: var(--text-muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-active { background: #eafaf0; color: var(--success); }
.badge-suspended { background: #fdf3e5; color: var(--warning); }
.badge-deactivated { background: #fdecec; color: var(--danger); }

.footer-brand {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 18px;
  flex-shrink: 0;
  margin-top: auto;
}
.footer-brand a { color: var(--accent); font-weight: 600; }

/* ---------- RSS: grouped tables & multi-column sections ---------- */
.rss-info-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  align-items: center;
  font-size: 13px;
}
.rss-info-bar strong { display: block; font-size: 14px; margin-top: 2px; }
.rss-info-bar .label { color: var(--text-muted); font-size: 12px; }

.rss-summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin: 18px 0 22px;
}
.rss-summary-strip .stat { text-align: left; }
.rss-summary-strip .stat .value { font-size: 20px; font-weight: 700; }
.rss-summary-strip .stat .label { font-size: 12px; color: var(--text-muted); }

.rss-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 20px;
}
@media (max-width: 1000px) { .rss-grid { grid-template-columns: 1fr; } }

.rss-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 20px;
}
@media (max-width: 900px) { .rss-grid-2col { grid-template-columns: 1fr; } }

.section-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
}
.section-title .num {
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
}
.section-sub { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; }

table.grouped-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.grouped-table th, table.grouped-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}
table.grouped-table th.group-header {
  background: var(--accent-soft);
  border-bottom: 1px solid #c3d3ff;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--navy);
}
table.grouped-table td:first-child, table.grouped-table th:first-child { text-align: left; }
table.grouped-table input, table.grouped-table select {
  width: 56px;
  padding: 5px;
  border-radius: 6px;
  border: 1px solid #d7deee;
  font-size: 12.5px;
  text-align: center;
}
table.grouped-table select { width: auto; }
table.grouped-table input.wide { width: 90px; }

.settlement-card {
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.settlement-card h4 { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.settlement-card .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13.5px; }
.settlement-card .row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; font-weight: 700; }

.cash-status-card {
  border-radius: 12px;
  padding: 18px;
  text-align: center;
}
.cash-status-card .amount { font-size: 26px; font-weight: 800; margin: 4px 0; }
.cash-status-balanced { background: #eafaf0; color: #16a34a; }
.cash-status-short { background: #fdecec; color: #dc2626; }
.cash-status-excess { background: #fdf3e5; color: #d97706; }

.route-status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 14px; margin-top: 10px; }
.route-status-grid .item { font-size: 12.5px; }
.route-status-grid .ok { color: #16a34a; }
.route-status-grid .warn { color: #d97706; }

.add-row-btn {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px dashed #c3d3ff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Responsive: tablet & mobile ---------- */
@media (max-width: 1024px) {
  .topbar-search { display: none; }
}

@media (max-width: 900px) {
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .app-shell.sidebar-collapsed .sidebar { transform: translateX(0); }
  .app-shell.sidebar-collapsed::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 30;
  }

  .content { padding: 18px 16px; }
  .topbar { padding: 12px 16px; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .rss-grid, .rss-grid-2col { grid-template-columns: 1fr; }

  table.data-table { display: block; overflow-x: auto; white-space: nowrap; }
  table.grouped-table { display: block; overflow-x: auto; }

  .topbar .user > div { display: none; }
  .topbar-date { display: none; }
}

@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .content { padding: 14px 12px; }
}

/* ---------- Dashboard widgets ---------- */
.dash-header { margin-bottom: 18px; }
.dash-header h2 { margin: 0 0 4px; font-size: 20px; }
.dash-header p { margin: 0; color: var(--text-muted); font-size: 13.5px; }

.mini-bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 130px; padding-top: 10px; }
.mini-bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; height: 100%; gap: 6px; }
.mini-bar { width: 100%; max-width: 34px; background: linear-gradient(180deg, var(--accent), #1d4fd1); border-radius: 6px 6px 2px 2px; }
.mini-bar-col span { font-size: 11px; color: var(--text-muted); }

.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.alert-list li { font-size: 13px; background: #fff7ed; border: 1px solid #fde3c4; border-radius: 8px; padding: 8px 12px; color: #9a5b12; }

.quick-actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }

/* ---------- Print support ---------- */
@media print {
  .sidebar, .topbar, .footer-brand, .no-print, .support-session-banner { display: none !important; }
  .app-shell, .main, .content { display: block !important; width: 100% !important; margin: 0 !important; padding: 0 !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}

/* Standalone printable A4 report sheets (reports/*_print.php — not wrapped in the app shell) */
.print-page {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto 14px;
  padding: 14mm;
  background: #fff;
  box-sizing: border-box;
  page-break-after: always;
  font-size: 12.5px;
  color: #1c2333;
}
.print-page:last-child { page-break-after: auto; }
.print-toolbar { text-align: center; padding: 14px; background: #eef1f8; }
.print-toolbar button {
  background: #2b57d6; color: #fff; border: none; padding: 10px 22px;
  border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.print-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #1c2333; padding-bottom: 12px; margin-bottom: 16px; }
.print-header .biz-name { font-size: 17px; font-weight: 700; }
.print-header .biz-meta { font-size: 11.5px; color: #555; margin-top: 2px; line-height: 1.5; }
.print-header .doc-meta { text-align: right; font-size: 11.5px; line-height: 1.6; }
.print-header .doc-meta .doc-title { font-size: 15px; font-weight: 700; color: #1c2333; }
.print-customer { display: flex; justify-content: space-between; margin-bottom: 14px; font-size: 12px; }
.print-customer .block { max-width: 48%; }
.print-customer .block strong { display: block; margin-bottom: 3px; }
.print-items { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.print-items th, .print-items td { border: 1px solid #ccc; padding: 6px 8px; text-align: left; font-size: 11.5px; }
.print-items th { background: #f2f4f9; }
.print-items td.num, .print-items th.num { text-align: right; }
.print-totals { display: flex; justify-content: flex-end; margin-bottom: 30px; }
.print-totals table { border-collapse: collapse; font-size: 12px; }
.print-totals td { padding: 4px 10px; }
.print-totals tr.grand td { font-weight: 700; font-size: 13.5px; border-top: 1px solid #333; }
.print-signatures { display: flex; justify-content: space-between; margin-top: 50px; }
.print-signatures .sig { width: 30%; text-align: center; font-size: 11px; }
.print-signatures .sig .line { border-top: 1px solid #333; margin-bottom: 6px; height: 40px; }
@media print {
  .print-toolbar { display: none !important; }
  .print-page { margin: 0; box-shadow: none; }
}
