/* Didgah — calm paper-and-ink interface, RTL first */
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --paper: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1b2337;
  --ink-2: #46506a;
  --ink-3: #6f7891;
  --line: #e2ded5;
  --line-2: #cfc9bd;
  --brand: #2f5ba8;
  --brand-ink: #ffffff;
  --brand-soft: #e4ebf7;
  --accent: #e7a83e;
  --ok: #2e7d4f;   --ok-soft: #e4f2ea;
  --warn: #9a6400; --warn-soft: #fbf0d9;
  --bad: #b03a2e;  --bad-soft: #f8e4e1;
  --info: #2d5f8b; --info-soft: #e3edf6;
  --muted-soft: #eeece6;
  --focus: #c77700;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31,42,44,.06), 0 2px 8px rgba(31,42,44,.05);
  --sidebar: 236px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 15px; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: "Vazirmatn", Tahoma, sans-serif; line-height: 1.75;
  font-feature-settings: "ss01";
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.4; margin: 0 0 .6rem; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.12rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 500; }
p { margin: 0 0 .7rem; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; font-feature-settings: "locl" 0; }
input[dir="ltr"] { font-feature-settings: "locl" 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: .87rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; right: -999px; top: 0; background: var(--ink); color: #fff; padding: .5rem 1rem; z-index: 100; }
.skip:focus { right: 0; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: #1b2c55; color: #dfe6e6; padding: 1.1rem .8rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: .2rem .5rem 1.2rem; color: #fff; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; flex: none; }
.brand-mark.lg { width: 56px; height: 56px; border-radius: 14px; }
.brand-name { font-weight: 700; font-size: 1.1rem; line-height: 1.2; }
.brand-org { font-size: .78rem; color: #9fb0b1; display: block; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav a {
  display: flex; align-items: center; gap: .65rem; padding: .55rem .7rem; border-radius: 8px; color: #dfe6e6; margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.12); color: #fff; font-weight: 500; box-shadow: inset -3px 0 0 var(--accent); }
.nav .ico { width: 1.3rem; text-align: center; opacity: .9; }
.nav .count { margin-inline-start: auto; background: var(--accent); color: #1f1f1f; border-radius: 99px; font-size: .75rem; padding: 0 .5rem; font-weight: 700; }
.nav-sep { border-top: 1px solid rgba(255,255,255,.1); margin: .8rem .4rem; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .8rem; padding: .7rem 1.6rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .grow { flex: 1; }
.menu-btn { display: none; }
.content { padding: 1.4rem 1.6rem 3rem; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-head p { color: var(--ink-2); margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.user-chip { display: flex; align-items: center; gap: .5rem; color: var(--ink); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: inline-grid; place-items: center;
  font-weight: 700; font-size: .85rem; object-fit: cover; flex: none;
}
.avatar.lg { width: 72px; height: 72px; font-size: 1.6rem; }
.bell { position: relative; padding: .3rem .5rem; border-radius: 8px; color: var(--ink-2); }
.bell .dot { position: absolute; top: -2px; left: -4px; background: var(--bad); color: #fff; font-size: .7rem; border-radius: 99px; padding: 0 .38rem; font-weight: 700; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > header:first-child { margin-top: 0; }
.card header { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .7rem; }
.card header h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
.stat { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; color: var(--ink); box-shadow: var(--shadow); }
a.stat:hover { border-color: var(--brand); text-decoration: none; }
.stat .v { font-size: 1.65rem; font-weight: 700; line-height: 1.2; display: block; }
.stat .l { color: var(--ink-2); font-size: .88rem; }
.stat.warn .v { color: var(--warn); } .stat.bad .v { color: var(--bad); } .stat.ok .v { color: var(--ok); }

/* ---------- tables & lists ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: right; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-2); font-weight: 500; font-size: .85rem; background: var(--surface-2); white-space: nowrap; }
tr:hover td { background: #fcfbf8; }
td.n, th.n { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: .55rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .6rem; align-items: flex-start; justify-content: space-between; }
.list > li:last-child { border-bottom: 0; }
.list .meta { color: var(--ink-3); font-size: .85rem; }

/* ---------- badges (always text + symbol, never colour alone) ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .05rem .55rem; border-radius: 99px; font-size: .8rem; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.badge .sym { font-size: .85em; }
.st-todo, .st-draft { background: var(--muted-soft); color: var(--ink-2); border-color: var(--line-2); }
.st-in_progress, .st-submitted { background: var(--info-soft); color: var(--info); }
.st-blocked, .st-returned { background: var(--bad-soft); color: var(--bad); }
.st-awaiting_approval { background: var(--warn-soft); color: var(--warn); }
.st-completed, .st-approved { background: var(--ok-soft); color: var(--ok); }
.st-canceled, .st-superseded { background: #f0f0f0; color: #777; text-decoration: line-through; }
.pr-urgent { background: var(--bad); color: #fff; } .pr-high { background: var(--warn-soft); color: var(--warn); }
.pr-normal { background: transparent; color: var(--ink-3); border-color: var(--line); } .pr-low { background: transparent; color: var(--ink-3); border-color: var(--line); }
.tag { display: inline-block; background: var(--brand-soft); color: var(--brand); border-radius: 6px; padding: 0 .45rem; font-size: .78rem; margin-inline-end: .25rem; }
.overdue { color: var(--bad); font-weight: 500; }
.overdue::before { content: "⚠ "; }

/* ---------- progress ---------- */
.prog { display: flex; align-items: center; gap: .5rem; min-width: 120px; }
.prog progress { flex: 1; height: 8px; appearance: none; border: 0; border-radius: 99px; background: var(--muted-soft); overflow: hidden; }
.prog progress::-webkit-progress-bar { background: var(--muted-soft); border-radius: 99px; }
.prog progress::-webkit-progress-value { background: var(--brand); border-radius: 99px; }
.prog progress::-moz-progress-bar { background: var(--brand); border-radius: 99px; }
.prog span { font-size: .82rem; color: var(--ink-2); min-width: 2.8rem; }
.bar { height: 10px; background: var(--brand); border-radius: 99px; min-width: 2px; width: 0; transition: width .3s; }
.bar.alt { background: var(--accent); }
.bar-row { display: grid; grid-template-columns: minmax(110px, 180px) 1fr auto; gap: .6rem; align-items: center; padding: .3rem 0; font-size: .9rem; }
.bar-track { background: var(--muted-soft); border-radius: 99px; }

/* ---------- forms ---------- */
form.stack > * + * { margin-top: .9rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field label, .field .label { font-weight: 500; font-size: .9rem; }
.field .hint { color: var(--ink-3); font-size: .82rem; }
.req::after { content: " *"; color: var(--bad); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: .48rem .65rem; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: 2px solid var(--brand-soft); }
input[type=checkbox], input[type=radio] { width: 1.05rem; height: 1.05rem; accent-color: var(--brand); vertical-align: middle; }
.check { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; margin: 0; }
legend { padding: 0 .4rem; font-weight: 500; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin-bottom: 1rem; }
.filters .field { min-width: 140px; flex: 1; }
.filters .field.wide { flex: 2; min-width: 200px; }
.date-wrap { position: relative; display: flex; }
.date-wrap input { padding-left: 2.3rem; direction: ltr; text-align: right; }
.date-wrap .cal-btn { position: absolute; left: 4px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; cursor: pointer; padding: .2rem .4rem; border-radius: 6px; color: var(--ink-2); }
.date-wrap .cal-btn:hover { background: var(--muted-soft); }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; font: inherit; font-weight: 500; font-size: .92rem; padding: .45rem .95rem; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; border-color: var(--ink-3); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #244a8c; }
.btn.danger { background: var(--surface); color: var(--bad); border-color: #e3b5ae; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: .2rem .6rem; font-size: .84rem; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 0; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.inline { display: inline; }

/* ---------- messages ---------- */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: .8rem; border: 1px solid; display: flex; gap: .6rem; align-items: flex-start; }
.flash::before { font-weight: 700; }
.flash.success { background: var(--ok-soft); border-color: #b9dcc7; color: #1d5737; } .flash.success::before { content: "✔"; }
.flash.error { background: var(--bad-soft); border-color: #ecc0b9; color: #8a2a20; } .flash.error::before { content: "✖"; }
.flash.warning { background: var(--warn-soft); border-color: #ecd7a6; color: #6d4700; } .flash.warning::before { content: "⚠"; }
.flash.info { background: var(--info-soft); border-color: #bcd3e8; color: #1f4466; } .flash.info::before { content: "ℹ"; }
.errors { background: var(--bad-soft); border: 1px solid #ecc0b9; color: #8a2a20; border-radius: var(--radius); padding: .6rem 1rem; margin-bottom: 1rem; }
.errors ul { margin: .2rem 0 0; padding-inline-start: 1.2rem; }
.empty { text-align: center; padding: 1.6rem 1rem; color: var(--ink-3); }
.empty .big { font-size: 1.8rem; display: block; margin-bottom: .2rem; opacity: .6; }
.note { background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: var(--radius); padding: .7rem 1rem; color: var(--ink-2); font-size: .9rem; }
.callout { border-inline-start: 4px solid var(--warn); background: var(--warn-soft); padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.callout.bad { border-color: var(--bad); background: var(--bad-soft); }
.callout.ok { border-color: var(--ok); background: var(--ok-soft); }
.callout.info { border-color: var(--info); background: var(--info-soft); }

/* ---------- tabs & pagination ---------- */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--brand); border-color: var(--brand); font-weight: 500; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.pager { display: flex; gap: .3rem; justify-content: center; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.pager a, .pager span { padding: .2rem .65rem; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); }
.pager [aria-current] { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- task detail ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; font-size: .93rem; margin: 0; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; }
.checklist li { align-items: center; }
.checklist .done span { text-decoration: line-through; color: var(--ink-3); }
.timeline { list-style: none; margin: 0; padding: 0; border-inline-start: 2px solid var(--line); }
.timeline li { padding: .25rem 1rem .5rem 0; position: relative; font-size: .88rem; margin-inline-start: .5rem; }
.timeline li::before { content: ""; position: absolute; right: -.5rem; top: .75rem; width: .6rem; height: .6rem; border-radius: 50%; background: var(--line-2); margin-right: -.3rem; }
.comment { display: flex; gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.comment .body { flex: 1; }
.comment .who { font-weight: 500; }
.status-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
details.reason { margin-top: .5rem; }
details summary { cursor: pointer; color: var(--brand); }

/* ---------- kanban ---------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(185px, 1fr)); gap: .8rem; overflow-x: auto; padding-bottom: .5rem; align-items: start; }
.col { background: #ece9e1; border-radius: var(--radius); padding: .6rem; min-height: 300px; border: 2px dashed transparent; transition: border-color .15s, background .15s; }
.col header { display: flex; justify-content: space-between; align-items: center; padding: .1rem .3rem .5rem; font-weight: 700; font-size: .92rem; }
.col.can-drop { border-color: var(--brand); background: #e3e9f4; }
.col.no-drop { opacity: .55; }
.col.over { background: #d3def0; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .6rem .7rem; margin-bottom: .55rem; box-shadow: var(--shadow); cursor: grab; }
.kcard[draggable="false"] { cursor: default; }
.kcard.dragging { opacity: .5; }
.kcard h3 { font-size: .93rem; margin: 0 0 .3rem; font-weight: 500; }
.kcard .meta { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; font-size: .8rem; color: var(--ink-3); }
.kcard form { margin-top: .4rem; display: flex; gap: .3rem; }
.kcard form select { font-size: .8rem; padding: .15rem .3rem; }

/* ---------- reports ---------- */
.entry-row td { font-size: .9rem; }
.entry-edit { background: var(--surface-2); }
.report-text { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; min-height: 2rem; }
.rev-box { border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: .6rem; }
.review-box { border: 2px solid var(--brand); }

/* ---------- datepicker ---------- */
.jdp { position: absolute; z-index: 60; top: calc(100% + 4px); inset-inline-start: 0; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.14); padding: .6rem; width: 270px; direction: rtl; }
.jdp header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; font-weight: 700; }
.jdp header button { border: 0; background: var(--muted-soft); border-radius: 6px; cursor: pointer; padding: .1rem .55rem; font: inherit; }
.jdp table { font-size: .85rem; }
.jdp th, .jdp td { text-align: center; padding: 0; border: 0; background: none; }
.jdp td button { width: 100%; aspect-ratio: 1; border: 0; background: none; border-radius: 6px; cursor: pointer; font: inherit; }
.jdp td button:hover, .jdp td button:focus { background: var(--brand-soft); }
.jdp td button.today { outline: 1px solid var(--brand); }
.jdp td button.sel { background: var(--brand); color: #fff; }
.jdp td button.off { color: var(--bad); }
.jdp footer { display: flex; justify-content: space-between; margin-top: .4rem; }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: 12px; padding: 1.2rem 1.3rem; max-width: 440px; width: 92vw; box-shadow: 0 10px 40px rgba(0,0,0,.25); color: var(--ink); font-family: inherit; }
dialog::backdrop { background: rgba(31,42,44,.45); }
dialog .actions { justify-content: flex-start; margin-top: 1rem; }

/* ---------- auth pages ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background:
  radial-gradient(circle at 15% 20%, #e1e8f5 0, transparent 45%), radial-gradient(circle at 85% 80%, #efe6d6 0, transparent 40%), var(--paper); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem 1.8rem; box-shadow: 0 8px 30px rgba(31,42,44,.08); }
.auth-card .brand { color: var(--ink); justify-content: center; padding-bottom: 1.4rem; }
.auth-card .brand-org { color: var(--ink-3); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 260px; transform: translateX(100%); transition: transform .2s; z-index: 50; }
  .sidebar.open { transform: none; box-shadow: -10px 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(5, 82vw); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .user-chip .name { display: none; }
  .hide-sm { display: none; }
}
@media print {
  .sidebar, .topbar, .actions, .filters, form { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; break-inside: avoid; }
}
.grow { flex: 1; }
.file-pick { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.file-pick input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-pick .file-name { color: var(--ink-3); font-size: .87rem; overflow-wrap: anywhere; }
.file-pick input[type=file]:focus-visible + .btn { outline: 3px solid var(--focus); outline-offset: 2px; }

@media (max-width: 600px) { .jdp { position: fixed; inset: auto auto 16px 50%; transform: translateX(-50%); width: min(300px, 92vw); } }
.auth-card.wide { max-width: 620px; }
.steps { list-style: none; display: flex; gap: .4rem; padding: 0; margin: .4rem 0 1rem; flex-wrap: wrap; }
.steps li { padding: .2rem .8rem; border-radius: 99px; background: var(--muted-soft); color: var(--ink-3); font-size: .85rem; }
.steps li.on { background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.big-url { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
body > .content { margin: 0 auto; }

/* health checks on the status page */
.checks { list-style: none; padding: 0; margin: .5rem 0; }
.checks li { padding: .25rem 0; }
.checks .check-ok { color: var(--ok, #1d7a46); }
.checks .check-warn { color: #9a6200; }
.checks .check-fail { color: var(--danger, #b3261e); font-weight: 600; }
