/* Partak Office — one stylesheet, RTL, light/dark via prefers-color-scheme.
   Layout: right-hand sidebar (the org chart) + working desk; a department = agent chat beside its records.
   Brand: red #C8202A + charcoal #3D3E40 from the Partak logo. Font: Vazirmatn (served locally, OFL). */

@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: 600 700; font-display: swap; }
@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-ExtraBold.woff2") format("woff2"); font-weight: 800; font-display: swap; }

:root {
  --bg: #F5F4F2; --surface: #FFFFFF; --surface-2: #EEEDEA; --ink: #232325; --ink-2: #626367; --line: #E1DFDB;
  --brand: #C8202A; --brand-ink: #FFFFFF; --brand-soft: #FBE8E9;
  --char: #3D3E40; --char-ink: #FFFFFF;
  --ok: #2C7A4B; --ok-soft: #E2F1E7; --warn: #A96300; --warn-soft: #FBEFD9; --info: #2C5D88; --info-soft: #E3EDF6;
  --plate: transparent; --shadow: 0 1px 2px rgba(35,35,37,.06), 0 4px 16px rgba(35,35,37,.05);
  --f: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  --r: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141415; --surface: #1D1D1F; --surface-2: #27272A; --ink: #ECECEE; --ink-2: #A2A3A8; --line: #323236;
    --brand: #E5484D; --brand-ink: #FFFFFF; --brand-soft: #3A1C1E; --char: #E6E6E8; --char-ink: #161617;
    --ok: #5CC08A; --ok-soft: #173022; --warn: #E3A34A; --warn-soft: #382912; --info: #7FB0DE; --info-soft: #172636;
    --plate: #EDEDED; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { direction: rtl; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f); font-size: 15px; line-height: 1.75; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.4; text-wrap: balance; }
p { margin: 0; }
code { background: var(--surface-2); border-radius: 5px; padding: 0 5px; direction: ltr; unicode-bidi: isolate; font-size: 13px; }
img { max-width: 100%; }

.app { display: grid; grid-template-columns: 268px minmax(0, 1fr); min-height: 100vh; }

/* sidebar */
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-inline-end: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; flex-direction: column; gap: 6px; padding-inline: 6px; text-decoration: none; }
.brand img { width: 170px; height: auto; background: var(--plate); border-radius: 8px; padding: 4px 6px; }
.brand span { font-size: 12px; color: var(--ink-2); }
.navgroup { display: flex; flex-direction: column; gap: 2px; }
.navlabel { font-size: 11.5px; color: var(--ink-2); padding: 0 10px 4px; font-weight: 600; }
.nav { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; border-radius: 10px; padding: 8px 10px;
  cursor: pointer; text-align: start; font-weight: 500; color: var(--ink); text-decoration: none; }
.nav svg { width: 19px; height: 19px; flex: none; color: var(--ink-2); }
.nav .cnt { margin-inline-start: auto; font-size: 12px; background: var(--surface-2); border-radius: 20px; padding: 0 8px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.nav:hover { background: var(--surface-2); }
.nav[aria-current="page"] { background: var(--char); color: var(--char-ink); }
.nav[aria-current="page"] svg { color: var(--char-ink); }
.nav[aria-current="page"] .cnt { background: var(--brand); color: var(--brand-ink); }
.me { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.me strong { font-size: 14px; }
.me form { margin: 0; }

/* main */
main.desk { min-width: 0; padding: 28px max(16px, env(safe-area-inset-right, 0px)) 60px max(16px, env(safe-area-inset-left, 0px)); }
.wrap { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.page-h { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; justify-content: space-between; }
.page-h h1 { font-size: 28px; font-weight: 800; }
.eyebrow { font-size: 13px; color: var(--brand); font-weight: 700; }
.lead { color: var(--ink-2); max-width: 68ch; }
.agentline { display: flex; gap: 12px; align-items: center; }
.ava { width: 46px; height: 46px; border-radius: 14px; background: var(--char); color: var(--char-ink); display: grid; place-items: center; flex: none; }
.ava svg { width: 24px; height: 24px; }
.ava.red { background: var(--brand); color: var(--brand-ink); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel-h { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; }
.panel-h h3 { font-size: 16px; font-weight: 700; }
.sub { font-size: 13px; color: var(--ink-2); }
.grid2 { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 18px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* kpis & units */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.kpi b { display: block; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.3; }
.kpi span { font-size: 13px; color: var(--ink-2); }
.kpi.alert b { color: var(--brand); }
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.unit { display: flex; gap: 12px; align-items: flex-start; text-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; text-decoration: none; }
.unit:hover { border-color: var(--char); }
.unit .ava { width: 38px; height: 38px; border-radius: 11px; }
.unit .ava svg { width: 20px; height: 20px; }
.unit strong { display: block; font-size: 14.5px; }
.unit small { display: block; color: var(--ink-2); font-size: 12.5px; line-height: 1.6; }
.unit .st { color: var(--ink); font-weight: 600; }

/* buttons, inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 6px 12px;
  cursor: pointer; font-size: 13.5px; font-weight: 600; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn svg { width: 16px; height: 16px; }
.btn:hover { border-color: var(--ink-2); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.dark { background: var(--char); border-color: var(--char); color: var(--char-ink); }
.btn.ghost { border-color: transparent; background: none; color: var(--ink-2); padding: 4px 8px; }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn.danger { color: var(--brand); }
.btn[disabled] { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
input[type=text], input[type=date], input[type=number], input[type=tel], input[type=password], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 7px 10px; font-size: 14px; }
textarea { resize: vertical; line-height: 1.8; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-2); margin: 0; }
.form .full, .form h3 { grid-column: 1 / -1; }
.form h3 { font-size: 15px; }
.form .act { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 20px; padding: 4px 12px; font-size: 13px; cursor: pointer; text-decoration: none; color: var(--ink); }
.chip:hover { border-color: var(--ink-2); }
.chip[aria-pressed="true"], .chip.on { background: var(--char); color: var(--char-ink); border-color: var(--char); }
.chip.q { background: var(--surface-2); border-color: transparent; }
.chip.q:hover { background: var(--brand-soft); color: var(--brand); }
.pill { display: inline-block; font-size: 12px; border-radius: 20px; padding: 0 9px; line-height: 22px; background: var(--surface-2); color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.pill.red { background: var(--brand-soft); color: var(--brand); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }

/* records */
.list { display: flex; flex-direction: column; gap: 10px; }
.rec { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.rec.over { border-color: var(--brand); }
.rec-top { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.rec-top strong { font-size: 15px; }
.rec .meta { font-size: 13px; color: var(--ink-2); }
.rec .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.rec .row input[type=date] { width: auto; }
.rec select { width: auto; padding: 3px 8px; font-size: 13px; }
.rec-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.rec-actions form { margin: 0; }
.sel { user-select: all; direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.empty { border: 1px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; color: var(--ink-2); font-size: 14px; }
.stagebar { display: flex; flex-wrap: wrap; gap: 6px; }
details summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }
.tbl-wrap { overflow-x: auto; }
table.q { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 620px; }
table.q th { background: var(--surface-2); font-weight: 700; text-align: start; padding: 6px 8px; font-size: 12.5px; color: var(--ink-2); }
table.q td { border-bottom: 1px solid var(--line); padding: 4px 6px; vertical-align: middle; }
table.q input { padding: 4px 6px; font-size: 13px; }
table.q td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.plain { width: 100%; border-collapse: collapse; font-size: 14px; }
table.plain th, table.plain td { border-bottom: 1px solid var(--line); padding: 8px; text-align: start; vertical-align: middle; }
table.plain th { color: var(--ink-2); font-size: 12.5px; }
.totals { display: grid; grid-template-columns: auto auto; gap: 2px 18px; justify-content: end; font-variant-numeric: tabular-nums; font-size: 14px; }
.totals b { font-weight: 800; }
.money { font-variant-numeric: tabular-nums; }

/* chat */
.chat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); display: flex; flex-direction: column; min-width: 0; box-shadow: var(--shadow); }
.chat-h { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-h .t { display: flex; flex-direction: column; line-height: 1.5; }
.chat-h .t strong { font-size: 15px; }
.chat-h .t small { font-size: 12px; color: var(--ink-2); }
.chat-h .tools { margin-inline-start: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.log { display: flex; flex-direction: column; gap: 12px; padding: 14px; min-height: 260px; max-height: 62vh; overflow-y: auto; }
.msg { max-width: 92%; border-radius: 12px; padding: 10px 13px; font-size: 14.5px; overflow-wrap: anywhere; }
.msg.u { align-self: flex-start; background: var(--char); color: var(--char-ink); white-space: pre-wrap; }
.msg.a { align-self: flex-end; background: var(--surface-2); width: 100%; max-width: 100%; }
.msg.a .mact { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); align-items: center; }
.msg .err { color: var(--brand); font-size: 13px; margin-top: 6px; }
.msg .did { color: var(--ok); font-size: 13px; margin-top: 6px; }
.thinking { color: var(--ink-2); font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .thinking i { animation: none; } }
.md h1, .md h2, .md h3, .md h4 { font-size: 15.5px; font-weight: 800; margin: 10px 0 4px; }
.md p { margin: 0 0 6px; }
.md ul, .md ol { margin: 0 0 6px; padding-inline-start: 22px; }
.md li { margin: 2px 0; }
.md pre { background: var(--surface); border-radius: 8px; padding: 8px 10px; direction: ltr; text-align: left; overflow-x: auto; white-space: pre-wrap; font-size: 13px; }
.md table { border-collapse: collapse; margin: 6px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.md td, .md th { border: 1px solid var(--line); padding: 4px 8px; }
.md th { background: var(--surface); }
.composer { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.composer .chips { max-height: 84px; overflow-y: auto; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 46px; max-height: 200px; }
.handoff { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--ink-2); }
.handoff svg { width: 16px; height: 16px; }
.handoff select { width: auto; padding: 3px 8px; font-size: 13px; }
.notice { border-radius: 10px; padding: 10px 12px; background: var(--warn-soft); color: var(--warn); font-size: 13.5px; }
.notice.info { background: var(--info-soft); color: var(--info); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.error { background: var(--brand-soft); color: var(--brand); }
.notice a { font-weight: 700; }

/* board */
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }
.col { background: var(--surface-2); border-radius: var(--r); padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.col h3 { font-size: 14px; font-weight: 700; padding: 2px 4px; display: flex; justify-content: space-between; }
.task { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 5px; }
.task .who { font-size: 12px; color: var(--ink-2); }
.task p { font-size: 13.5px; color: var(--ink-2); white-space: pre-wrap; }

/* roadmap */
.bar { height: 8px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 8px; }
.phase { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 14px; }
.phase .num { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; background: var(--surface-2); font-size: 17px; }
.phase.done .num { background: var(--ok); color: #fff; }
.phase.cur .num { background: var(--brand); color: var(--brand-ink); }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 5px 0; cursor: pointer; font-size: 14.5px; }
.check input { margin-top: 6px; accent-color: var(--brand); width: 17px; height: 17px; flex: none; }
.check.done span { color: var(--ink-2); text-decoration: line-through; }
.gptgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }

/* overlay + toast */
.ov { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.ov .box { background: var(--surface); border-radius: 14px; max-width: 720px; width: 100%; max-height: 86vh; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--char); color: var(--char-ink); padding: 9px 18px; border-radius: 12px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); }

/* auth / install */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-box { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 14px; }
.auth-box h1 { font-size: 22px; font-weight: 800; }
.auth-logo { width: 190px; background: var(--plate); border-radius: 8px; padding: 4px 6px; }
.auth-box .form { background: none; border: 0; padding: 0; }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.checks .ok { color: var(--ok); }
.checks .bad { color: var(--brand); font-weight: 700; }

@media (max-width: 1080px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; gap: 10px; border-inline-end: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .brand img { width: 130px; }
  .navwrap { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
  .navgroup { flex-direction: row; gap: 4px; }
  .navlabel, .nav .cnt, .me { display: none; }
  .nav { width: auto; white-space: nowrap; padding: 7px 11px; }
  .board { grid-template-columns: minmax(0, 1fr); }
  .page-h h1 { font-size: 23px; }
  main.desk { padding-top: 18px; }
}
