:root,
[data-theme="emerald"] {
  --bg: #eef4f1;
  --bg-2: #e4eeea;
  --surface: #ffffff;
  --surface-2: #f4faf7;
  --chat: #dbeee6;
  --text: #12352f;
  --muted: #5b746e;
  --line: #d5e4de;
  --primary: #0f766e;
  --primary-2: #0d9488;
  --primary-ink: #ffffff;
  --accent: #d97706;
  --sidebar: #0b3d38;
  --sidebar-ink: #d7efe9;
  --sidebar-muted: #9cc9c0;
  --sidebar-on: #123f3a;
  --bubble-in: #ffffff;
  --bubble-out: #c8f0e2;
  --doc: #fff8e1;
  --unread: #0284c7;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --shadow: 0 10px 30px rgba(15, 55, 48, .08);
  --pattern: radial-gradient(circle at 20% 20%, rgba(15, 118, 110, .08) 0 2px, transparent 3px);
}

[data-theme="navy"] {
  --bg: #eef1f6;
  --bg-2: #e3e8f0;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --chat: #d9e3f2;
  --text: #12233d;
  --muted: #5b6b82;
  --line: #d4dce8;
  --primary: #1e3a5f;
  --primary-2: #2b4d7a;
  --primary-ink: #fff8e7;
  --accent: #c9a227;
  --sidebar: #10233f;
  --sidebar-ink: #e8eef8;
  --sidebar-muted: #abc0dc;
  --sidebar-on: #1b365c;
  --bubble-in: #ffffff;
  --bubble-out: #d9e6fb;
  --doc: #fff4d4;
  --unread: #2563eb;
  --danger: #b91c1c;
  --ok: #047857;
  --warn: #b45309;
  --shadow: 0 10px 30px rgba(16, 35, 63, .1);
  --pattern: radial-gradient(circle at 20% 20%, rgba(30, 58, 95, .1) 0 2px, transparent 3px);
}

[data-theme="sand"] {
  --bg: #f6efe6;
  --bg-2: #efe4d6;
  --surface: #fffdf9;
  --surface-2: #fbf4ea;
  --chat: #f0e2cf;
  --text: #3f2e22;
  --muted: #7c6656;
  --line: #e6d5c3;
  --primary: #9a3412;
  --primary-2: #c2410c;
  --primary-ink: #fff7ed;
  --accent: #b45309;
  --sidebar: #3f2a1d;
  --sidebar-ink: #f8eadb;
  --sidebar-muted: #d8b99a;
  --sidebar-on: #533726;
  --bubble-in: #fffdf8;
  --bubble-out: #f3ddc0;
  --doc: #ffe9b5;
  --unread: #c2410c;
  --danger: #b91c1c;
  --ok: #3f6212;
  --warn: #b45309;
  --shadow: 0 10px 30px rgba(63, 42, 29, .08);
  --pattern: radial-gradient(circle at 20% 20%, rgba(154, 52, 18, .1) 0 2px, transparent 3px);
}

[data-theme="night"] {
  --bg: #0f1419;
  --bg-2: #151c24;
  --surface: #1a2330;
  --surface-2: #223042;
  --chat: #121a24;
  --text: #e8eef6;
  --muted: #93a4b8;
  --line: #2a384a;
  --primary: #2dd4bf;
  --primary-2: #14b8a6;
  --primary-ink: #042f2e;
  --accent: #fbbf24;
  --sidebar: #0b1016;
  --sidebar-ink: #e8eef6;
  --sidebar-muted: #8aa0b8;
  --sidebar-on: #1a2736;
  --bubble-in: #243246;
  --bubble-out: #134e4a;
  --doc: #3a2f18;
  --unread: #38bdf8;
  --danger: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --shadow: 0 12px 32px rgba(0, 0, 0, .35);
  --pattern: radial-gradient(circle at 20% 20%, rgba(45, 212, 191, .12) 0 2px, transparent 3px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Vazirmatn, Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 1rem; }
img { max-width: 100%; }
.grow { flex: 1; min-width: 0; }
code { font-family: inherit; background: var(--bg); padding: 1px 6px; border-radius: 6px; }

html { --side-w: 280px; }
.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--side-w, 280px) minmax(0, 1fr);
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 12px;
  position: relative;
  min-width: 0;
}
.sidebar-resizer {
  position: absolute;
  top: 0; bottom: 0;
  inset-inline-end: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 4;
}
.sidebar-collapse {
  margin-inline-start: auto;
  color: inherit;
  flex-shrink: 0;
}
.sidebar-handle {
  display: none;
  position: fixed;
  top: 42%;
  inset-inline-start: 0;
  z-index: 36;
  width: 22px;
  height: 72px;
  border: 0;
  cursor: pointer;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  border-start-end-radius: 14px;
  border-end-end-radius: 14px;
  box-shadow: var(--shadow);
  place-items: center;
}
html.sidebar-closed .app-shell { grid-template-columns: 0 minmax(0, 1fr); }
html.sidebar-closed .sidebar {
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
}
html.sidebar-closed .sidebar-handle { display: grid; }
html.sidebar-closed .sidebar-resizer { display: none; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand > div:nth-child(2) { min-width: 0; flex: 1; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--primary-2), var(--primary));
  color: var(--primary-ink);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand strong { display: block; font-size: 14px; }
.brand span, .side-user span { display: block; font-size: 12px; opacity: .75; }
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  color: var(--sidebar-ink); padding: 10px 12px; border-radius: 12px;
}
.side-nav a svg { width: 18px; height: 18px; opacity: .9; }
.side-nav a b {
  margin-inline-start: auto; background: #ef4444; color: #fff;
  min-width: 20px; height: 20px; border-radius: 999px;
  display: grid; place-items: center; font-size: 11px; padding: 0 6px;
}
.side-nav a.on, .side-nav a:hover { background: var(--sidebar-on); }
.nav-sep { margin: 16px 8px 8px; font-size: 11px; color: var(--sidebar-muted); }
.side-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 14px; background: rgba(255,255,255,.06);
}
.side-user img, .pick-user img, .chat-item img, .bubble img, .ref-node img, .user-row img {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: #fff;
}
.side-user .icon-btn { color: var(--sidebar-ink); }

.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; flex: 1; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.content { padding: 18px; flex: 1; min-height: 0; overflow: auto; }
.content:has(.inbox-shell) { padding: 0; overflow: hidden; display: flex; flex-direction: column; }

.theme-switch { display: flex; gap: 6px; }
.theme-switch button {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15); cursor: pointer;
}
.theme-switch [data-theme="emerald"] { background: #0f766e; }
.theme-switch [data-theme="navy"] { background: #1e3a5f; }
.theme-switch [data-theme="sand"] { background: #9a3412; }
.theme-switch [data-theme="night"] { background: #111827; }

.icon-btn {
  width: 40px; height: 40px; border: 0; background: transparent; color: inherit;
  border-radius: 12px; display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  background: var(--surface-2); color: var(--text); font-weight: 600;
  box-shadow: 0 0 0 1px var(--line);
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--primary); color: var(--primary-ink); box-shadow: none; }
.btn.ghost { background: transparent; }
.btn.warn { background: var(--warn); color: #fff; box-shadow: none; }
.btn.danger { background: var(--danger); color: #fff; box-shadow: none; }
.btn.lg { width: 100%; padding: 12px 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
input[type="text"], input[type="password"], input[type="tel"], input[type="search"],
input[type="number"], input[type="email"], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); border-radius: 12px; padding: 10px 12px; outline: none;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.muted { color: var(--muted); }
.form-h { margin: 8px 0 0; font-size: 14px; }

.card {
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px;
}
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); }
.stat b { display: block; font-size: 26px; }
.stat span { color: var(--muted); font-size: 13px; }

.alert, .toast {
  padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; font-weight: 500;
}
.toast { position: sticky; top: 61px; z-index: 70; margin: 10px 18px 0; }
.alert.bad, .toast-error { background: #fee2e2; color: #991b1b; }
.alert.ok, .toast-ok { background: #d1fae5; color: #065f46; }
.toast-warn { background: #fef3c7; color: #92400e; }
[data-theme="night"] .alert.bad, [data-theme="night"] .toast-error { background: #3f1d1d; color: #fecaca; }
[data-theme="night"] .alert.ok, [data-theme="night"] .toast-ok { background: #12372c; color: #a7f3d0; }

.auth-body { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.auth-wrap {
  width: min(980px, 100%); display: grid; grid-template-columns: 1.1fr .9fr;
  background: var(--surface); border-radius: 28px; overflow: hidden; box-shadow: var(--shadow);
}
.auth-hero { background: var(--sidebar); color: var(--sidebar-ink); padding: 36px; }
.auth-hero h1 { font-size: 32px; line-height: 1.35; margin: 24px 0 12px; }
.auth-points { list-style: none; padding: 0; display: grid; gap: 10px; }
.auth-points li { display: flex; gap: 8px; align-items: center; }
.auth-points svg { width: 18px; height: 18px; }
.auth-card { padding: 36px; }
.auth-themes { margin-top: 22px; justify-content: center; }

.inbox-shell {
  display: flex; flex-direction: column;
  height: 100%; min-height: 0; flex: 1;
  background: var(--surface);
}
.list-pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; flex: 1;
  background: var(--surface);
}
.inbox-hint { margin: 0; }
.list-tools { padding: 12px; display: grid; gap: 10px; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--bg);
  border-radius: 999px; padding: 0 12px;
}
.search svg { width: 18px; height: 18px; color: var(--muted); }
.search input { border: 0; background: transparent; padding-inline: 0; box-shadow: none; }
.search button.icon-btn { width: 36px; height: 36px; flex-shrink: 0; }
.pills { display: flex; gap: 6px; overflow: auto; padding-bottom: 2px; }
.pills a, .pills button {
  white-space: nowrap; border: 0; background: var(--bg); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.pills a svg, .pills button svg { display: none; width: 18px; height: 18px; flex-shrink: 0; }
.pills a.on, .pills button.on { background: var(--primary); color: var(--primary-ink); }
.chat-list { overflow: auto; flex: 1; min-height: 0; }
.chat-item {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 10px;
  padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--line);
  color: inherit; position: relative;
}
.chat-item:hover, .chat-item.on { background: var(--surface-2); }
.chat-item.unread b.title { font-weight: 800; }
.chat-item .who { display: flex; justify-content: space-between; gap: 8px; }
.chat-item .title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .meta { text-align: end; font-size: 11px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--unread); margin-top: 8px; margin-inline-start: auto; }
.chat-item.urgent { border-inline-start: 3px solid var(--warn); }
.chat-item.critical { border-inline-start: 3px solid var(--danger); }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700;
}
.badge.normal { background: var(--bg-2); }
.badge.urgent { background: #ffedd5; color: #9a3412; }
.badge.critical { background: #fee2e2; color: #991b1b; }
[data-theme="night"] .badge.urgent { background: #3b2610; color: #fdba74; }
[data-theme="night"] .badge.critical { background: #3f1d1d; color: #fca5a5; }

.thread-pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  background: var(--chat); background-image: var(--pattern); background-size: 18px 18px;
}
.thread-empty { margin: auto; text-align: center; color: var(--muted); padding: 40px; }
.thread-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  position: relative;
}
.thread-head h2 { margin: 0; font-size: 16px; }
.thread-head .grow { min-width: 0; flex: 1; }
.thread-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.doc-card {
  background: var(--doc); border-radius: 16px; padding: 14px; max-width: 720px;
  margin-inline: auto; width: 100%; box-shadow: var(--shadow);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-inline-start: 4px solid var(--accent);
}
.doc-card h3 { margin: 0 0 8px; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.doc-meta span { display: inline-flex; align-items: center; gap: 4px; }
.doc-meta svg { width: 14px; height: 14px; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px;
  background: var(--bg); border-radius: 10px; color: var(--text); font-size: 13px;
}
.file-chip svg { width: 16px; height: 16px; }

.bubble {
  max-width: min(78%, 560px); padding: 8px 12px 6px; border-radius: 16px;
  box-shadow: 0 1px 1px rgba(0,0,0,.05); display: grid; gap: 4px;
}
.bubble.in { align-self: flex-end; background: var(--bubble-in); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-start; background: var(--bubble-out); border-bottom-right-radius: 4px; }
.bubble .from { font-size: 12px; font-weight: 700; color: var(--primary); }
.bubble .time { font-size: 11px; color: var(--muted); text-align: end; }
.sys {
  align-self: center; font-size: 12px; color: var(--muted);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  padding: 4px 10px; border-radius: 999px;
}

.composer {
  background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px 14px;
  flex-shrink: 0; display: grid; gap: 8px;
}
.ltr-no { direction: ltr; unicode-bidi: isolate; display: inline-block; text-align: left; font-variant-numeric: tabular-nums; }
.btn.sm { padding: 4px 8px; font-size: 12px; border-radius: 9px; }
.bubble-acts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.bubble-acts form { margin: 0; display: inline-flex; }
.bubble.kind-cc { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent, var(--primary)) 45%, transparent); }
.bubble.kind-bcc { opacity: .95; background: color-mix(in srgb, var(--surface) 40%, var(--bubble-in)); }
.bubble.hit { outline: 2px solid var(--primary); }
.search-hide { display: none !important; }
.thread-search {
  display: flex; align-items: center; gap: 6px; background: var(--bg);
  border-radius: 999px; padding: 0 10px; min-width: 160px; max-width: 240px;
}
.thread-search svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
.thread-search input { border: 0; background: transparent; padding: 6px 0; box-shadow: none; min-width: 0; }
.thread-head { flex-wrap: wrap; }
.note-row-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.note-row-head select { width: auto; padding: 6px 8px; }
.note-row-tools { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.branch-meta { font-size: 11px; color: var(--muted); padding: 0 4px 4px; }
.composer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.composer-actions form { margin: 0; }
.note-list { display: grid; gap: 8px; margin: 10px 0; }
.note-row { background: var(--bg); border-radius: 12px; padding: 10px; }
.note-row textarea { min-height: 64px; }
.thread-view-opts { display: grid; gap: 8px; }
.thread-view-opts .check.nested { padding-inline-start: 22px; }
.thread-view-opts .check:has(input:disabled) { opacity: .55; }
.thread-view-opts .check.locked-opt { opacity: 1; }
.thread-view-opts .check.locked-opt input { cursor: not-allowed; }

.tabs { display: flex; gap: 6px; }
.tabs button, .tabs a { border: 0; background: transparent; padding: 6px 10px; border-radius: 999px; cursor: pointer; color: inherit; text-decoration: none; font-size: 13px; }
.tabs button.on, .tabs a.on { background: var(--primary); color: var(--primary-ink); }

.picker { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--surface); }
.picker-search { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.picker-search svg { width: 16px; height: 16px; }
.picker-search input { border: 0; box-shadow: none; padding: 6px 0; }
.picker-tree { max-height: 320px; overflow: auto; }
.pick-gname { font-size: 12px; color: var(--muted); font-weight: 700; padding: 8px 12px; display: flex; gap: 6px; align-items: center; }
.pick-gname svg { width: 14px; height: 14px; }
.pick-user { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; }
.pick-user:hover { background: var(--surface-2); }
.pick-user:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.pick-user span { display: grid; line-height: 1.3; }
.pick-user i { font-style: normal; color: var(--muted); font-size: 12px; }
.pick-user img { width: 28px; height: 28px; }

.org-layout { display: grid; grid-template-columns: 1.1fr .9fr; gap: 16px; min-height: 70dvh; }
.org-tree, .org-users { min-height: 420px; }
.tree-item { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; cursor: default;
}
.tree-row svg, .tree-ico svg { width: 18px; height: 18px; flex-shrink: 0; }
.tree-ico { display: grid; place-items: center; width: 22px; height: 22px; color: var(--warn); }
.tree-row:hover, .tree-row.on { background: var(--surface-2); }
.tree-row.over { outline: 2px dashed var(--primary); }
.tree-kids { padding-inline-start: 18px; border-inline-start: 1px dashed var(--line); margin-inline-start: 16px; }
.user-row {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px;
  background: var(--surface-2); margin-bottom: 8px; cursor: grab;
}
.user-row:active { cursor: grabbing; }
.user-row .grow { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: right; }
table.data th { font-size: 12px; color: var(--muted); font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.ref-tree { list-style: none; padding: 0; margin: 0; }
.ref-node { display: flex; gap: 10px; background: var(--surface); border-radius: 14px; padding: 10px; margin: 8px 0; border-inline-start: 3px solid var(--line); }
.ref-node.st-unread { border-color: var(--unread); }
.ref-node.st-read { border-color: var(--ok); }
.ref-node.st-referred { border-color: var(--accent); }
.ref-node.st-closed { border-color: var(--muted); }
.ref-node small { display: block; color: var(--muted); }
.ref-node p { margin: 6px 0 0; }

.mobile-only { display: none; }
.sidebar-backdrop { display: none; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.compose-layout { display: grid; grid-template-columns: 1.2fr .8fr; gap: 16px; }
.profile-hero { display: flex; gap: 16px; align-items: center; padding: 8px 4px 16px; }
.profile-hero img { width: 88px; height: 88px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); }
.rule-head-acts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rule-head-acts form { margin: 0; }
.rule-acts { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.rule-acts form { margin: 0; }
.rule {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  background: var(--surface-2); border-radius: 12px; padding: 10px 12px;
}

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.drag-handle { cursor: grab; color: var(--muted); display: grid; place-items: center; }
.drag-handle svg { width: 16px; height: 16px; }
.danger-ico { color: var(--danger); }
.org-toolbar { margin-bottom: 14px; }
.org-board { display: grid; gap: 8px; }
.root-drop { border: 1px dashed var(--line); margin-bottom: 8px; }
.tree-users {
  display: flex; flex-wrap: wrap; gap: 8px; min-height: 44px;
  padding-block: 8px; padding-inline: 10px 10px; padding-inline-start: 36px;
  border-radius: 12px;
}
.tree-users.over, .tree-row.over, .holding-bin .over { outline: 2px dashed var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.drop-hint { font-size: 12px; color: var(--muted); }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px;
  background: var(--surface); border-radius: 999px; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line); font-size: 13px; font-weight: 600;
}
.user-chip[draggable="true"] { cursor: grab; }
.user-chip img { width: 28px; height: 28px; border-radius: 50%; }
.holding-bin { margin-top: 18px; border: 1px dashed var(--warn); border-radius: 16px; padding: 8px; background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.holding-bin .tree-row { cursor: default; }
.inactive-bin { margin-top: 12px; border: 1px dashed var(--muted); border-radius: 16px; padding: 8px; background: color-mix(in srgb, var(--muted) 10%, var(--surface)); }
.inactive-bin .tree-row { cursor: default; }
.inactive-bin .tree-ico { color: var(--muted); }
.user-chip.locked { cursor: pointer; opacity: .92; }
.rule.locked { cursor: default; }
.rule.locked .drag-handle { cursor: default; }
.icon-btn.danger-ico:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.rule { cursor: grab; }
.rule.allow { background: #ecfdf5; border-inline-start: 4px solid #059669; }
.rule.deny { background: #fef2f2; border-inline-start: 4px solid #dc2626; }
.rule.all-all,
.rule.allow.all-all,
.rule.deny.all-all { background: #f3e8ff; border-inline-start: 4px solid #7c3aed; }
.rule.hit { box-shadow: 0 0 0 2px var(--primary); }
.rule.dragging { opacity: .45; }
.rule-num { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface); font-size: 12px; font-weight: 800; }
.rule-tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; margin-inline-end: 6px; }
.rule.allow .rule-tag { background: #059669; color: #fff; }
.rule.deny .rule-tag { background: #dc2626; color: #fff; }
.rule.all-all .rule-tag { background: #7c3aed; color: #fff; }
[data-theme="night"] .rule.allow { background: #12372c; }
[data-theme="night"] .rule.deny { background: #3f1d1d; }
[data-theme="night"] .rule.all-all,
[data-theme="night"] .rule.allow.all-all,
[data-theme="night"] .rule.deny.all-all { background: #2e1a4d; }

.inspect-who { display: flex; gap: 12px; align-items: center; padding: 8px 0; }
.inspect-who img { width: 52px; height: 52px; border-radius: 50%; }
.result-list { display: grid; gap: 6px; max-height: 420px; overflow: auto; }
.result-row { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 12px; }
.result-row img { width: 32px; height: 32px; border-radius: 50%; }
.result-row small { display: block; color: var(--muted); font-size: 12px; }
.result-row.ok { background: #ecfdf5; }
.result-row.no { background: #fef2f2; }
.result-row.ok .rule-tag { background: #059669; color: #fff; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
.result-row.no .rule-tag { background: #dc2626; color: #fff; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
[data-theme="night"] .result-row.ok { background: #12372c; }
[data-theme="night"] .result-row.no { background: #3f1d1d; }
#inspectSel, #inspectGroupSel { height: 180px; }

table.data tr.is-inactive td { color: var(--muted); background: color-mix(in srgb, var(--muted) 12%, var(--surface)); }
.user-filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.user-filters .grow { flex: 1; min-width: 180px; }
.filter-check { padding-bottom: 8px; }
.icon-actions { flex-wrap: nowrap; }
.icon-actions form { margin: 0; }

.compose-page { max-width: 880px; margin: 0 auto; }
.compose-page .picker-tree { max-height: min(52vh, 520px); }
.acc.card { padding: 0; }
.acc { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--surface); }
.acc > summary {
  cursor: pointer; font-weight: 700; padding: 12px 16px; list-style: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::after { content: "▾"; color: var(--muted); font-weight: 400; }
.acc:not([open]) > summary::after { content: "◂"; }
.acc-body { padding: 0 16px 16px; }
.acc.compact { border: 0; background: transparent; }
.acc.compact > summary { padding: 6px 0; font-size: 13px; font-weight: 600; color: var(--muted); }

.kind-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kind-opt {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px;
  border: 1px solid var(--line); border-radius: 14px; cursor: pointer; background: var(--bg);
}
.kind-opt:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.kind-opt span { display: grid; gap: 2px; }
.kind-opt small { color: var(--muted); font-size: 12px; }
.badge.informal { background: var(--bg-2); color: var(--muted); }

.combo { position: relative; }
.combo-list {
  display: none; position: absolute; inset-inline: 0; top: 100%; z-index: 8;
  max-height: 240px; overflow: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; margin-top: 4px; box-shadow: var(--shadow);
}
.combo-list.open { display: block; }
.combo-opt {
  display: block; width: 100%; text-align: right; border: 0; background: transparent;
  padding: 8px 12px; cursor: pointer; color: inherit;
}
.combo-opt:hover { background: var(--surface-2); }

.chat-thread { display: flex; flex-direction: column; gap: 8px; max-width: 720px; margin-inline: auto; width: 100%; }
.thread-branch { display: flex; flex-direction: column; gap: 8px; padding-inline-start: 8px; border-inline-start: 2px solid color-mix(in srgb, var(--line) 70%, transparent); }
.branch-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: color-mix(in srgb, var(--surface) 80%, transparent);
  padding: 8px 12px; border-radius: 12px; cursor: pointer; color: inherit; text-align: right;
}
.branch-toggle svg { width: 16px; height: 16px; flex-shrink: 0; }
.branch-toggle:hover { background: var(--surface); }
.reply-row { display: flex; gap: 8px; align-items: flex-end; }
.reply-row textarea { min-height: 48px; max-height: 140px; flex: 1; }
.icon-btn.primary-ico { background: var(--primary); color: var(--primary-ink); }
.member-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.user-chip.static { cursor: default; }
.result-row.mix { background: #fff7ed; }
.result-row.mix .rule-tag { background: #c2410c; color: #fff; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
[data-theme="night"] .result-row.mix { background: #3b2610; }

.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  z-index: 40; place-items: center; padding: 18px;
}
.modal-overlay.open { display: grid; }
.modal { width: min(640px, 100%); max-height: 90dvh; overflow: auto; }
.same-note-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }

.modal-overlay.letter-room {
  z-index: 45; padding: 12px;
  grid-template: 1fr / 1fr;
  place-items: stretch center;
}
.letter-room-card {
  grid-area: 1 / 1;
  width: min(920px, 100%);
  height: min(96dvh, 100%);
  max-height: 96dvh;
  display: flex; flex-direction: column;
  padding: 0 !important; overflow: hidden;
  background: var(--chat); background-image: var(--pattern); background-size: 18px 18px;
}
.letter-room-inner {
  display: flex; flex-direction: column; height: 100%; min-height: 0;
}
.letter-room > .refer-sheet,
.letter-room > .note-sheet {
  grid-area: 1 / 1;
  z-index: 55;
  width: auto; height: auto;
  place-self: stretch;
}
.refer-sheet, .note-sheet { z-index: 55; }
.refer-sheet .picker-tree { max-height: min(36vh, 280px); }
.refer-sheet .modal { width: min(560px, 100%); }
.note-sheet .modal { width: min(440px, 100%); }
.doc-fold { max-width: 720px; margin-inline: auto; width: 100%; }
.doc-fold > summary {
  cursor: pointer; font-weight: 700; padding: 4px 6px 10px; color: var(--accent);
}
.doc-fold .doc-card { margin: 0; }

.party-combo {
  display: flex; align-items: center; position: relative;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.party-combo [data-combo-q] {
  border: 0 !important; box-shadow: none !important; height: 42px; flex: 1; min-width: 0;
}
.party-ico-btn {
  width: 42px; height: 42px; border: 0; background: transparent; color: var(--text);
  cursor: pointer; display: grid; place-items: center; flex-shrink: 0;
  border-inline-end: 1px solid var(--line);
}
.party-ico-btn svg { width: 18px; height: 18px; }
.party-combo .combo-list { z-index: 12; }
.party { display: inline-flex; align-items: center; gap: 6px; }
.party svg { width: 16px; height: 16px; flex-shrink: 0; }
.rule-party { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.combo-opt .party { pointer-events: none; }
.result-ico {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2, var(--bg)); color: var(--muted); flex-shrink: 0;
}
.result-ico.lg { width: 52px; height: 52px; }
.result-ico svg { width: 18px; height: 18px; }
.result-ico.lg svg { width: 24px; height: 24px; }

.sig-field { display: grid; gap: 8px; }
.sig-preview { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.sig-preview img, [data-sig-img] { max-height: 72px; max-width: 180px; background: #fff; border-radius: 8px; box-shadow: 0 0 0 1px var(--line); padding: 4px; }
.sig-stamp { margin-top: 6px; }
.sig-stamp img { max-height: 56px; max-width: 140px; background: #fff; border-radius: 6px; padding: 4px; }
.btn .sig-mini { height: 22px; max-width: 64px; margin-inline-start: 6px; background: #fff; border-radius: 4px; vertical-align: middle; }

.jcal-wrap { position: relative; display: flex; align-items: center; gap: 6px; width: 100%; }
.jcal-wrap input { flex: 1; min-width: 0; }
.jcal-btn {
  width: 40px; height: 40px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; color: var(--text); cursor: pointer; display: grid; place-items: center; flex-shrink: 0;
}
.jcal {
  position: fixed; z-index: 80; width: 280px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 10px;
}
.jcal-head { display: grid; grid-template-columns: 32px 1fr 1fr 32px; gap: 6px; align-items: center; margin-bottom: 8px; }
.jcal-head select { padding: 4px 6px; font-size: 13px; }
.jcal-nav { border: 0; background: var(--bg); border-radius: 8px; height: 32px; cursor: pointer; color: inherit; }
.jcal-week { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.jcal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.jcal-day, .jcal-empty { height: 32px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: inherit; }
.jcal-day:hover { background: var(--surface-2, var(--bg)); }
.jcal-day.on { background: var(--primary); color: var(--primary-ink); }
.jcal-day.today:not(.on) { box-shadow: 0 0 0 1px var(--primary); }
.jcal-day:disabled, .jcal-day.off { opacity: .35; cursor: not-allowed; }
.jcal-day:disabled:hover { background: transparent; }
.jcal-nav:disabled { opacity: .35; cursor: not-allowed; }
.jcal-foot { display: flex; justify-content: space-between; margin-top: 8px; }
.jcal-foot button { border: 0; background: transparent; color: var(--primary); cursor: pointer; font-weight: 600; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  html.sidebar-closed .app-shell { grid-template-columns: 1fr; }
  html.sidebar-closed .sidebar {
    visibility: visible; pointer-events: auto; overflow: auto;
  }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px);
    transform: translateX(110%); transition: transform .2s ease; z-index: 30;
  }
  html[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 20; }
  .sidebar-handle, .sidebar-resizer, .sidebar-collapse { display: none !important; }
  .mobile-only { display: grid; }
  .auth-wrap, .org-layout, .compose-layout, .grid2, .grid3, .stats { grid-template-columns: 1fr; }
  .inbox-shell { height: 100%; }
  .pills { gap: 4px; }
  .pills a, .pills button {
    flex: 1;
    min-width: 36px;
    height: 36px;
    padding: 0;
    font-size: 0;
  }
  .pills a svg, .pills button svg { display: block; }
  .pills .pill-lab {
    display: none !important;
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .inbox-hint { display: none; }
  .chat-item .preview { display: none; }
  .modal-overlay.letter-room {
    padding: 0;
    inset: 0;
    height: 100dvh;
    height: 100svh;
    max-height: 100svh;
  }
  .letter-room-card {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: 0;
    box-shadow: none;
  }
  .thread-head {
    padding: 6px 8px;
    gap: 6px;
    flex-wrap: nowrap;
  }
  .thread-head > .icon-btn,
  .thread-head > .badge { flex-shrink: 0; }
  .thread-head h2 {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .thread-head .grow small { display: block; font-size: 11px; }
  .thread-search {
    min-width: 36px;
    max-width: 36px;
    width: 36px;
    padding: 0;
    justify-content: center;
    flex-shrink: 0;
  }
  .thread-search input {
    width: 0;
    min-width: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
  }
  .thread-search:focus-within {
    position: absolute;
    inset-inline-end: 48px;
    inset-inline-start: 48px;
    top: 6px;
    width: auto;
    min-width: 0;
    max-width: none;
    padding: 0 10px;
    z-index: 3;
  }
  .thread-search:focus-within input {
    width: 100%;
    opacity: 1;
    padding: 6px 0;
    pointer-events: auto;
  }
  .thread-scroll { padding: 8px 8px 4px; gap: 8px; }
  .doc-fold > summary { padding: 2px 2px 6px; font-size: 13px; }
  .doc-card { padding: 10px; border-radius: 12px; }
  .doc-card h3 { display: none; }
  .doc-meta { gap: 6px; margin-bottom: 6px; }
  .chat-thread { gap: 6px; }
  .branch-meta { display: none; }
  .bubble { max-width: 94%; padding: 7px 10px 5px; }
  .bubble-acts {
    gap: 2px;
    margin-top: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }
  .bubble-acts .btn { padding: 4px 6px; }
  .bubble-acts .btn-lab { display: none; }
  .composer {
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }
  .reply-row textarea { min-height: 40px; }
  .composer-actions {
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .composer-actions .btn {
    padding: 8px;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .composer-actions .btn-lab { display: none; }
  .content { padding: 12px; }
  .content:has(.inbox-shell) { padding: 0; }
}
