/* Phinyamath OIL -- shared design system (used by both sys/ and sys/admin/) */

@font-face {
  font-family: 'Noto Sans Lao';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/NotoSansLao-lao.woff2') format('woff2');
  unicode-range: U+0E81-0EDF, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Noto Sans Lao';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/NotoSansLao-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-tint: #eaf1ff;
  --violet: #7c3aed;
  --violet-tint: #ede9fe;
  --teal: #0d9488;
  --teal-tint: #ccfbf1;
  --pink: #db2777;
  --pink-tint: #fce7f3;
  --amber: #d97706;
  --amber-tint: #fef3c7;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --success-tint: #dcfce7;
  --warning: #d97706;
  --warning-tint: #fef3c7;
  --danger: #dc2626;
  --danger-tint: #fee2e2;
  --info: #0891b2;
  --info-tint: #cffafe;
  --radius-sm: 8px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --sidebar-w: 250px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans Lao', 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.content {
  background:
    radial-gradient(900px 500px at 100% -10%, rgba(37, 99, 235, .07), transparent),
    radial-gradient(700px 400px at -10% 0%, rgba(124, 58, 237, .05), transparent);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

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

.sidebar {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 40;
  transition: transform .2s ease;
}
.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #7c3aed 120%);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}
.sidebar-brand small { color: rgba(255,255,255,.75) !important; }
.sidebar-brand .logo-chip {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: rgba(255,255,255,.18);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
}
.sidebar-search {
  margin: 14px 14px 4px;
  position: relative;
}
.sidebar-search input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px 8px 32px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}
.sidebar-search svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted);
}
.sidebar-nav { padding: 10px 12px 24px; }
.sidebar-section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 14px 10px 6px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
}
.sidebar-item:hover { background: var(--bg); }
.sidebar-item.active { background: linear-gradient(90deg, var(--primary-tint), transparent); color: var(--primary-dark); font-weight: 700; box-shadow: inset 3px 0 0 var(--primary); }
.sidebar-item .icon-chip {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  color: var(--text-muted);
  flex-shrink: 0;
}
.sidebar-item[data-tone="blue"] .icon-chip { background: var(--primary-tint); color: var(--primary); }
.sidebar-item[data-tone="violet"] .icon-chip { background: var(--violet-tint); color: var(--violet); }
.sidebar-item[data-tone="teal"] .icon-chip { background: var(--teal-tint); color: var(--teal); }
.sidebar-item[data-tone="pink"] .icon-chip { background: var(--pink-tint); color: var(--pink); }
.sidebar-item[data-tone="amber"] .icon-chip { background: var(--amber-tint); color: var(--amber); }
.sidebar-item[data-tone="danger"] .icon-chip { background: var(--danger-tint); color: var(--danger); }
.sidebar-item.active .icon-chip {
  background: var(--primary) !important;
  color: #fff !important;
  font-size: 13px;
}
.sidebar-item.active .icon-chip { background: var(--primary); color: #fff; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.sidebar-toggle {
  border: none;
  background: var(--bg);
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
}
.topbar-title { font-weight: 700; font-size: 15px; }
.topbar-spacer { flex: 1; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--bg);
}
.user-chip .avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.user-chip .user-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-chip .user-role { font-size: 11px; color: var(--text-muted); }
.logout-link {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  color: var(--danger);
  background: var(--danger-tint);
  flex-shrink: 0;
}

.content { padding: 22px; flex: 1; }

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-header-main { display: flex; gap: 14px; align-items: flex-start; }
.page-header .icon-chip-lg {
  width: 48px; height: 48px;
  border-radius: 13px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.page-header h1 { font-size: 21px; font-weight: 700; margin: 0 0 2px; }
.page-header .subtitle { color: var(--text-muted); font-size: 12.5px; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.stat-card .stat-top { display: flex; justify-content: space-between; align-items: flex-start; }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.stat-icon.tone-blue { background: var(--primary-tint); color: var(--primary); }
.stat-icon.tone-green { background: var(--success-tint); color: var(--success); }
.stat-icon.tone-orange { background: var(--warning-tint); color: var(--warning); }
.stat-icon.tone-red { background: var(--danger-tint); color: var(--danger); }
.stat-icon.tone-violet { background: var(--violet-tint); color: var(--violet); }
.stat-icon.tone-teal { background: var(--teal-tint); color: var(--teal); }
.stat-icon.tone-pink { background: var(--pink-tint); color: var(--pink); }
.stat-icon.tone-amber { background: var(--amber-tint); color: var(--amber); }
.stat-value { font-size: 24px; font-weight: 700; overflow-wrap: break-word; }
.stat-label { color: var(--text-muted); font-size: 13px; }
.stat-delta { font-size: 12px; font-weight: 700; display: inline-flex; gap: 3px; align-items: center; padding: 3px 9px; border-radius: 999px; }
.stat-delta.up { color: var(--success); background: var(--success-tint); }
.stat-delta.down { color: var(--danger); background: var(--danger-tint); }
.stat-delta.flat { color: var(--text-muted); background: var(--bg); }

/* ---------- Generic card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 15px; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 20px; }
.card-body.no-pad { padding: 0; }

/* ---------- Table ---------- */
/* Scrolls horizontally within its own box (never the page) -- a fading
   edge shows there's more to scroll, and the shadow only shows on the
   side that actually has hidden content (CSS-only scroll-shadow trick). */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)) local,
    linear-gradient(to right, rgba(255,255,255,0), var(--surface) 70%) 100% 0 local,
    linear-gradient(to right, rgba(15,23,42,.15), rgba(15,23,42,0)) scroll,
    linear-gradient(to left, rgba(15,23,42,.15), rgba(15,23,42,0)) 100% 0 scroll;
  background-repeat: no-repeat;
  background-color: var(--surface);
  background-size: 32px 100%, 32px 100%, 12px 100%, 12px 100%;
}
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 700;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
/* keep the row's identifying first column in view while scrolling wide tables sideways */
.data-table thead tr:first-child > th:first-child,
.data-table tbody > tr > td:first-child,
.data-table tfoot > tr > td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  box-shadow: 2px 0 4px -2px rgba(15, 23, 42, .12);
}
.data-table thead tr:first-child > th:first-child { background: var(--bg); z-index: 2; }
.data-table tbody > tr > td:first-child { background: var(--surface); }
.data-table tbody tr:hover > td:first-child { background: var(--bg); }
.data-table tbody tr.row-cancelled > td:first-child { background: var(--surface); }
.data-table tbody tr.row-subtotal > td:first-child { background: var(--warning-tint); }
.data-table tbody tr.row-total > td:first-child { background: var(--primary-tint); }
.data-table tbody tr.row-grandtotal > td:first-child { background: var(--success-tint); }
.data-table tfoot > tr > td:first-child { background: inherit; }
.data-table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--bg); }
.data-table tbody tr.row-cancelled td { opacity: .55; }
.data-table tbody tr.row-subtotal td { background: var(--warning-tint); font-weight: 600; }
.data-table tbody tr.row-total td { background: var(--primary-tint); font-weight: 700; }
.data-table tbody tr.row-grandtotal td { background: var(--success-tint); font-weight: 700; }
.num-green { color: var(--success); font-weight: 600; }
.num-blue { color: var(--primary); font-weight: 600; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge-success { color: var(--success); background: var(--success-tint); }
.badge-warning { color: var(--warning); background: var(--warning-tint); }
.badge-danger { color: var(--danger); background: var(--danger-tint); }
.badge-muted { color: var(--text-muted); background: var(--bg); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-success { background: var(--success-tint); color: var(--success); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 6px; width: 30px; height: 30px; justify-content: center; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field .control,
input.control,
select.control,
textarea.control {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  width: 100%;
}
.field .control:focus,
input.control:focus,
select.control:focus,
textarea.control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.field-icon-group { position: relative; }
.field-icon-group .control { padding-left: 36px; }
.field-icon-group .field-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

/* ---------- Pagination ---------- */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.pagination-info { font-size: 12.5px; color: var(--text-muted); }
.pagination-links { display: flex; gap: 4px; flex-wrap: wrap; }
.page-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}
.page-link:hover { background: var(--bg); }
.page-link.current { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link.disabled { opacity: .4; pointer-events: none; }
.page-size-select { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.page-size-select select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 5px 8px; font-family: inherit; font-size: 12.5px; }

/* ---------- Charts ---------- */
.chart-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; margin-bottom: 20px; align-items: stretch; }
.chart-card { display: flex; flex-direction: column; }
.chart-card .card-body { flex: 1; display: flex; flex-direction: column; }
.chart-canvas-wrap { position: relative; flex: 1; min-height: 260px; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; justify-content: center; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.chart-empty { display: flex; align-items: center; justify-content: center; flex: 1; color: var(--text-muted); font-size: 13px; min-height: 200px; }
@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .chart-canvas-wrap { min-height: 220px; }
}

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.filter-bar .field { margin-bottom: 0; min-width: 170px; }
.filter-bar .filter-actions { display: flex; gap: 8px; padding-bottom: 1px; }
.result-note { color: var(--text-muted); font-size: 13px; margin: 4px 0 14px; }

/* ---------- Alerts ---------- */
.alert-box { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; }
.alert-box.success { background: var(--success-tint); color: #14532d; }
.alert-box.error { background: var(--danger-tint); color: #7f1d1d; }
.alert-box.info { background: var(--info-tint); color: #164e63; }

/* ---------- Login page ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eaf1ff 0%, var(--bg) 55%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .12);
  padding: 34px 30px;
}
.login-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-logo .logo-chip { width: 52px; height: 52px; border-radius: 16px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; }
.login-logo .title { font-size: 17px; font-weight: 700; }
.login-logo .subtitle { font-size: 12.5px; color: var(--text-muted); }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

/* ---------- bootstrap-datepicker popup ----------
   The plugin adds a "dropdown-menu" class and expects Bootstrap core's
   .dropdown-menu{position:absolute} rule to place it; that framework
   isn't loaded here (removed as unused), so restore just the piece the
   plugin actually needs -- it sets its own inline top/left via JS. */
.datepicker.dropdown-menu {
  position: absolute;
  z-index: 1060;
  font-family: 'Noto Sans Lao', 'Segoe UI', sans-serif;
  background-color: var(--surface);
  background-clip: padding-box;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .18);
}
.datepicker table tr td.active.active,
.datepicker table tr td.today {
  background: var(--primary) !important;
  color: #fff !important;
}

/* ---------- DataTables reskin ---------- */
.dataTables_wrapper { font-family: inherit; }
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate { font-size: 13px; color: var(--text-muted); padding: 10px 4px; }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-family: inherit;
  margin-left: 6px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  padding: 4px 10px !important;
  margin-left: 4px !important;
  background: var(--surface) !important;
  color: var(--text) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled { opacity: .4; }
table.dataTable thead th { border-bottom: 1px solid var(--border) !important; }
table.dataTable.no-footer { border-bottom: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 0 100vmax rgba(15,23,42,0); }
  body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 0 10px 30px rgba(15,23,42,.2); }
  .main { margin-left: 0; }
  .content { padding: 16px; }
  .topbar-title { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .page-header { margin-bottom: 14px; }
  .page-header-actions { width: 100%; }
  .page-header-actions .btn { flex: 1; justify-content: center; }
  .filter-bar { width: 100%; }
  .filter-bar .field { flex: 1 1 140px; min-width: 0; }
  table.data-table { font-size: 12.5px; }
  .data-table thead th, .data-table tbody td { padding: 8px 9px; }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 20px; }
}
