:root{
  --ink:#14283c; --ink-2:#3b4f63; --muted:#6b7c8d; --line:#d7dee5; --paper:#f3f6f8; --card:#ffffff;
  --brand:#1d4e6e; --brand-dark:#123550; --accent:#c2415d; --dentin:#b98a3e; --ok:#2f7d57; --warn:#b7791f; --bad:#b3261e;
  --radius:10px; --shadow:0 1px 2px rgba(20,40,60,.08);
  font-family:"Vazirmatn","Segoe UI",Tahoma,"Noto Sans Arabic",sans-serif;
}
*{box-sizing:border-box}
html{font-size:16px}
body{margin:0;background:var(--paper);color:var(--ink);line-height:1.7}
a{color:var(--brand)}
h1,h2,h3{line-height:1.35;margin:0 0 .6rem;color:var(--ink)}
h1{font-size:1.45rem} h2{font-size:1.15rem} h3{font-size:1rem}
.boot{padding:3rem;text-align:center;color:var(--muted)}
:focus-visible{outline:3px solid #7fb2d6;outline-offset:2px}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}

/* layout */
.topbar{background:var(--brand-dark);color:#fff;display:flex;align-items:center;gap:1rem;padding:.5rem 1rem;flex-wrap:wrap;position:sticky;top:0;z-index:20}
.brand{font-weight:700;font-size:1rem;color:#fff;text-decoration:none;white-space:nowrap}
.brand small{display:block;font-weight:400;font-size:.72rem;opacity:.75}
.nav{display:flex;gap:.25rem;flex-wrap:wrap;flex:1}
.nav a{color:#dbe7f0;text-decoration:none;padding:.35rem .7rem;border-radius:8px;font-size:.92rem}
.nav a.active,.nav a:hover{background:rgba(255,255,255,.14);color:#fff}
.userbox{display:flex;gap:.5rem;align-items:center;font-size:.88rem}
.userbox button{background:transparent;color:#dbe7f0;border:1px solid rgba(255,255,255,.35);border-radius:8px;padding:.2rem .6rem;cursor:pointer}
main{max-width:1280px;margin:0 auto;padding:1.2rem 1rem 4rem}
.pagehead{display:flex;align-items:center;justify-content:space-between;gap:1rem;flex-wrap:wrap;margin-bottom:1rem}
.card{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:1rem 1.1rem;margin-bottom:1rem;box-shadow:var(--shadow)}
.card>h2:first-child,.card>h3:first-child{margin-top:0}
.grid{display:grid;gap:1rem}
.grid.two{grid-template-columns:repeat(2,minmax(0,1fr))}
.grid.three{grid-template-columns:repeat(3,minmax(0,1fr))}
@media (max-width:800px){.grid.two,.grid.three{grid-template-columns:1fr}}
.row{display:flex;gap:.6rem;align-items:center;flex-wrap:wrap}
.spacer{flex:1}
.muted{color:var(--muted);font-size:.9rem}
.empty{padding:1.5rem;text-align:center;color:var(--muted);border:1px dashed var(--line);border-radius:var(--radius)}

/* forms */
.field{display:flex;flex-direction:column;gap:.25rem;margin-bottom:.8rem}
.field>label{font-size:.9rem;color:var(--ink-2);font-weight:600}
.field .help{font-size:.8rem;color:var(--muted)}
.field .err{font-size:.82rem;color:var(--bad)}
input,select,textarea{font:inherit;color:inherit;border:1px solid #b9c5d0;border-radius:8px;padding:.5rem .65rem;background:#fff;width:100%;min-width:0}
textarea{min-height:5rem;resize:vertical}
input[type=checkbox],input[type=radio]{width:auto}
input.invalid,select.invalid,textarea.invalid{border-color:var(--bad)}
.btn{font:inherit;border:1px solid var(--brand);background:var(--brand);color:#fff;border-radius:8px;padding:.5rem 1rem;cursor:pointer;display:inline-flex;gap:.4rem;align-items:center;justify-content:center;text-decoration:none}
.btn:hover{background:var(--brand-dark)}
.btn.secondary{background:#fff;color:var(--brand)} .btn.secondary:hover{background:#eaf1f6}
.btn.danger{background:var(--bad);border-color:var(--bad)} .btn.danger:hover{background:#8f1d17}
.btn.small{padding:.2rem .6rem;font-size:.85rem}
.btn[disabled]{opacity:.5;cursor:not-allowed}
.chips{display:flex;gap:.4rem;flex-wrap:wrap}
.chip{display:inline-flex;align-items:center;gap:.3rem;padding:.1rem .6rem;border-radius:999px;font-size:.8rem;background:#e6edf3;color:var(--ink-2);border:1px solid transparent}
.chip.ok{background:#e1f2e9;color:var(--ok)} .chip.warn{background:#fbf0d9;color:var(--warn)} .chip.bad{background:#fbe3e1;color:var(--bad)} .chip.info{background:#dcebf6;color:var(--brand)}
.alert{padding:.7rem 1rem;border-radius:8px;margin-bottom:1rem;border:1px solid}
.alert.err{background:#fdeceb;border-color:#f1b7b3;color:#7d1a14} .alert.ok{background:#e6f4ec;border-color:#b5dcc5;color:#1d5a3b} .alert.info{background:#e8f1f8;border-color:#bcd5e8;color:#1b4764}

/* tables */
.tablewrap{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:.92rem}
th,td{padding:.55rem .6rem;border-bottom:1px solid var(--line);text-align:start;vertical-align:top}
th{background:#f0f4f7;font-weight:600;color:var(--ink-2);white-space:nowrap}
tr.click{cursor:pointer} tr.click:hover{background:#f6fafc}
.num{font-variant-numeric:tabular-nums;white-space:nowrap}

/* auth */
.authbox{max-width:430px;margin:3rem auto}
.authbox .card{padding:1.5rem}

/* order workspace */
.workspace{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:1rem;align-items:start}
@media (max-width:1000px){.workspace{grid-template-columns:1fr}}
.sticky{position:sticky;top:4.2rem}
.section-title{display:flex;align-items:center;gap:.6rem;margin-bottom:.8rem}
.section-title .n{width:1.7rem;height:1.7rem;border-radius:50%;background:var(--brand);color:#fff;display:inline-flex;align-items:center;justify-content:center;font-size:.85rem;flex:none}
.toolbar{display:flex;gap:.4rem;flex-wrap:wrap;margin:.5rem 0}
.seg{display:inline-flex;border:1px solid var(--brand);border-radius:8px;overflow:hidden}
.seg button{border:0;background:#fff;color:var(--brand);padding:.3rem .8rem;font:inherit;cursor:pointer}
.seg button.on{background:var(--brand);color:#fff}
.chartbox{background:linear-gradient(#fff,#eef3f7);border:1px solid var(--line);border-radius:var(--radius);padding:.5rem}
svg.teeth{width:100%;height:auto;max-height:520px;display:block;touch-action:manipulation}
.tooth{cursor:pointer;outline:none}
.tooth .shape{fill:#fbfaf6;stroke:#9fb0bf;stroke-width:1.5;transition:fill .12s}
.tooth:hover .shape{stroke:var(--brand);stroke-width:2.5}
.tooth.assigned .shape{stroke:#33475b}
.tooth.selected .shape{stroke:var(--accent);stroke-width:4}
.tooth:focus-visible .shape{stroke:#1b6fb3;stroke-width:4}
.tooth text{font-size:11px;fill:#33475b;pointer-events:none;text-anchor:middle;dominant-baseline:central}
.tooth.pontic .shape{stroke-dasharray:4 3}
.midline{stroke:#c5d0da;stroke-dasharray:3 4}
.jawlabel{font-size:12px;fill:#7a8b9b;text-anchor:middle}
.itemcard{border:1px solid var(--line);border-inline-start:6px solid var(--c,#999);border-radius:8px;padding:.7rem .8rem;margin-bottom:.7rem;background:#fff}
.itemcard header{display:flex;gap:.6rem;align-items:center;justify-content:space-between;margin-bottom:.4rem}
.toothchip{display:inline-flex;align-items:center;gap:.3rem;border:1px solid var(--line);border-radius:6px;padding:.05rem .4rem;font-size:.85rem;background:#f7f9fb}
.dropzone{border:2px dashed #9fb4c6;border-radius:var(--radius);padding:1.2rem;text-align:center;background:#f8fbfd}
.dropzone.drag{background:#e6f1f9;border-color:var(--brand)}
progress{width:100%;height:.6rem}
.filerow{display:flex;gap:.6rem;align-items:center;padding:.4rem 0;border-bottom:1px solid var(--line);flex-wrap:wrap}
.kv{display:grid;grid-template-columns:max-content 1fr;gap:.2rem .9rem;font-size:.92rem}
.kv dt{color:var(--muted)} .kv dd{margin:0}
.timeline{list-style:none;margin:0;padding:0}
.timeline li{padding:.35rem 0;border-bottom:1px dashed var(--line);font-size:.9rem}
.msg{padding:.5rem .7rem;border-radius:8px;background:#eef3f7;margin-bottom:.5rem}
.msg.internal{background:#fff6dc;border:1px dashed var(--warn)}
.msg .meta{font-size:.78rem;color:var(--muted)}
.toast-host{position:fixed;bottom:1rem;inset-inline-start:1rem;display:flex;flex-direction:column;gap:.5rem;z-index:99}
.toast{background:var(--ink);color:#fff;padding:.6rem 1rem;border-radius:8px;box-shadow:0 4px 14px rgba(0,0,0,.25);max-width:340px}
.toast.err{background:var(--bad)} .toast.ok{background:var(--ok)}
.modal-bg{position:fixed;inset:0;background:rgba(10,20,30,.5);display:flex;align-items:center;justify-content:center;z-index:50;padding:1rem}
.modal{background:#fff;border-radius:12px;padding:1.2rem;max-width:560px;width:100%;max-height:90vh;overflow:auto}
.ltr{direction:ltr;unicode-bidi:plaintext;text-align:start}
html[dir=ltr] body{font-family:"Segoe UI",Tahoma,sans-serif}
