:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --border: #e3e4e8;
  --border-strong: #c9cbd2;
  --text: #16181d;
  --text-2: #52514e;
  --muted: #898781;
  --primary: #2a78d6;
  --primary-600: #1c5cab;
  --primary-50: #eaf2fc;
  --good: #0ca30c;
  --good-ink: #006300;
  --good-bg: #e7f6e7;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --warn-bg: #fff4dc;
  --bad: #d03b3b;
  --bad-ink: #a42727;
  --bad-bg: #fcebeb;
  --na-bg: #eeeef0;
  --na-ink: #52514e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand-logo {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #4a3aa7); color: #fff; font-size: 15px;
}
.nav { display: flex; gap: 4px; margin-left: 16px; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--primary-50); color: var(--primary-600); }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-50); color: var(--primary-600);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.role-tag { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--na-bg); color: var(--text-2); }

main { padding: 24px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .grow { flex: 1; min-width: 240px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:focus-visible, .cell:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--bad-ink); border-color: #efc4c4; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.success { background: var(--good-ink); border-color: var(--good-ink); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--na-bg); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.icon { width: 30px; padding: 0; height: 30px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; color: var(--text-2); }
input[type=text], input[type=password], input[type=date], input[type=month], input[type=search], select, textarea {
  height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface); font: inherit; color: var(--text); width: 100%;
}
textarea { height: auto; min-height: 110px; padding: 10px 12px; resize: vertical; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); cursor: pointer; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.card-head .grow { flex: 1; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- dashboard forms list ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.seg { display: inline-flex; background: var(--na-bg); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font: inherit; font-weight: 550; color: var(--text-2); cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.month-row + .month-row { margin-top: 26px; }
.month-head { font-size: 16px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.month-head .count { font-size: 12px; font-weight: 500; color: var(--text-2); }
.forms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.form-card { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; cursor: pointer; transition: box-shadow .15s, transform .15s; color: inherit; }
.form-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.form-card .top { display: flex; gap: 12px; align-items: flex-start; }
.form-card .title { font-weight: 650; font-size: 15.5px; }
.form-card .period { color: var(--text-2); font-size: 13px; margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.form-card .meta { display: flex; gap: 18px; color: var(--text-2); font-size: 12.5px; }
.form-card .meta b { color: var(--text); font-size: 15px; display: block; }
.ring { --p: 0; width: 58px; height: 58px; border-radius: 50%; flex: none; margin-left: auto;
  background: conic-gradient(var(--ring-color, var(--primary)) calc(var(--p) * 1%), var(--na-bg) 0);
  display: grid; place-items: center; }
.ring span { width: 46px; height: 46px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 700; font-size: 13px; }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.chip.open { background: var(--primary-50); color: var(--primary-600); }
.chip.closed { background: var(--na-bg); color: var(--text-2); }
.chip.good { background: var(--good-bg); color: var(--good-ink); }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip.bad { background: var(--bad-bg); color: var(--bad-ink); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.empty { text-align: center; padding: 56px 20px; color: var(--text-2); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- form workspace ---------- */
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.banner.closed { background: #fff8e6; border: 1px solid #f3d58a; color: #6b4a00; }
.banner .grow { flex: 1; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 16px; color: var(--text-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary-600); border-bottom-color: var(--primary); }
.tabs .count { font-size: 11px; background: var(--na-bg); padding: 1px 7px; border-radius: 99px; margin-left: 4px; color: var(--text-2); }

.workspace { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; align-items: start; }
.sidebar { position: sticky; top: 72px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; }
.sidebar .search { padding: 12px; border-bottom: 1px solid var(--border); }
.section-list { overflow-y: auto; padding: 6px; }
.section-item { display: flex; flex-direction: column; gap: 6px; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--text); }
.section-item:hover { background: var(--surface-2); }
.section-item.active { background: var(--primary-50); }
.section-item .name { font-weight: 550; font-size: 13px; display: flex; gap: 8px; }
.section-item .name .n { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 18px; }
.progress { height: 4px; background: var(--na-bg); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.progress.done > i { background: var(--good); }

/* ---------- grid (data entry) ---------- */
.grid-wrap { overflow: auto; max-height: calc(100vh - 250px); border-top: 1px solid var(--border); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; background: var(--surface); }
table.grid thead th { position: sticky; top: 0; z-index: 3; background: var(--surface-2); font-weight: 600; }
table.grid .qcol { position: sticky; left: 0; z-index: 2; min-width: 340px; max-width: 420px; text-align: left; }
table.grid thead .qcol { z-index: 4; }
table.grid .qtext { padding: 8px 12px; display: flex; gap: 10px; align-items: flex-start; }
table.grid .qtext .no { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 22px; }
table.grid .qtext .t { flex: 1; }
table.grid tr.header-row td { background: #f2f4f8; }
table.grid tr.header-row .qtext { font-weight: 650; color: var(--text-2); }
table.grid tr:hover td { background: #fafbfd; }
table.grid tr:hover td.qcol { background: #f5f8fd; }
.row-tools { visibility: hidden; display: flex; gap: 4px; }
tr:hover .row-tools { visibility: visible; }
.pcol { min-width: 64px; width: 64px; }
.phead { padding: 6px 4px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.phead .idx { font-size: 10.5px; color: var(--muted); }
.phead .mr { font-weight: 650; font-size: 12px; max-width: 70px; overflow: hidden; text-overflow: ellipsis; }
.phead button { border: 0; background: transparent; color: var(--primary); font-size: 10.5px; cursor: pointer; padding: 1px 4px; border-radius: 4px; font-weight: 600; }
.phead button:hover { background: var(--primary-50); }

.cell {
  width: 100%; height: 36px; border: 0; background: transparent; cursor: pointer; font: inherit;
  font-weight: 700; font-size: 12px; display: grid; place-items: center; color: var(--muted);
}
.cell span { width: 40px; height: 26px; border-radius: 7px; display: grid; place-items: center; }
.cell[data-v=""] span { border: 1px dashed var(--border-strong); }
.cell[data-v="Y"] span { background: var(--good-bg); color: var(--good-ink); }
.cell[data-v="N"] span { background: var(--bad-bg); color: var(--bad-ink); }
.cell[data-v="NA"] span { background: var(--na-bg); color: var(--na-ink); }
.cell:hover span { box-shadow: inset 0 0 0 1.5px var(--primary); }
.cell:disabled { cursor: default; }
.cell:disabled:hover span { box-shadow: none; }

.legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend .sw { display: inline-grid; place-items: center; width: 30px; height: 20px; border-radius: 6px; font-weight: 700; font-size: 11px; margin-right: 4px; }
.kbd { font-family: ui-monospace, Consolas, monospace; font-size: 11px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--surface); }
.save-state { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.save-state.saving { color: var(--primary-600); }
.save-state.error { color: var(--bad-ink); }

/* ---------- tables ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; width: 64px; }
table.data tr.header-row td { font-weight: 650; color: var(--text-2); background: #f6f7f9; }
table.data input[type=text] { height: 32px; }

/* ---------- results ---------- */
.results-section { margin-bottom: 18px; break-inside: avoid; }
.results-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.results-body .chart-box { padding: 16px 18px; border-left: 1px solid var(--border); position: relative; min-height: 280px; }
.chart-box canvas { width: 100% !important; }
.pct-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar-mini { width: 54px; height: 6px; background: var(--na-bg); border-radius: 99px; overflow: hidden; }
.bar-mini > i { display: block; height: 100%; background: var(--primary); }

/* ---------- structure ---------- */
.q-row { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.q-row .no { color: var(--muted); min-width: 26px; font-variant-numeric: tabular-nums; }
.q-row .t { flex: 1; }
.q-row.header .t { font-weight: 650; color: var(--text-2); }
.q-row .tools { display: flex; gap: 2px; opacity: 0; }
.q-row:hover .tools, .q-row:focus-within .tools { opacity: 1; }
.q-row input[type=text] { height: 32px; }

/* ---------- daily archive (Arabic, RTL) ---------- */
.rtl, [dir=rtl] .m-head, [dir=rtl] .m-body { font-family: "Noto Kufi Arabic", "Inter", "Segoe UI", Tahoma, sans-serif; }
.nav a[lang=ar] { font-family: "Noto Kufi Arabic", "Inter", sans-serif; font-size: 13px; }
.rtl table.data th { text-align: right; }
.rtl table.data .num { text-align: left; }
.rtl .card-head .grow { flex: 1; }
.link-row { cursor: pointer; }
.link-row:hover td { background: var(--surface-2); }
.archive-table .chk { width: 110px; text-align: center; }
.archive-table input[type=checkbox] { width: 20px; height: 20px; cursor: pointer; accent-color: var(--good-ink); }

/* ---------- file location labels ---------- */
.loc-table select { height: 32px; min-width: 64px; padding: 0 8px; }
.loc-table input[type=month] { height: 32px; min-width: 150px; }
.loc-table .loc-code code { font-family: ui-monospace, Consolas, monospace; font-weight: 700; font-size: 13px; white-space: nowrap; }
.label-sheet { display: none; }
.loc-label { border: 2px solid #000; border-radius: 6px; padding: 10px 14px; break-inside: avoid; color: #000; font-family: Arial, sans-serif; }
.loc-label .code { font-size: 26px; font-weight: 700; text-align: center; padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1.5px solid #000; white-space: nowrap; }
.loc-label table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.loc-label th, .loc-label td { text-align: center; border: 1px solid #000; padding: 4px 6px; }
.loc-label th { font-size: 14px; font-weight: 700; }
.loc-label td { font-size: 22px; font-weight: 700; }
.loc-label.stacked table { table-layout: auto; }
.loc-label.stacked th, .loc-label.stacked td { border: 0; font-size: 20px; padding: 2px 6px; }
.loc-label.stacked th { text-align: right; width: 45%; }
.loc-label.stacked td { text-align: left; }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 18, 25, .45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(520px, 100%); max-height: 90vh; overflow: auto; animation: pop .15s; }
.modal .m-head { padding: 18px 22px 0; }
.modal .m-head p { margin: 6px 0 0; color: var(--text-2); }
.modal .m-body { padding: 18px 22px; }
.modal .m-foot { padding: 14px 22px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1e2129; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; animation: pop .15s; max-width: 380px; }
.toast.error { background: var(--bad-ink); }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: linear-gradient(150deg, #1c5cab 0%, #2a78d6 45%, #4a3aa7 100%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-art h1 { font-size: 34px; line-height: 1.2; max-width: 460px; }
.login-art p { opacity: .85; max-width: 440px; font-size: 15px; }
.login-art .feat { display: grid; gap: 12px; margin-top: 28px; }
.login-art .feat div { display: flex; gap: 10px; align-items: center; opacity: .95; }
.login-box { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(380px, 100%); }
.login-card h2 { font-size: 24px; margin-bottom: 6px; }
.error-text { color: var(--bad-ink); font-size: 13px; min-height: 18px; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: 260px; }
  .results-body { grid-template-columns: 1fr; }
  .results-body .chart-box { border-left: 0; border-top: 1px solid var(--border); }
  .login-page { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .nav { display: none; }
  main { padding: 16px; }
  .form-grid.two { grid-template-columns: 1fr; }
}

@media print {
  .topbar, .tabs, .no-print, .banner, .toolbar { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; }
  .results-body { grid-template-columns: 1fr 1fr; }
  body.print-labels main > :not(.label-sheet), body.print-labels .toasts { display: none !important; }
  body.print-labels .label-sheet { display: grid; grid-template-columns: 1fr; gap: 6mm; }
  body.print-labels .label-sheet.single { grid-template-columns: repeat(3, 1fr); }
}
