/* ---------- design tokens ---------- */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1a1d23;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #b91c1c;
  --success: #047857;
  --warning: #c2410c;
  --pill-bg: #eef2ff;
  --pill-fg: #3730a3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a22;
    --border: #2a313d;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --pill-bg: #1e293b;
    --pill-fg: #c7d2fe;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.logo { font-size: 22px; }
.user-area { display: flex; align-items: center; gap: 12px; }
#userBadge { color: var(--muted); font-size: 13px; }
#modeBadge {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--pill-fg);
  font-weight: 600;
}

/* ---------- buttons & forms ---------- */
button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 16px;
  cursor: pointer;
  transition: background .12s ease, transform .05s ease;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-hover); }
button.primary:disabled { background: #94a3b8; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
button.ghost:hover { background: var(--bg); }
button.block { width: 100%; }

label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); font-weight: 500; }
label.row { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 400; }
label.row input { width: auto; }
input[type=text], input[type=email], input[type=password], textarea {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row.gap { display: flex; gap: 10px; align-items: center; }

/* ---------- screens & cards ---------- */
.screen { padding: 24px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* ---------- auth ---------- */
.auth-card { max-width: 440px; margin: 50px auto; }
.auth-card h1 { margin: 0 0 4px; }
.muted { color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 16px 0 18px; }
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 600;
}
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.error { color: var(--danger); margin-top: 8px; font-size: 13px; }

/* ---------- case layout ---------- */
.case-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 18px;
  max-width: 1200px;
  margin: 0 auto;
}
@media (max-width: 720px) {
  .case-layout { grid-template-columns: 1fr; }
}
.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  height: fit-content;
}
.sidebar h2 { margin: 0 0 12px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.case-list { list-style: none; padding: 0; margin: 12px 0 0; max-height: 480px; overflow: auto; }
.case-list li {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 4px;
  border: 1px solid transparent;
}
.case-list li:hover { background: var(--bg); }
.case-list li.active { background: var(--pill-bg); color: var(--pill-fg); font-weight: 600; }
.case-list .case-status { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.case-main .empty { text-align: center; color: var(--muted); }
.case-main .empty h2 { margin-top: 0; }

/* ---------- chat ---------- */
.chat-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.chat-header h2 { margin: 0; font-size: 19px; }
.chat-header .muted { margin: 4px 0 0; font-size: 13px; }
.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--pill-fg);
  font-size: 12px;
  font-weight: 600;
}

.messages {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px;
  max-height: 460px;
  overflow-y: auto;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.message { margin-bottom: 12px; display: flex; }
.message.user { justify-content: flex-end; }
.message .bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
}
.message.user .bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.message .role-label { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.message.assistant .role-label { text-align: left; }
.message.user .role-label { text-align: right; }

.reply { display: flex; gap: 10px; align-items: flex-end; }
.reply textarea { flex: 1; }
.actions { margin-top: 14px; }

/* ---------- report ---------- */
.report {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.report h3 { margin-top: 18px; }
.report .issue {
  padding: 10px 12px;
  border-left: 4px solid var(--border);
  margin-bottom: 8px;
  background: var(--bg);
  border-radius: 0 8px 8px 0;
}
.report .issue.RED { border-left-color: var(--danger); }
.report .issue.YELLOW { border-left-color: var(--warning); }
.report .issue.GREEN { border-left-color: var(--success); }
.report .severity-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: middle;
}
.report .severity-tag.RED { background: #fee2e2; color: #991b1b; }
.report .severity-tag.YELLOW { background: #fef3c7; color: #92400e; }
.report .severity-tag.GREEN { background: #d1fae5; color: #065f46; }
.report ul { padding-left: 22px; }
.report .disclaimer {
  margin-top: 22px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
}
.report .download-row { margin-top: 16px; display: flex; gap: 10px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 999;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- thinking indicator ---------- */
.thinking-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 0.95;
  font-style: italic;
}
.thinking-bubble .dots {
  display: inline-flex;
  gap: 3px;
}
.thinking-bubble .dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
  animation: thinking-bounce 1.2s infinite ease-in-out;
}
.thinking-bubble .dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-bubble .dots span:nth-child(3) { animation-delay: 0.30s; }
.thinking-elapsed {
  font-size: 11px;
  opacity: 0.6;
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
  font-style: normal;
}
@keyframes thinking-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

.thinking-bubble { flex-direction: column; align-items: flex-start; }
.thinking-line { display: inline-flex; align-items: center; gap: 8px; }
.thinking-note {
  margin-top: 8px;
  font-size: 12px;
  font-style: normal;
  opacity: 0.7;
  line-height: 1.45;
  max-width: 560px;
}

/* ---------- action plan panel ---------- */
.action-plan {
  background: rgba(34, 197, 94, 0.07);
  border: 1.5px solid rgba(34, 197, 94, 0.4);
  border-radius: 10px;
  padding: 18px 22px;
  margin: 22px 0 16px 0;
}
.action-plan h3 { color: #22c55e; margin-top: 0; border-bottom: 2px solid rgba(34, 197, 94, 0.25); padding-bottom: 6px; }
.action-plan h4 { color: #4ade80; margin-top: 14px; margin-bottom: 6px; }
.action-plan h4.ap-warn { color: #f87171; }
.ap-recommended {
  background: rgba(34, 197, 94, 0.12);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 10px 0 16px 0;
}
.ap-alt {
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid #94a3b8;
  padding: 10px 14px;
  margin: 10px 0;
  border-radius: 0 6px 6px 0;
}
.ap-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #86efac;
  margin-bottom: 4px;
}
.ap-alt .ap-label { color: #cbd5e1; }
.ap-when { margin: 4px 0 6px 0; font-size: 13px; opacity: 0.85; }
.action-plan ol li { margin-bottom: 6px; line-height: 1.5; }

/* ---------- section switcher (Cases / Contracts tabs in sidebar) ---------- */
.section-switch { display: flex; gap: 6px; margin-bottom: 12px; background: var(--surface-alt, #1e293b); border-radius: 8px; padding: 4px; }
.section-switch .seg {
  flex: 1; padding: 7px 10px; border: 0; background: transparent;
  color: var(--muted, #94a3b8); cursor: pointer; border-radius: 6px;
  font-size: 13px; font-weight: 500;
}
.section-switch .seg.active { background: var(--primary, #2563eb); color: #fff; }
.section-switch .seg:hover:not(.active) { background: rgba(255,255,255,0.05); }

/* ---------- contract template picker ---------- */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 14px; }
.tpl-card {
  text-align: left; padding: 14px; border: 1px solid var(--border, #334155);
  background: var(--surface-alt, #1e293b); color: var(--text, #e2e8f0);
  border-radius: 10px; cursor: pointer; transition: border-color 0.15s, transform 0.05s;
}
.tpl-card:hover { border-color: var(--primary, #2563eb); }
.tpl-card:active { transform: translateY(1px); }
.tpl-cat { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--primary, #60a5fa); font-weight: 600; }
.tpl-title { font-size: 15px; font-weight: 600; margin: 4px 0 2px 0; }
.tpl-desc { font-size: 12px; color: var(--muted, #94a3b8); margin-top: 8px; line-height: 1.45; }
.small { font-size: 11px; }

/* ---------- contract form ---------- */
#contractFields label { display: block; margin-bottom: 12px; }
#contractFields label span { display: block; font-size: 12px; color: var(--muted, #94a3b8); margin-bottom: 4px; }
#contractFields input[type=checkbox] { width: auto; margin-right: 6px; }

.danger { color: var(--danger, #dc2626); }

/* ---------- case attachments bar ---------- */
.attachments-bar {
  margin: 10px 0 6px 0;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border, #334155);
  border-radius: 8px;
}
.attachment-list { list-style: none; padding: 0; margin: 8px 0 0 0; }
.attachment-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 6px;
  background: rgba(255,255,255,0.03);
  margin-bottom: 4px; font-size: 13px;
}
.attachment-name { flex: 1; color: var(--text, #e2e8f0); }
.attachment-item button { padding: 2px 8px; border-radius: 4px; }

/* ---------- language selector in topbar ---------- */
.lang-select {
  background: var(--surface-alt, #1e293b);
  color: var(--text, #e2e8f0);
  border: 1px solid var(--border, #334155);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
  margin-right: 8px;
}
.lang-select:hover { border-color: var(--primary, #2563eb); }

/* ============================================================
   MODERN THEME OVERLAY (v9)
   Layered on top of the base tokens so the original design
   keeps working if anything below this is removed.
   ============================================================ */

:root {
  --grad-primary: linear-gradient(135deg, #6366f1 0%, #2563eb 60%, #0ea5e9 100%);
  --grad-accent: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
  --glass: rgba(255,255,255,0.65);
  --glass-stroke: rgba(255,255,255,0.4);
  --ring: 0 0 0 3px rgba(99,102,241,0.18);
  --easing: cubic-bezier(.2,.7,.2,1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --glass: rgba(22,26,34,0.6);
    --glass-stroke: rgba(255,255,255,0.06);
  }
}

/* ----- typography polish ----- */
body {
  font-family: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
  background:
    radial-gradient(60rem 40rem at -10% -10%, rgba(99,102,241,0.10), transparent 60%),
    radial-gradient(60rem 40rem at 110% 10%, rgba(14,165,233,0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
h1, h2, h3 { letter-spacing: -0.02em; }

/* ----- topbar ----- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  background: var(--glass);
  border-bottom: 1px solid var(--glass-stroke);
  padding: 12px 22px;
}
.brand {
  font-size: 16px; font-weight: 700;
  background: var(--grad-primary);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.brand .logo {
  filter: drop-shadow(0 2px 6px rgba(99,102,241,.4));
}
.lang-select {
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
}
#modeBadge { background: var(--grad-accent); color: #fff; border: none; }

/* ----- connection status dot ----- */
.conn-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22,163,74,0.18);
  transition: background .2s var(--easing), box-shadow .2s var(--easing);
  margin-right: 8px;
  cursor: help;
}
.conn-dot.warn { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,0.18); }
.conn-dot.down { background: #dc2626; box-shadow: 0 0 0 3px rgba(220,38,38,0.18); animation: pulse-down 1.4s infinite var(--easing); }
@keyframes pulse-down {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.35); }
}

/* ----- cards ----- */
.card {
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 10px 30px rgba(0,0,0,.06);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: box-shadow .25s var(--easing), border-color .2s var(--easing);
}
.card:hover { box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 16px 40px rgba(0,0,0,.08); }
.auth-card {
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: ""; position: absolute; inset: -2px;
  background: var(--grad-primary);
  filter: blur(40px); opacity: 0.18; z-index: -1;
}

/* ----- buttons ----- */
button { transition: background .15s var(--easing), transform .08s var(--easing), box-shadow .15s var(--easing); }
button.primary {
  background: var(--grad-primary);
  border: none;
  box-shadow: 0 6px 16px rgba(37,99,235,0.25), inset 0 -1px 0 rgba(0,0,0,0.15);
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
button.primary:active { transform: translateY(0); }
button.primary:focus-visible { outline: none; box-shadow: 0 6px 16px rgba(37,99,235,0.25), var(--ring); }
button.ghost { border-color: var(--border); }
button.ghost:hover { background: rgba(99,102,241,0.06); }

/* ----- form inputs ----- */
input, textarea, select {
  transition: border-color .15s var(--easing), box-shadow .15s var(--easing), background .15s var(--easing);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

/* ----- sidebar ----- */
.sidebar h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 14px 0 8px;
}
.case-list li {
  position: relative;
  border: 1px solid transparent;
  transition: background .15s var(--easing), border-color .15s var(--easing), transform .12s var(--easing);
  border-radius: 10px;
}
.case-list li:hover { background: rgba(99,102,241,0.06); transform: translateX(2px); }
.case-list li.active {
  background: rgba(99,102,241,0.12);
  border-color: rgba(99,102,241,0.4);
}
.case-list li.active::before {
  content: ""; position: absolute; left: -4px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 2px;
  background: var(--grad-primary);
}

/* ----- template cards ----- */
.tpl-card {
  position: relative; overflow: hidden;
  transition: transform .15s var(--easing), border-color .15s var(--easing), box-shadow .2s var(--easing);
}
.tpl-card::after {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--grad-primary);
  opacity: 0; transition: opacity .2s var(--easing);
}
.tpl-card:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(99,102,241,0.15); }
.tpl-card:hover::after { opacity: 1; }
.tpl-cat {
  background: var(--grad-accent);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  font-weight: 700;
}

/* ----- empty / pick state ----- */
.empty-pick {
  background:
    radial-gradient(20rem 12rem at 50% 0%, rgba(99,102,241,0.08), transparent 60%),
    transparent !important;
  transition: border-color .2s var(--easing);
}
.empty-pick:hover { border-color: rgba(99,102,241,0.4) !important; }
.empty { padding: 28px; }

/* ----- thinking bubble polish ----- */
.thinking-bubble {
  background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(14,165,233,0.10));
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 12px;
  padding: 10px 14px;
}
.thinking-bubble .dots span { background: var(--primary); }

/* ----- toast polish ----- */
.toast {
  border-radius: 12px;
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  animation: toast-in .25s var(--easing);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================================
   CONFIRM MODAL  (replaces native confirm() for destructive ops)
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: backdrop-in .15s var(--easing);
}
.modal-card {
  width: min(440px, 92vw);
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 30px 60px rgba(0,0,0,0.4);
  padding: 22px;
  animation: modal-in .2s var(--easing);
}
.modal-card h3 { margin: 0 0 8px; }
.modal-card p { margin: 0 0 16px; color: var(--muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   FOOTER (trust signals)
   ============================================================ */
.app-footer {
  padding: 16px 22px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
}
.app-footer .trust { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.trust-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.18);
  font-weight: 500;
  color: var(--text);
}
.trust-chip .ico { font-size: 13px; }

/* ============================================================
   SKELETON loader (for lists while data loads)
   ============================================================ */
.skel {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0.04) 100%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.2s infinite linear;
  border-radius: 6px;
  height: 14px;
}
@keyframes skel-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   MODERN THEME v10 — bolder, glassier, more eye-catching
   ============================================================ */

:root {
  --grad-hero:
    radial-gradient(60rem 40rem at 8% 10%, rgba(168,85,247,0.18), transparent 60%),
    radial-gradient(60rem 40rem at 92% 0%, rgba(14,165,233,0.22), transparent 60%),
    radial-gradient(70rem 50rem at 50% 110%, rgba(34,197,94,0.10), transparent 60%);
  --noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .04 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --stroke-soft: rgba(255,255,255,0.06);
}

/* ----- animated mesh background ----- */
body {
  background:
    var(--noise),
    var(--grad-hero),
    var(--bg);
  background-attachment: fixed;
  background-size: 200px 200px, auto, auto;
  position: relative;
}
body::before {
  content: "";
  position: fixed; inset: -10vmax;
  background:
    radial-gradient(40rem 30rem at 20% 30%, rgba(99,102,241,0.18), transparent 60%),
    radial-gradient(40rem 30rem at 80% 70%, rgba(236,72,153,0.14), transparent 60%);
  filter: blur(20px);
  z-index: -2;
  animation: mesh-drift 28s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes mesh-drift {
  0%   { transform: translate3d(0,0,0) rotate(0deg); }
  50%  { transform: translate3d(-3%,-2%,0) rotate(2deg); }
  100% { transform: translate3d(2%,3%,0) rotate(-2deg); }
}

/* ----- topbar v2: cleaner, brand more prominent ----- */
.topbar {
  border-bottom: 1px solid var(--stroke-soft);
  padding: 14px 26px;
}
.brand {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand .logo {
  font-size: 24px;
  filter: drop-shadow(0 4px 10px rgba(99,102,241,.45));
  animation: logo-float 4s ease-in-out infinite;
}
@keyframes logo-float {
  0%,100% { transform: translateY(0) rotate(-2deg); }
  50%     { transform: translateY(-2px) rotate(2deg); }
}
#modeBadge {
  box-shadow: 0 4px 12px rgba(168,85,247,0.35), inset 0 -1px 0 rgba(0,0,0,0.15);
  letter-spacing: 0.02em;
}

/* ----- auth screen hero polish ----- */
.auth-card {
  padding: 32px;
  border: 1px solid var(--stroke-soft);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01)),
    var(--surface);
}
.auth-card h1 {
  font-size: 32px;
  font-weight: 800;
  background: linear-gradient(135deg, #fff 0%, #c7d2fe 60%, #818cf8 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 6px;
}
.auth-card::before {
  background: var(--grad-primary);
  filter: blur(60px);
  opacity: 0.3;
  z-index: -1;
}

/* ----- case-main pane background card ----- */
.case-main .card {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.025), transparent 200px),
    var(--surface);
  animation: pane-fade-in .4s var(--easing);
}
@keyframes pane-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----- sidebar v2 ----- */
.sidebar {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.005)),
    var(--surface);
  border: 1px solid var(--stroke-soft);
  border-radius: 14px;
  padding: 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.section-switch {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--stroke-soft);
  padding: 4px;
  border-radius: 10px;
}
.section-switch .seg {
  font-weight: 600;
  border-radius: 7px;
}
.section-switch .seg.active {
  background: var(--grad-primary);
  box-shadow: 0 6px 16px rgba(99,102,241,0.4);
}
.case-list { display: flex; flex-direction: column; gap: 6px; }
.case-list li {
  padding: 10px 12px;
  list-style: none;
  cursor: pointer;
  font-size: 13.5px;
}
.case-list li .case-status {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 2px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.case-list li.active .case-status { color: #a5b4fc; }
.case-list li:hover { transform: translateX(3px); }

/* ----- buttons v2: pill-shape primaries with glow ----- */
button.primary {
  border-radius: 10px;
  padding: 10px 18px;
  letter-spacing: 0.01em;
  box-shadow:
    0 8px 20px rgba(99,102,241,0.4),
    0 1px 0 rgba(255,255,255,0.1) inset,
    0 -1px 0 rgba(0,0,0,0.2) inset;
}
button.primary::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.18), transparent 40%);
  opacity: 0; transition: opacity .15s var(--easing);
}
button.primary:hover::after { opacity: 1; }
button.primary {
  position: relative;
  overflow: hidden;
}
button.block { width: 100%; }

button.ghost {
  border-color: var(--stroke-soft);
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
}

/* ----- inputs / selects v2 ----- */
input, textarea, select {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--stroke-soft);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  font-size: 14px;
}
input:focus, textarea:focus, select:focus {
  background: rgba(99,102,241,0.04);
  border-color: rgba(99,102,241,0.6);
  box-shadow: 0 0 0 4px rgba(99,102,241,0.18);
}
textarea { resize: vertical; min-height: 80px; }

label { display: block; margin-bottom: 14px; }
label > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }

/* ----- template grid v2: bigger, category icons ----- */
.template-grid { gap: 16px; }
.tpl-card {
  padding: 18px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.04), transparent 80px),
    rgba(255,255,255,0.025);
  border: 1px solid var(--stroke-soft);
  display: flex; flex-direction: column; gap: 6px;
  min-height: 140px;
}
.tpl-card .tpl-icon {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  font-size: 20px;
  background: var(--grad-accent);
  box-shadow: 0 4px 12px rgba(168,85,247,0.3);
  margin-bottom: 4px;
}
.tpl-card .tpl-title {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.tpl-card:hover {
  border-color: rgba(99,102,241,0.5);
  transform: translateY(-4px);
}

/* ----- chat composer polish ----- */
.reply textarea {
  border-radius: 14px;
  font-size: 14px;
  padding: 14px 16px;
}
.messages {
  border-radius: 14px;
  padding: 8px 0;
}
.message .bubble {
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.message.user .bubble {
  background: var(--grad-primary);
  color: #fff;
  border: none;
}
.message .role-label { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }

/* ----- attachments bar v2 ----- */
.attachments-bar {
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px dashed var(--stroke-soft);
}
.attachment-item {
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  transition: background .15s var(--easing);
}
.attachment-item:hover { background: rgba(99,102,241,0.08); }

/* ----- footer chips v2 ----- */
.trust-chip {
  background: linear-gradient(180deg, rgba(99,102,241,0.08), rgba(99,102,241,0.04));
  transition: transform .15s var(--easing), border-color .15s var(--easing);
}
.trust-chip:hover {
  border-color: rgba(99,102,241,0.5);
  transform: translateY(-1px);
}

/* ----- pills v2 ----- */
.pill, #statusPill, #contractStatus {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--stroke-soft);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
}
#statusPill::before, #contractStatus::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.7;
}

/* ----- chat-header layout polish ----- */
.chat-header {
  border-bottom: 1px solid var(--stroke-soft);
  padding-bottom: 14px;
  margin-bottom: 14px;
}
.chat-header h2 { font-size: 18px; font-weight: 700; margin: 0; }
.chat-header .muted { font-size: 12.5px; margin-top: 2px; }

/* ----- modal v2 ----- */
.modal-card {
  border: 1px solid var(--stroke-soft);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.05), transparent 60px),
    var(--surface);
}
.modal-card h3 { font-size: 18px; font-weight: 700; }

/* ---------- v10 quick fixes ---------- */

/* Hide the "Claude API" mode badge unless it's in stub/local mode (warning). */
#modeBadge { display: none; }
#modeBadge.stub-warning { display: inline-flex; background: linear-gradient(135deg, #f59e0b, #ea580c); }

/* Pin the footer to the bottom of the viewport on short pages. */
html, body { min-height: 100%; }
body { display: flex; flex-direction: column; }
main#app { flex: 1 0 auto; }
.app-footer { flex: 0 0 auto; margin-top: auto; }

/* The user/email + lang dropdown were squashing — give them breathing room. */
.user-area { gap: 14px; }
.user-area #userBadge { white-space: nowrap; }

/* ---------- v10 fixes round 2 ---------- */

/* 1) Logo emoji was being clipped by the gradient text-fill on .brand.
   Restore its native rendering (emoji), keep the gradient only on the text. */
.brand .logo {
  -webkit-background-clip: initial; background-clip: initial;
  -webkit-text-fill-color: initial; color: initial;
  background: none;
  display: inline-flex; align-items: center;
  /* Slight glow stays via the existing drop-shadow filter rule */
}

/* 2) Log out button was wrapping to two lines. Give it firm sizing. */
#logoutBtn {
  white-space: nowrap;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 9px;
}

/* 3) <select> option text was black-on-black in dark themes (some
   browsers ignore the parent text color for <option>). Force it. */
select { color: var(--text); }
select option {
  background: var(--surface);
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  select option {
    background: #1f2937;
    color: #e6e8ec;
  }
}

/* Also make the topbar `.user-area` group don't squish on narrow widths. */
.topbar { gap: 12px; }
.user-area { flex-wrap: nowrap; }

/* ---------- RTL polish (Arabic / Farsi / Hebrew / Urdu) ---------- */
html[dir="rtl"] body { font-family: "Vazirmatn", "IBM Plex Sans Arabic", "Geeza Pro", "Tahoma", sans-serif; }

/* Sidebar active indicator bar flips side. */
html[dir="rtl"] .case-list li.active::before { left: auto; right: -4px; }

/* Sidebar hover translate flips direction. */
html[dir="rtl"] .case-list li:hover { transform: translateX(-3px); }

/* Attachment items & similar rows reverse so the ✕ button stays on the "end". */
html[dir="rtl"] .attachment-item,
html[dir="rtl"] .chat-header,
html[dir="rtl"] .reply,
html[dir="rtl"] .row { direction: rtl; }

/* Markdown body keeps natural reading direction for the content language —
   but since most contracts/output are in their jurisdiction's language, this
   stays LTR by default. */
.md, .messages .bubble { direction: inherit; text-align: start; }

/* ---------- output-language banner ---------- */
.lang-banner {
  margin: 10px 0 14px 0;
  padding: 10px 14px;
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(99,102,241,0.10), rgba(14,165,233,0.10));
  border: 1px solid rgba(99,102,241,0.25);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.lang-banner strong { color: #c7d2fe; }

/* ---------- v10 fixes round 3 ---------- */

/* Inputs were showing browser-default black text on the dark theme. Force
   the theme text colour on every form control. */
input, textarea, select, button {
  color: var(--text);
}
input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
/* Autofill (Safari/Chrome) was repainting fields white-on-white. Override. */
input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
  -webkit-text-fill-color: var(--text) !important;
  -webkit-box-shadow: 0 0 0 1000px rgba(255,255,255,0.04) inset !important;
  caret-color: var(--text);
}
/* Disabled / readonly fields. */
input:disabled, textarea:disabled, select:disabled {
  color: var(--muted);
  background: rgba(255,255,255,0.02);
  cursor: not-allowed;
}

/* ============================================================
   CLARAVEN brand — logo + hero
   ============================================================ */

/* ---- logo ---- */
.brand { display: flex; align-items: center; height: 36px; text-decoration: none; }
.brand .logo-img { height: 36px; width: auto; display: block; }
.brand:hover .logo-img { filter: drop-shadow(0 4px 14px rgba(99,102,241,0.5)); transition: filter 0.2s var(--easing); }

/* ---- auth screen: two-column hero + sign-in card ---- */
.auth-screen-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 56px;
  align-items: center;
  max-width: 1180px;
  margin: 32px auto;
  padding: 0 28px;
}
@media (max-width: 900px) {
  .auth-screen-grid { grid-template-columns: 1fr; gap: 24px; }
}

.hero { padding: 8px 0; }
.hero-eyebrow {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(99,102,241,0.10);
  border: 1px solid rgba(99,102,241,0.25);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #c7d2fe;
  margin-bottom: 18px;
}
.hero-title {
  font-size: 44px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
}
.hero-title-grad {
  display: block;
  background: linear-gradient(135deg, #818cf8 0%, #60a5fa 50%, #22d3ee 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.hero-lede {
  font-size: 17px;
  line-height: 1.55;
  color: var(--text);
  margin: 0 0 24px;
  max-width: 56ch;
}
.hero-lede strong { color: #fff; }

.hero-feats {
  list-style: none;
  padding: 0;
  margin: 0 0 22px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.hero-feats li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--stroke-soft);
  font-size: 14px;
  line-height: 1.45;
}
.hero-feats .ico {
  font-size: 18px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}
.hero-disclaimer {
  font-size: 12px;
  line-height: 1.5;
  padding-top: 14px;
  border-top: 1px solid var(--stroke-soft);
}

/* On wide screens, the sign-in card stays compact + sticky */
@media (min-width: 901px) {
  .auth-screen-grid .auth-card {
    max-width: 420px;
    width: 100%;
    align-self: start;
    position: sticky;
    top: 80px;
  }
}

/* ============================================================
   PRICING MODAL  (country-aware prices, language-aware copy)
   ============================================================ */
.pricing-modal {
  width: min(1040px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 26px 28px 30px;
}
.pricing-head { text-align: center; margin-bottom: 6px; position: relative; }
.pricing-head h2 { margin: 0 0 6px; font-size: 26px; }
.pricing-head p { margin: 0 auto; color: var(--muted); max-width: 620px; }
.pricing-close {
  position: absolute; top: -4px; inset-inline-end: -4px;
  width: 34px; height: 34px; border-radius: 8px;
  border: none; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.pricing-close:hover { background: var(--pill-bg); color: var(--text); }
.pricing-toolbar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  flex-wrap: wrap; margin: 16px 0 22px;
}
.pricing-toolbar .loc-note { color: var(--muted); font-size: 13px; }
.pricing-toolbar select {
  padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.tier-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}
@media (max-width: 760px) { .tier-grid { grid-template-columns: 1fr; } }
.tier-card {
  border: 1px solid var(--border); border-radius: 14px;
  padding: 22px 20px; background: var(--surface);
  display: flex; flex-direction: column; position: relative;
}
.tier-card.featured {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), 0 18px 40px rgba(37,99,235,.18);
}
.tier-badge {
  position: absolute; top: -11px; inset-inline-start: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff; font-size: 11px; font-weight: 700;
  letter-spacing: .3px; padding: 3px 12px; border-radius: 999px; white-space: nowrap;
}
.tier-name { font-size: 18px; font-weight: 700; margin: 2px 0 2px; }
.tier-tagline { color: var(--muted); font-size: 13px; min-height: 34px; margin-bottom: 12px; }
.tier-price { font-size: 34px; font-weight: 800; line-height: 1; }
.tier-price .per { font-size: 14px; font-weight: 500; color: var(--muted); }
.tier-feats { list-style: none; padding: 0; margin: 16px 0 20px; display: grid; gap: 9px; }
.tier-feats li { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; }
.tier-feats li::before { content: "✓"; color: var(--success); font-weight: 800; flex: 0 0 auto; }
.tier-card .tier-cta { margin-top: auto; width: 100%; }
.tier-card.featured .tier-cta { background: var(--primary); color: #fff; border-color: var(--primary); }
.pricing-vat { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }
[dir="rtl"] .tier-feats li { flex-direction: row; }

/* topbar pricing button */
#pricingNavBtn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
#pricingNavBtn:hover { border-color: var(--primary); color: var(--primary); }

/* ---- billing badge (topbar) + trial-blocked banner ---- */
.billing-badge {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--pill-bg); color: var(--pill-fg); white-space: nowrap;
  border: 1px solid transparent;
}
.billing-badge.warn { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.pricing-blocked {
  display: flex; flex-direction: column; gap: 2px; text-align: center;
  background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
  border-radius: 10px; padding: 12px 16px; margin: 4px auto 18px; max-width: 560px;
}
.pricing-blocked strong { font-size: 15px; }
.pricing-blocked span { font-size: 13px; }

/* ---- settings modal ---- */
#settingsBtn {
  background: transparent; border: none; color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 17px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease, color .15s ease;
}
#settingsBtn:hover { background: var(--pill-bg); color: var(--text); }
.set-section {
  text-align: left; border-top: 1px solid var(--border); padding-top: 16px; margin-top: 18px;
}
.set-section h3 { margin: 0 0 12px; font-size: 15px; }
.set-section label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.set-section input {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px;
}
.set-btn { padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.set-btn.danger { color: var(--danger); border: 1px solid var(--danger); background: transparent; }
.set-btn.danger:hover { background: var(--danger); color: #fff; }

/* ============================================================
   Auth screen polish — readable link, animated aurora, glass card
   (added 2026-06-15)
   ============================================================ */

/* Readable "Forgot password?" link in both light and dark */
#forgotLink {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
}
#forgotLink:hover { filter: brightness(1.12); }
@media (prefers-color-scheme: dark) {
  #forgotLink { color: #ffffff; opacity: 0.85; }
  #forgotLink:hover { opacity: 1; filter: none; }
}

/* Animated gradient "aurora" glow behind the whole auth screen */
.auth-screen-grid::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(38% 50% at 14% 18%, rgba(99,102,241,0.30), transparent 70%),
    radial-gradient(42% 52% at 88% 26%, rgba(34,211,238,0.18), transparent 72%),
    radial-gradient(52% 62% at 62% 98%, rgba(37,99,235,0.24), transparent 72%);
  animation: aurora-drift 22s ease-in-out infinite alternate;
}
@keyframes aurora-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(0, -24px, 0) scale(1.07); }
}
@media (prefers-reduced-motion: reduce) {
  .auth-screen-grid::before { animation: none; }
}

/* Glassmorphic sign-in card floating over the aurora */
.auth-screen-grid .auth-card {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
@media (prefers-color-scheme: dark) {
  .auth-screen-grid .auth-card {
    background: rgba(20, 24, 33, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.10);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  }
  .auth-screen-grid .hero-feats li { background: rgba(255, 255, 255, 0.05); }
}

/* First-run onboarding guide */
.guide-card { width: min(540px, 94vw); }
.guide-steps { list-style: none; padding: 0; margin: 16px 0 18px; display: grid; gap: 14px; }
.guide-steps li { display: flex; gap: 12px; align-items: flex-start; }
.guide-ico {
  font-size: 22px; flex-shrink: 0; width: 34px; height: 34px;
  display: grid; place-items: center; border-radius: 10px;
  background: rgba(99,102,241,0.12); border: 1px solid rgba(99,102,241,0.22);
}
.guide-steps strong { display: block; margin-bottom: 2px; font-size: 15px; }
.guide-steps p { margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.45; }
