:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --border: color-mix(in srgb, #172927 13%, #ffffff);
  --text: #172927;
  --text-muted: color-mix(in srgb, #172927 62%, #ffffff);
  --primary: #0e655d;
  --primary-hover: color-mix(in srgb, #0e655d 82%, #172927);
  --danger: #b9443d;
  --saffron: #d79b2b;
  --teal-soft: color-mix(in srgb, #0e655d 10%, #ffffff);
  --saffron-soft: color-mix(in srgb, #d79b2b 16%, #ffffff);
  --clay-soft: color-mix(in srgb, #b9443d 10%, #ffffff);
  --radius: 8px;
  --sidebar: 252px;
  --ease: cubic-bezier(.2, .75, .25, 1);
  --font-display: "Estedad", "Vazirmatn", Tahoma, sans-serif;
  --font-body: "Vazirmatn", Tahoma, sans-serif;
}

html { min-width: 320px; scroll-behavior: smooth; }
body { min-height: 100vh; font-family: var(--font-body); font-size: 15px; line-height: 1.75; background: var(--bg); color: var(--text); text-rendering: optimizeLegibility; }
button, input, select, textarea { font: inherit; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--primary-hover); text-decoration: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--saffron) 78%, #ffffff); outline-offset: 3px; }
::selection { color: #ffffff; background: var(--primary); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; inset: 12px auto auto 12px; z-index: 100; padding: 8px 14px; color: #ffffff; background: var(--text); border-radius: 4px; transform: translateY(-180%); }
.skip-link:focus { transform: translateY(0); }

.app-shell { min-height: 100vh; }
.topbar { position: fixed; inset: 0 0 0 auto; z-index: 20; width: var(--sidebar); background: var(--text); color: #ffffff; border: 0; }
.topbar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 1px; background: rgba(255,255,255,.08); }
.topbar-inner { max-width: none; min-height: 100%; margin: 0; padding: 28px 22px 22px; display: flex; flex-direction: column; align-items: stretch; gap: 0; flex-wrap: nowrap; }
.brand { display: flex; flex-direction: column; align-items: flex-start; width: fit-content; margin: 0 0 44px; color: #ffffff; }
.brand:hover { color: #ffffff; }
.brand-name { font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1.2; letter-spacing: -.04em; }
.brand-caption { color: rgba(255,255,255,.56); font-size: 11px; font-weight: 500; letter-spacing: .08em; }

.nav { position: relative; display: flex; flex: 1; flex-direction: column; gap: 3px; flex-wrap: nowrap; padding: 2px 0; }
.nav::before { content: ""; position: absolute; inset: 20px 6px 20px auto; width: 1px; background: rgba(255,255,255,.15); }
.nav a { position: relative; display: flex; min-height: 46px; align-items: center; padding: 8px 31px 8px 12px; color: rgba(255,255,255,.63); border-radius: 4px; transition: color 160ms var(--ease), background 160ms var(--ease), transform 160ms var(--ease); }
.nav a::before { content: ""; position: absolute; inset: 50% 1px auto auto; z-index: 1; width: 11px; height: 11px; background: var(--text); border: 1px solid rgba(255,255,255,.32); border-radius: 50%; transform: translateY(-50%); }
.nav a:hover { color: #ffffff; background: rgba(255,255,255,.055); transform: translateX(-2px); }
.nav a.active { color: #ffffff; background: rgba(255,255,255,.08); font-weight: 600; }
.nav a.active::before { background: var(--saffron); border-color: var(--saffron); box-shadow: 0 0 0 4px rgba(215,155,43,.14); }

.sidebar-tools { display: grid; gap: 18px; padding-top: 22px; border-top: 1px solid rgba(255,255,255,.1); }
.search-form { display: block; margin: 0; }
.search-form input { width: 100%; min-width: 0; color: #ffffff; background: rgba(255,255,255,.065); border-color: rgba(255,255,255,.12); }
.search-form input::placeholder { color: rgba(255,255,255,.42); }
.search-form input:focus { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.32); }
.account-row { display: grid; grid-template-columns: 32px minmax(0,1fr) auto; align-items: center; gap: 9px; }
.user-chip { display: grid; width: 32px; height: 32px; place-items: center; color: var(--text); background: var(--saffron); border-radius: 50%; font-weight: 700; }
.account-name { overflow: hidden; color: rgba(255,255,255,.68); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.logout-form { display: block; margin: 0; }

.app-main { min-height: 100vh; margin-right: var(--sidebar); }
.container { width: min(100%,1480px); max-width: none; margin: 0 auto; padding: 42px clamp(24px,4vw,64px) 64px; }
.public-container { display: grid; min-height: 100vh; max-width: none; align-items: center; padding: 28px; background: linear-gradient(90deg,transparent 0 72%,color-mix(in srgb,var(--primary) 7%,transparent) 72%), var(--bg); }

h1, h2, h3 { font-family: var(--font-display); color: var(--text); text-wrap: pretty; }
h1 { margin: 0; font-size: clamp(28px,3vw,42px); font-weight: 700; line-height: 1.35; letter-spacing: -.035em; }
h2 { margin: 0; font-size: 18px; font-weight: 650; line-height: 1.55; }
h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
p { text-wrap: pretty; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.page-header > div, .page-header .quick-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 0; }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px; color: var(--text-muted); font-size: 13px; }
.back-link::before { content: "←"; }

.card { padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: none; }
.card-link { color: var(--text); transition: border-color 160ms var(--ease), transform 160ms var(--ease); }
.card-link:hover { color: var(--text); border-color: color-mix(in srgb,var(--text) 23%,#ffffff); transform: translateY(-2px); box-shadow: none; }
.grid { grid-template-columns: repeat(auto-fill,minmax(220px,1fr)); gap: 12px; }
.relationship-toggle { display: flex; gap: 6px; margin-bottom: 18px; }
.relationship-grid.single-view { grid-template-columns: 1fr; }

.btn { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 15px; color: #ffffff; background: var(--primary); border: 1px solid var(--primary); border-radius: 4px; font-size: 13px; font-weight: 600; transition: background 160ms var(--ease), border-color 160ms var(--ease), transform 160ms var(--ease); }
.btn:hover { color: #ffffff; background: var(--primary-hover); border-color: var(--primary-hover); transform: translateY(-1px); }
.btn-secondary { color: var(--text); background: var(--surface); border-color: color-mix(in srgb,var(--text) 22%,#ffffff); }
.btn-secondary:hover { color: var(--primary-hover); background: var(--teal-soft); border-color: color-mix(in srgb,var(--primary) 35%,#ffffff); }
.btn-ghost { min-height: 30px; padding: 4px 8px; color: rgba(255,255,255,.56); background: transparent; border-color: transparent; }
.btn-ghost:hover { color: #ffffff; background: rgba(255,255,255,.06); border-color: transparent; }
.btn-link { padding: 0; color: var(--text-muted); background: none; border: 0; font-size: 12px; font-weight: 500; }
.btn-link:hover { color: var(--primary); }

input, select, textarea { min-height: 42px; padding: 8px 11px; color: var(--text); background: var(--surface); border: 1px solid color-mix(in srgb,var(--text) 22%,#ffffff); border-radius: 4px; font-size: 14px; transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease); }
textarea { min-height: 116px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb,var(--primary) 13%,transparent); }
input:disabled, select:disabled, textarea:disabled, button:disabled { opacity: .48; cursor: not-allowed; }
form.form, form.card { max-width: 660px; }
form p { gap: 5px; margin: 0 0 16px; }
form p label { color: var(--text-muted); font-size: 13px; font-weight: 500; }

.alert { margin: 0 0 16px; padding: 12px 14px; border-radius: 4px; font-size: 13px; }
.alert-error { color: var(--danger); background: var(--clay-soft); border-color: color-mix(in srgb,var(--danger) 30%,#ffffff); }
.alert-warning { color: color-mix(in srgb,var(--saffron) 54%,var(--text)); background: var(--saffron-soft); border-color: color-mix(in srgb,var(--saffron) 34%,#ffffff); }
.alert-success { color: var(--primary-hover); background: var(--teal-soft); border-color: color-mix(in srgb,var(--primary) 26%,#ffffff); }

.auth-card { position: relative; width: min(100%,440px); max-width: none; margin: auto; padding: 44px; overflow: hidden; }
.auth-card::before { content: "هرمز"; display: block; margin-bottom: 34px; color: var(--primary); font-family: var(--font-display); font-size: 22px; font-weight: 700; }
.auth-card h1 { margin-bottom: 26px; font-size: 28px; }

.table-wrap { overflow: auto; border-radius: var(--radius); }
.table { min-width: 560px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 12px 15px; font-size: 13px; }
.table th { color: var(--text-muted); background: color-mix(in srgb,var(--bg) 72%,#ffffff); font-size: 11px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.table tbody tr { transition: background 120ms var(--ease); }
.table tbody tr:hover { background: var(--teal-soft); }
.table td a { font-weight: 600; }
.table .empty { padding: 32px 18px; }

.detail-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); padding: 0; }
.detail-list > div { display: grid; grid-template-columns: minmax(100px,.75fr) minmax(0,1.25fr); gap: 16px; min-height: 52px; align-items: start; padding: 13px 16px; }
.detail-list > div:nth-child(odd) { border-left: 1px solid var(--border); }
.detail-list > div:nth-last-child(-n+2) { border-bottom: 0; }
.detail-list > div:last-child:nth-child(odd) { grid-column: 1/-1; border-left: 0; }
.detail-list dt { font-size: 12px; }
.detail-list dd { font-size: 13px; font-weight: 600; }

.badge-warning, .badge-danger, .badge-type { min-height: 24px; display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 1.4; }
.badge-warning { color: color-mix(in srgb,var(--saffron) 54%,var(--text)); background: var(--saffron-soft); border-color: color-mix(in srgb,var(--saffron) 34%,#ffffff); }
.badge-danger { color: var(--danger); background: var(--clay-soft); border-color: color-mix(in srgb,var(--danger) 26%,#ffffff); }
.badge-type { color: var(--primary-hover); background: var(--teal-soft); border-color: color-mix(in srgb,var(--primary) 22%,#ffffff); }

.saved-views { gap: 6px; margin-bottom: 22px; padding-bottom: 13px; }
.view-chip { min-height: 30px; display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 4px; font-size: 12px; }
.view-chip.active { color: #ffffff; background: var(--primary); border-color: var(--primary); }
.save-view-form { margin-right: auto; }
.filter-row { gap: 8px; margin-bottom: 18px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.filter-checkbox input { width: 16px; min-height: 16px; accent-color: var(--primary); }

.today-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.today-heading-copy { display: grid; gap: 5px; }
.today-kicker { margin: 0; color: var(--primary); font-size: 12px; font-weight: 600; }
.today-heading .text-muted { max-width: 460px; margin: 0; }
.focus-banner { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 12px; margin: 0 0 22px; padding: 10px 12px; background: var(--saffron-soft); border: 1px solid color-mix(in srgb,var(--saffron) 34%,#ffffff); border-radius: var(--radius); }
.focus-banner label { color: color-mix(in srgb,var(--saffron) 54%,var(--text)); font-size: 12px; font-weight: 700; white-space: nowrap; }
.focus-banner input { background: rgba(255,255,255,.72); border-color: transparent; }
.today-grid { display: grid; grid-template-columns: repeat(12,minmax(0,1fr)); gap: 14px; }
.today-box { grid-column: span 6; min-width: 0; padding: 18px; border-radius: var(--radius); box-shadow: none; }
.today-box-wide { grid-column: 1/-1; }
.today-box h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 15px; }
.today-box h2::before { content: ""; width: 8px; height: 8px; background: var(--primary); border-radius: 50%; }
.today-box-danger h2::before { background: var(--danger); }
.today-box-complete h2::before { background: var(--saffron); }
.followup-list { gap: 7px; margin-bottom: 14px; }
.followup-item { min-height: 44px; gap: 12px; padding: 9px 11px; color: var(--text); background: color-mix(in srgb,var(--bg) 54%,#ffffff); border-radius: 4px; font-size: 13px; }
.followup-item:hover { background: var(--teal-soft); border-color: color-mix(in srgb,var(--primary) 22%,#ffffff); }
.followup-item > a { color: var(--text); }
.followup-tag, .followup-date { font-size: 11px; }
.waiting-columns { gap: 14px; }
.action-row-controls { padding-top: 8px; border-top: 1px solid var(--border); }
.wait-form select, .wait-form input { min-height: 32px; padding: 4px 7px; font-size: 11px; }
.inbox-form { max-width: none !important; margin: 0 0 14px; padding: 0; background: transparent; border: 0; }

.board { gap: 10px; padding: 2px 2px 16px; scroll-snap-type: x proximity; }
.board-column { flex-basis: 246px; min-height: 220px; padding: 12px; background: color-mix(in srgb,var(--bg) 70%,#ffffff); border: 0; border-top: 3px solid color-mix(in srgb,var(--text) 22%,#ffffff); border-radius: 0 0 var(--radius) var(--radius); scroll-snap-align: start; }
.board-count { min-width: 25px; height: 25px; display: inline-grid; place-items: center; border-radius: 50%; font-size: 10px; }
.board-card { gap: 5px; padding: 11px; border-radius: 4px; }
.board-card:hover { border-color: color-mix(in srgb,var(--primary) 38%,#ffffff); transform: translateY(-1px); }
.board-card > a { color: var(--text); }
.board-card-value { color: var(--primary); font-weight: 600; }

.workspace-nav { top: 0; z-index: 10; gap: 4px; margin-bottom: 28px; padding: 9px 0; background: color-mix(in srgb,var(--bg) 92%,transparent); backdrop-filter: blur(12px); }
.workspace-nav a { padding: 5px 10px; border-radius: 4px; font-size: 12px; }
.workspace-nav a:hover { color: var(--primary-hover); background: var(--teal-soft); }
.workspace-section { margin-bottom: 38px; scroll-margin-top: 70px; }
.stage-progress-bar { height: 5px; }
.stage-progress-fill { background: var(--primary); }
.stage-step { min-height: 26px; display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 4px; font-size: 10px; }
.stage-step-done { color: var(--primary-hover); background: var(--teal-soft); border-color: color-mix(in srgb,var(--primary) 22%,#ffffff); }
.stage-step-current { color: #ffffff; background: var(--primary); border-color: var(--primary); }

.note-stream { position: relative; gap: 9px; padding-right: 16px; }
.note-stream::before { content: ""; position: absolute; inset: 12px 2px 12px auto; width: 1px; background: color-mix(in srgb,var(--text) 22%,#ffffff); }
.note-item { position: relative; padding: 13px 15px; border-radius: 4px; }
.note-item::before { content: ""; position: absolute; inset: 17px -19px auto auto; width: 7px; height: 7px; background: var(--primary); border: 3px solid var(--bg); border-radius: 50%; }

.kpi-grid { gap: 10px; margin: 10px 0 28px; }
.kpi-tile { padding: 16px; border-radius: var(--radius); }
.kpi-tile:hover { border-color: var(--primary); }
.kpi-tile-value { font-family: var(--font-display); font-size: 28px; }
.kpi-tile-outcome { color: #ffffff; background: var(--primary); border-color: var(--primary); }
.kpi-tile-outcome:hover { color: #ffffff; background: var(--primary-hover); border-color: var(--primary-hover); }
.kpi-tile-outcome .kpi-tile-value { color: #ffffff; }

details summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "+"; margin-right: 8px; }
details[open] summary::after { content: "−"; }

@media (max-width:1040px) {
  :root { --sidebar: 220px; }
  .container { padding-inline: 28px; }
  .detail-list { grid-template-columns: 1fr; }
  .detail-list > div:nth-child(odd) { border-left: 0; }
  .detail-list > div:nth-last-child(-n+2) { border-bottom: 1px solid var(--border); }
  .detail-list > div:last-child { border-bottom: 0; }
}

@media (max-width:760px) {
  body { padding-bottom: 68px; font-size: 14px; }
  .topbar { inset: auto 0 0; width: 100%; height: 68px; }
  .topbar-inner { display: block; min-height: 0; padding: 0; }
  .brand, .sidebar-tools { display: none; }
  .nav { display: grid; grid-template-columns: repeat(6,1fr); gap: 0; padding: 0; }
  .nav::before { display: none; }
  .nav a { min-height: 68px; justify-content: center; padding: 28px 2px 5px; border-radius: 0; font-size: 10px; text-align: center; }
  .nav a::before { inset: 13px 50% auto auto; width: 8px; height: 8px; transform: translateX(50%); }
  .nav a:hover { transform: none; }
  .app-main { margin-right: 0; }
  .container { padding: 24px 16px 42px; }
  .public-container { padding: 16px; }
  .auth-card { padding: 30px 24px; }
  .page-header, .today-heading { align-items: stretch; flex-direction: column; gap: 12px; }
  .page-header > div, .page-header .quick-actions { justify-content: flex-start; }
  .focus-banner { grid-template-columns: 1fr auto; }
  .focus-banner label { grid-column: 1/-1; }
  .today-grid { grid-template-columns: 1fr; }
  .today-box, .today-box-wide { grid-column: 1; }
  .waiting-columns { grid-template-columns: 1fr; }
  .filter-row { align-items: stretch; flex-direction: column; }
  .filter-row select, .filter-row input[type="text"], .filter-row input[type="number"] { width: 100%; }
  .save-view-form { width: 100%; margin: 7px 0 0; }
  .detail-list > div { grid-template-columns: 1fr; gap: 2px; }
  .workspace-nav { flex-wrap: nowrap; overflow-x: auto; }
  .followup-item { align-items: flex-start; flex-direction: column; }
  .inbox-form { flex-direction: column; }
}

@media (prefers-reduced-motion:reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
