:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ed;
  --text: #1c2630;
  --muted: #66727f;
  --accent: #0f766e;
  --accent-hover: #0d645d;
  --accent-soft: #e6f4f2;
  --danger: #c2410c;
  --danger-soft: #fdeee6;
  --warn: #a16207;
  --warn-soft: #fdf6dd;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --info: #1d4ed8;
  --info-soft: #e9effd;
  --sidebar: #12302d;
  --sidebar-text: #c9dbd8;
  --shadow: 0 1px 2px rgba(16, 24, 32, .05), 0 1px 6px rgba(16, 24, 32, .04);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171c; --surface: #1a2027; --surface-2: #20272f; --border: #2c353f; --text: #e4e9ee; --muted: #93a0ad;
    --accent: #2dd4bf; --accent-hover: #5eead4; --accent-soft: #163a37; --danger: #fb923c; --danger-soft: #3a2418;
    --warn: #facc15; --warn-soft: #362f14; --ok: #4ade80; --ok-soft: #173322; --info: #93b4ff; --info-soft: #1c2742;
    --sidebar: #0d1513; --sidebar-text: #a9bdb9; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12171c; --surface: #1a2027; --surface-2: #20272f; --border: #2c353f; --text: #e4e9ee; --muted: #93a0ad;
  --accent: #2dd4bf; --accent-hover: #5eead4; --accent-soft: #163a37; --danger: #fb923c; --danger-soft: #3a2418;
  --warn: #facc15; --warn-soft: #362f14; --ok: #4ade80; --ok-soft: #173322; --info: #93b4ff; --info-soft: #1c2742;
  --sidebar: #0d1513; --sidebar-text: #a9bdb9; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Vazirmatn, Tahoma, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.6; background: var(--bg); color: var(--text);
  font-feature-settings: "ss01";
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700; font-size: 15px; }
.brand svg { flex: none; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--sidebar-text); opacity: .8; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: var(--sidebar-text); padding: 8px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(45, 212, 191, .16); color: #fff; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .sep { height: 1px; background: rgba(255,255,255,.08); margin: 10px 8px; }
.nav .badge { margin-inline-start: auto; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; font-size: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .who { color: #fff; font-weight: 500; }
.sidebar-foot button { background: none; border: 0; color: var(--sidebar-text); padding: 0; cursor: pointer; font: inherit; text-decoration: underline; margin-inline-end: 10px; }

.main { min-width: 0; padding: 22px 28px 40px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-h .spacer { flex: 1; }
.card-b { padding: 16px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.danger { background: var(--danger); } .dot.warn { background: var(--warn); } .dot.info { background: var(--info); }

.btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; min-height: 34px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #06201d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #06201d; } }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 2px 10px; min-height: 28px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.nav .badge { background: var(--danger); color: #fff; border: 0; }

/* forms */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; min-height: 34px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); vertical-align: middle; }
input.ltr-in, input[type="time"], input.jdate { direction: ltr; text-align: right; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.field > span .req { color: var(--danger); }
.field .help { font-size: 11px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.weekdays { display: flex; gap: 6px; flex-wrap: wrap; }
.weekdays label { border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: 13px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 140px; }
.filters .field.grow { flex: 1; min-width: 200px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th { font-weight: 500; color: var(--muted); font-size: 12px; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: left; width: 1%; }
td.actions .btn-group { flex-wrap: nowrap; justify-content: flex-end; }
td.wrap { white-space: normal; min-width: 180px; }
tr.row-off td { color: var(--muted); }
tr.row-holiday td, tr.row-off td { background: var(--surface-2); }
tfoot td { font-weight: 700; background: var(--surface-2); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--border); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; }
.tabs a.active { color: var(--accent); border-color: var(--accent); font-weight: 500; }

/* charts */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .bar { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .bar.soft { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.bars .lbl { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars .val { font-size: 11px; color: var(--text); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: middle; }
.stack { display: flex; flex-direction: column-reverse; width: 100%; max-width: 34px; border-radius: 4px 4px 0 0; overflow: hidden; }
.stack span { display: block; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li .spacer { flex: 1; }

/* device cards */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.device .meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.device .meta dt { color: var(--muted); }
.device .meta dd { margin: 0; }
.code { font-family: Consolas, "SFMono-Regular", monospace; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; direction: ltr; display: inline-block; }
.callout { border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius); padding: 12px 16px; font-size: 13px; }
.callout.warn { background: var(--warn-soft); border-color: transparent; }
.callout ol { margin: 6px 0 0; padding-inline-start: 20px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 16, 22, .45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 12px; width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.25); border: 1px solid var(--border); }
.modal.wide { width: min(900px, 100%); }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-h .spacer { flex: 1; }
.modal-b { padding: 18px; overflow-y: auto; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-start; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px; }
@keyframes fade { from { opacity: 0; } }

/* toast */
#toast-root { position: fixed; bottom: 20px; left: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 380px; animation: fade .15s; }
.toast.error { background: var(--danger); color: #fff; }

/* jalali datepicker */
.jdp { position: absolute; z-index: 70; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 10px; width: 260px; user-select: none; }
.jdp-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 500; }
.jdp-h button { border: 0; background: none; cursor: pointer; color: var(--text); font-size: 16px; width: 28px; height: 28px; border-radius: 6px; }
.jdp-h button:hover { background: var(--surface-2); }
.jdp-g { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font-size: 12px; }
.jdp-g .wd { color: var(--muted); padding: 4px 0; }
.jdp-g button { border: 0; background: none; padding: 6px 0; border-radius: 6px; cursor: pointer; color: var(--text); font: inherit; }
.jdp-g button:hover { background: var(--accent-soft); }
.jdp-g button.today { outline: 1px solid var(--accent); }
.jdp-g button.sel { background: var(--accent); color: #fff; }
.jdp-g button.fri { color: var(--danger); }
.jdp-f { display: flex; justify-content: space-between; margin-top: 6px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at top, var(--accent-soft), var(--bg) 60%); }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.login form { display: flex; flex-direction: column; gap: 14px; }

.emp-head { display: flex; gap: 24px; flex-wrap: wrap; font-size: 13px; }
.emp-head b { font-weight: 500; }
.sum-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.sum-grid div { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.sum-grid span { display: block; font-size: 11px; color: var(--muted); }
.sum-grid b { font-size: 16px; }

/* responsive */
@media (max-width: 1100px) { .g-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 250px; z-index: 40; transform: translateX(100%); transition: transform .2s; }
  .layout.nav-open .sidebar { transform: none; box-shadow: -10px 0 30px rgba(0,0,0,.3); }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 14px 16px 30px; }
  .g-2, .g-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* print (reports) */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; font-size: 11px; }
  .sidebar, .topbar .btn, .filters, .tabs, .no-print, #toast-root { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  .card { border: 0; box-shadow: none; }
  th { background: #eee !important; }
  th, td { padding: 4px 6px; }
  .print-only { display: block; }
}
