/* ============================================================
   CanteenOS — application shell
   Tokens first; Bootstrap components are re-skinned through them.
   ============================================================ */
:root {
  --cos-ground: #f3f5f7;
  --cos-surface: #ffffff;
  --cos-surface-2: #eaeef2;
  --cos-ink: #1b2430;
  --cos-ink-2: #3d4956;
  --cos-muted: #6b7784;
  --cos-rule: #d8dee5;
  --cos-rule-soft: #e7ebf0;
  --cos-accent: #0e6f64;
  --cos-accent-ink: #0b5a51;
  --cos-accent-soft: #dff0ec;
  --cos-sidebar: #14212b;
  --cos-sidebar-ink: #c9d3dc;
  --cos-sidebar-muted: #7f8d9a;
  --cos-sidebar-active: #0e6f64;
  --cos-warn: #9a6a12;
  --cos-warn-soft: #fbf1dd;
  --cos-danger: #b42318;
  --cos-danger-soft: #fde8e6;
  --cos-radius: 8px;
  --cos-shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 8px 24px -18px rgba(20, 30, 40, .3);
  --cos-sidebar-w: 260px;
  --cos-topbar-h: 56px;

  /* Bootstrap overrides */
  --bs-body-bg: var(--cos-ground);
  --bs-body-color: var(--cos-ink);
  --bs-body-font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  --bs-body-font-size: .9375rem;
  --bs-primary: #0e6f64;
  --bs-primary-rgb: 14, 111, 100;
  --bs-link-color: #0e6f64;
  --bs-link-color-rgb: 14, 111, 100;
  --bs-link-hover-color: #0b5a51;
  --bs-border-color: var(--cos-rule);
  --bs-border-radius: var(--cos-radius);
}

html, body { height: 100%; }
body { font-feature-settings: "tnum"; -webkit-font-smoothing: antialiased; }

.btn-primary { --bs-btn-bg: var(--cos-accent); --bs-btn-border-color: var(--cos-accent); --bs-btn-hover-bg: var(--cos-accent-ink); --bs-btn-hover-border-color: var(--cos-accent-ink); --bs-btn-active-bg: var(--cos-accent-ink); --bs-btn-active-border-color: var(--cos-accent-ink); }
.btn-outline-primary { --bs-btn-color: var(--cos-accent); --bs-btn-border-color: var(--cos-accent); --bs-btn-hover-bg: var(--cos-accent); --bs-btn-hover-border-color: var(--cos-accent); --bs-btn-active-bg: var(--cos-accent); }
.form-control:focus, .form-select:focus { border-color: var(--cos-accent); box-shadow: 0 0 0 .2rem rgba(14, 111, 100, .18); }
.form-check-input:checked { background-color: var(--cos-accent); border-color: var(--cos-accent); }
.text-primary { color: var(--cos-accent) !important; }
.bg-accent-soft { background: var(--cos-accent-soft); }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--cos-sidebar-w); flex: 0 0 auto; background: var(--cos-sidebar); color: var(--cos-sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  transition: margin .2s ease;
}
.sidebar::-webkit-scrollbar { width: 6px; } .sidebar::-webkit-scrollbar-thumb { background: #2b3a47; border-radius: 3px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 18px; height: var(--cos-topbar-h); border-bottom: 1px solid rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand .mark { width: 30px; height: 30px; border-radius: 7px; background: var(--cos-accent); display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff; }
.brand .name { font-weight: 600; font-size: 15px; letter-spacing: .01em; line-height: 1.1; }
.brand .tag { font-size: 11px; color: var(--cos-sidebar-muted); }
.nav-side { list-style: none; margin: 0; padding: 10px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.nav-side .group-title {
  display: flex; align-items: center; justify-content: space-between; width: 100%; background: none; border: 0;
  color: var(--cos-sidebar-ink); padding: 9px 10px; border-radius: 6px; font-size: 14px; text-align: start;
}
.nav-side .group-title:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-side .group-title .bi-chevron-down { font-size: 11px; transition: transform .15s; color: var(--cos-sidebar-muted); }
.nav-side .group-title[aria-expanded="true"] .bi-chevron-down { transform: rotate(180deg); }
.nav-side a.item, .nav-side span.item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--cos-sidebar-ink);
  text-decoration: none; font-size: 14px;
}
.nav-side a.item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-side a.item.active { background: var(--cos-sidebar-active); color: #fff; }
.nav-side .sub a.item, .nav-side .sub span.item { padding-inline-start: 34px; font-size: 13.5px; }
.nav-side .item .bi { font-size: 15px; width: 18px; text-align: center; color: var(--cos-sidebar-muted); }
.nav-side a.item.active .bi, .nav-side a.item:hover .bi { color: #fff; }
.nav-side span.item.soon { color: var(--cos-sidebar-muted); cursor: default; }
.nav-side .soon .badge { font-size: 10px; font-weight: 500; background: rgba(255,255,255,.08); color: var(--cos-sidebar-muted); margin-inline-start: auto; }
.sidebar-foot { margin-top: auto; padding: 12px 18px; font-size: 11.5px; color: var(--cos-sidebar-muted); border-top: 1px solid rgba(255,255,255,.06); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--cos-topbar-h); background: var(--cos-surface); border-bottom: 1px solid var(--cos-rule);
  display: flex; align-items: center; gap: 12px; padding: 0 18px; position: sticky; top: 0; z-index: 1020;
}
.topbar .page-title { font-weight: 600; font-size: 16px; margin: 0; }
.topbar .spacer { flex: 1; }
.school-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--cos-accent-soft); color: var(--cos-accent-ink); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 500; border: 0; }
.school-pill .bi { font-size: 14px; }
.user-menu .btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--cos-rule); background: var(--cos-surface); border-radius: 999px; padding: 3px 10px 3px 4px; font-size: 13.5px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--cos-surface-2); color: var(--cos-ink-2); display: grid; place-items: center; font-weight: 600; font-size: 12px; }
.content { padding: 22px 22px 40px; flex: 1; }
.content-narrow { max-width: 1100px; }

/* ---------- Cards / tables ---------- */
.card { border: 1px solid var(--cos-rule); box-shadow: var(--cos-shadow); border-radius: var(--cos-radius); }
.card-header { background: var(--cos-surface); border-bottom: 1px solid var(--cos-rule-soft); font-weight: 600; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; }
.stat .label { font-size: 12.5px; color: var(--cos-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 26px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12.5px; color: var(--cos-muted); }
.table { --bs-table-striped-bg: rgba(234, 238, 242, .45); font-size: 14px; }
.table thead th { font-size: 12.5px; color: var(--cos-ink-2); background: var(--cos-surface-2); border-bottom: 1px solid var(--cos-rule); white-space: nowrap; font-weight: 600; }
.table td { vertical-align: middle; }
.num { font-variant-numeric: tabular-nums; text-align: end; }
.ltr { direction: ltr; unicode-bidi: embed; }
.mono { font-family: Consolas, "IBM Plex Mono", monospace; font-size: .92em; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 20px; font-weight: 600; margin: 0; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--cos-muted); padding: 36px 12px; }
.empty .bi { font-size: 34px; display: block; margin-bottom: 8px; opacity: .5; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth .panel { background: var(--cos-sidebar); color: #fff; display: flex; flex-direction: column; justify-content: space-between; padding: 40px 48px; }
.auth .panel h1 { font-size: 34px; font-weight: 700; line-height: 1.25; text-wrap: balance; margin: 0 0 12px; }
.auth .panel p { color: var(--cos-sidebar-ink); max-width: 46ch; }
.auth .panel .brand { padding: 0; height: auto; border: 0; }
.auth .panel ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; color: var(--cos-sidebar-ink); font-size: 14px; }
.auth .panel ul li { display: flex; gap: 10px; align-items: center; }
.auth .panel ul .bi { color: #4db6a6; }
.auth .form-side { display: grid; place-items: center; padding: 32px 16px; }
.auth .form-card { width: 100%; max-width: 400px; }
.auth .form-card h2 { font-size: 22px; font-weight: 600; margin-bottom: 4px; }
.auth .form-card .sub { color: var(--cos-muted); margin-bottom: 22px; }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth .panel { display: none; } }

/* ---------- Toasts ---------- */
.toast-container { z-index: 1090; }
.toast { border: 0; box-shadow: var(--cos-shadow); }

/* ---------- Responsive sidebar ---------- */
@media (max-width: 991.98px) {
  .sidebar { position: fixed; inset-inline-start: 0; z-index: 1040; margin-inline-start: calc(-1 * var(--cos-sidebar-w)); }
  body.sidebar-open .sidebar { margin-inline-start: 0; }
  body.sidebar-open .backdrop { display: block; }
  .backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1035; }
  .content { padding: 16px 16px 32px; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
}

/* ---------- Lists & forms (Phase 1) ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters .form-control, .filters .form-select { width: auto; min-width: 150px; }
.filters input[type="search"] { min-width: 220px; }
.filters input[type="date"] { min-width: 150px; }
.row-inactive td { color: var(--cos-muted); }
.row-inactive td a { color: var(--cos-muted) !important; }
.badge-soft-success { background: #dcf3e7; color: #146c43; font-weight: 500; }
.badge-soft-danger { background: var(--cos-danger-soft); color: var(--cos-danger); font-weight: 500; }
.badge-soft-warn { background: var(--cos-warn-soft); color: var(--cos-warn); font-weight: 500; }
.badge-soft-muted { background: var(--cos-surface-2); color: var(--cos-ink-2); font-weight: 500; }
.badge-soft-accent { background: var(--cos-accent-soft); color: var(--cos-accent-ink); font-weight: 500; }
.card-footer { background: var(--cos-surface); border-top: 1px solid var(--cos-rule-soft); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagination { --bs-pagination-active-bg: var(--cos-accent); --bs-pagination-active-border-color: var(--cos-accent); --bs-pagination-color: var(--cos-ink-2); }
[dir="rtl"] .rtl-flip { transform: scaleX(-1); display: inline-block; }
.form-label.required::after { content: " *"; color: var(--cos-danger); }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; }
.check-list .form-check { margin: 0; padding-inline-start: 1.6em; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Permission matrix */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.perm-module { border-bottom: 1px solid var(--cos-rule-soft); border-inline-end: 1px solid var(--cos-rule-soft); padding: 12px 16px; }
.perm-module-head { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 8px; cursor: pointer; }
.perm-module-head .form-check-input { margin: 0; }
.perm-items { display: flex; flex-direction: column; gap: 3px; }
.perm-items .form-check { margin: 0; font-size: 13.5px; }

/* Settings */
.settings-list { padding: 0; }
.setting-row { display: flex; align-items: center; gap: 16px; padding: 12px 18px; border-bottom: 1px solid var(--cos-rule-soft); }
.setting-row:last-child { border-bottom: 0; }
.setting-label { flex: 1 1 auto; min-width: 0; }
.setting-control { flex: 0 0 220px; }
.setting-control .form-check { padding-inline-start: 2.5em; }
@media (max-width: 575.98px) { .setting-row { flex-direction: column; align-items: stretch; } .setting-control { flex-basis: auto; } }

/* Audit details */
.dl-compact { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.dl-compact dt { color: var(--cos-muted); font-weight: 500; }
.dl-compact dd { margin: 0; }
.diff-table td { font-size: 13px; }
.diff-changed td { background: #fffbe6; }
.diff-old { color: var(--cos-danger); }
.diff-new { color: #146c43; font-weight: 500; }

/* ---------- Catalog (Phase 2) ---------- */
.thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; display: inline-block; vertical-align: middle; }
.thumb-empty { opacity: .35; }
.color-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; border: 1px solid rgba(0,0,0,.15); }
.form-control-color { width: 44px; padding: 2px; }
.nav-tabs .nav-link { color: var(--cos-ink-2); font-weight: 500; }
.nav-tabs .nav-link.active { color: var(--cos-accent-ink); border-bottom-color: var(--cos-surface); }
.card-header-tabs { margin-bottom: -1px; }
.tab-content .table-sm .form-control-sm, .tab-content .table-sm .form-select-sm { min-width: 90px; }
.conv-form .form-select-sm { min-width: 120px; }

/* ---------- Inventory (Phase 3) ---------- */
.dl-inline { grid-template-columns: max-content 1fr max-content 1fr; }
@media (max-width: 767.98px) { .dl-inline { grid-template-columns: max-content 1fr; } }
#line-results .list-group-item { text-align: start; }
.batch-cell .form-select, .batch-cell .new-batch { min-width: 180px; }
#lines-table .qty, #lines-table .cost { min-width: 90px; }
#lines-table .unit { min-width: 110px; }
.new-batch { display: flex; gap: .25rem; }
.new-batch[hidden] { display: none; }
.new-batch input[type="text"] { min-width: 110px; }

/* ---------- Purchasing (Phase 4) ---------- */
#lines-table .price, #lines-table .disc, #lines-table .tax { min-width: 80px; }
#lines-table .batch { min-width: 110px; }
#lines-table .expiry { min-width: 140px; }
.totals dd .form-control { max-width: 160px; margin-inline-start: auto; }
.validation-summary-valid { display: none; }

/* ---- Reports & dashboard (Phase 9) ---- */
.report-card { transition: box-shadow .15s, transform .15s; }
.report-card:hover { box-shadow: 0 4px 16px rgba(20, 33, 43, .12); transform: translateY(-1px); }
.report-icon { width: 42px; height: 42px; border-radius: 10px; background: var(--cos-surface-2); color: var(--cos-primary, #0e6f64); display: flex; align-items: center; justify-content: center; font-size: 20px; flex: 0 0 auto; }
.report-chart { position: relative; height: 280px; }
.report-chart-pie { height: 260px; }
.report-table th, .report-table td { white-space: nowrap; }
.dash-chart { position: relative; height: 240px; }
.dash-chart-lg { height: 300px; }
.stat .value.text-success, .stat .value.text-danger { font-weight: 700; }
.stat .delta { font-size: 12px; }
.alert-list a { text-decoration: none; }
.alert-list .badge { min-width: 2.2em; }
.stat .value { white-space: nowrap; }
.stat-sm .value { font-size: 20px; }
