/* ============================================================
   EditorHQ Design System v0 — "Paper & Ink"
   Phase 0 foundation for the desk + all future rebuilt surfaces.
   Tokens are INHERITED from the existing portal (site/index.html):
   paper #f5f1e5 · ink #2a2620 · amber #b85c1a · hairline borders
   Spline Sans / IBM Plex Mono / Noto Sans Bengali / Architects Daughter
   Rule: new surfaces consume these tokens. Never hardcode hex.
   ============================================================ */

:root {
  /* ---- Color · surfaces ---- */
  --paper: #f5f1e5;
  --paper-raise: #fbf9f2;
  --paper-sink: #efe9da;
  --paper-deep: #e9e2cf;
  --paper-edge: #d5cdb8;

  /* ---- Color · ink ---- */
  --ink: #2a2620;
  --ink-deep: #1a1814;
  --ink-soft: #6b6358;
  --ink-mute: #9a9384;

  /* ---- Color · brand & semantics ---- */
  --amber: #b85c1a;
  --amber-deep: #9a4a12;
  --amber-wash: rgba(184, 92, 26, 0.09);
  --red: #b4232d;
  --red-wash: rgba(180, 35, 45, 0.08);
  --green: #1e7f4f;
  --green-wash: rgba(30, 127, 79, 0.10);
  --blue: #3b5b92;
  --blue-wash: rgba(59, 91, 146, 0.10);
  --ok: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;

  /* ---- Color · lines ---- */
  --hairline: rgba(42, 38, 32, 0.18);
  --hairline-strong: rgba(42, 38, 32, 0.34);
  --hairline-soft: rgba(42, 38, 32, 0.09);

  /* ---- Type ---- */
  --ff-body: 'Spline Sans', system-ui, -apple-system, sans-serif;
  --ff-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;
  --ff-bn: 'Noto Sans Bengali', 'Spline Sans', sans-serif;
  --ff-hand: 'Architects Daughter', cursive;

  --text-2xs: 0.6875rem;   /* 11px — meta, timestamps */
  --text-xs: 0.75rem;      /* 12px — labels, badges */
  --text-sm: 0.8125rem;    /* 13px — secondary body */
  --text-md: 0.875rem;     /* 14px — body default */
  --text-base: 0.9375rem;  /* 15px — chat body */
  --text-lg: 1.0625rem;    /* 17px — window titles */
  --text-xl: 1.375rem;     /* 22px — page/section heads */
  --text-2xl: 1.75rem;     /* 28px — hero/brand */

  /* ---- Space (4px base) ---- */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px;

  /* ---- Radius ---- */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-full: 999px;

  /* ---- Shadow (soft, warm — never heavy) ---- */
  --sh-win: 0 1px 2px rgba(26, 24, 20, 0.06), 0 12px 32px -8px rgba(26, 24, 20, 0.22);
  --sh-pop: 0 2px 6px rgba(26, 24, 20, 0.08), 0 16px 40px -12px rgba(26, 24, 20, 0.28);
  --sh-sub: 0 1px 2px rgba(26, 24, 20, 0.05);

  /* ---- Motion ---- */
  --t-fast: 120ms cubic-bezier(0.3, 0, 0.2, 1);
  --t-med: 200ms cubic-bezier(0.3, 0, 0.2, 1);
  --t-pop: 260ms cubic-bezier(0.2, 0, 0.1, 1);

  /* ---- Z scale ---- */
  --z-wall: 0; --z-desk: 1; --z-dock: 40; --z-top: 50;
  --z-win: 20; --z-win-focus: 30; --z-menu: 60; --z-toast: 80;

  /* ---- Layout ---- */
  --topbar-h: 56px;
  --dock-h: 60px;
  --tap: 44px; /* minimum touch target */
}

/* ---- Base ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--ff-body);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:where(bn), :where([lang="bn"]) { font-family: var(--ff-bn); }
::selection { background: var(--amber-wash); color: var(--ink-deep); }

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

/* Scrollbars — thin, warm */
* { scrollbar-width: thin; scrollbar-color: var(--paper-edge) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--paper-edge); border-radius: var(--r-full); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---- Buttons (default / hover / active / disabled) ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 36px; padding: 0 var(--s4);
  font: 500 var(--text-md)/1 var(--ff-body);
  color: var(--ink); background: var(--paper-raise);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  cursor: pointer; user-select: none;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--paper-sink); border-color: var(--hairline-strong); }
.btn:active { transform: translateY(1px); background: var(--paper-deep); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn--primary {
  color: #fff; background: var(--amber); border-color: var(--amber-deep);
}
.btn--primary:hover { background: var(--amber-deep); }
.btn--primary:active { background: #863f0e; }

.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--amber-wash); }
.btn--ghost:active { background: rgba(184, 92, 26, 0.16); }

.btn--danger { color: var(--red); border-color: rgba(180, 35, 45, 0.4); background: transparent; }
.btn--danger:hover { background: var(--red-wash); }

.btn--icon {
  width: 36px; min-height: 36px; padding: 0;
  border-radius: var(--r-sm);
}
.btn--icon svg { width: 18px; height: 18px; }

/* ---- Inputs ---- */
.input, .textarea, .select {
  width: 100%; min-height: 38px; padding: 7px var(--s3);
  font: 400 var(--text-md)/1.4 var(--ff-body);
  color: var(--ink); background: var(--paper-raise);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-mute); }
.input:hover, .textarea:hover { border-color: var(--ink-soft); }
.input:focus, .textarea:focus {
  outline: none; border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-wash);
}
.input:disabled { opacity: 0.5; cursor: not-allowed; }
.textarea { resize: vertical; min-height: 72px; }
.input[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px var(--red-wash); }

.field { display: grid; gap: 6px; }
.field > label { font: 600 var(--text-xs)/1 var(--ff-body); letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft); }
.field .hint { font-size: var(--text-xs); color: var(--ink-mute); }
.field .err { font-size: var(--text-xs); color: var(--bad); display: none; }
.field.has-err .err { display: block; }

/* ---- Checkbox ---- */
.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; }
.check input {
  appearance: none; width: 18px; height: 18px; margin: 0;
  border: 1.5px solid var(--hairline-strong); border-radius: 5px;
  background: var(--paper-raise); cursor: pointer;
  display: grid; place-content: center;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.check input:hover { border-color: var(--amber); }
.check input:checked { background: var(--amber); border-color: var(--amber-deep); }
.check input:checked::after {
  content: ""; width: 10px; height: 10px;
  background: var(--paper-raise);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.check input:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---- Cards / panels ---- */
.card {
  background: var(--paper-raise);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  box-shadow: var(--sh-sub);
}

/* ---- Badges & chips ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: var(--r-full);
  font: 600 var(--text-xs)/1.6 var(--ff-body);
  color: var(--ink-soft); background: var(--paper-sink);
  border: 1px solid var(--hairline-soft);
  white-space: nowrap;
}
.badge--running { color: var(--blue); background: var(--blue-wash); border-color: transparent; }
.badge--pending { color: var(--amber-deep); background: var(--amber-wash); border-color: transparent; }
.badge--done    { color: var(--green); background: var(--green-wash); border-color: transparent; }
.badge--blocked { color: var(--red); background: var(--red-wash); border-color: transparent; }

.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--running .dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---- Tooltips / toasts ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-h) + 16px);
  transform: translateX(-50%) translateY(8px);
  padding: 10px var(--s4); border-radius: var(--r-md);
  font-size: var(--text-md); color: var(--ink);
  background: var(--ink-deep); color: var(--paper);
  box-shadow: var(--sh-pop);
  opacity: 0; pointer-events: none; z-index: var(--z-toast);
  transition: opacity var(--t-med), transform var(--t-med);
  max-width: min(92vw, 420px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Skeleton (loading) ---- */
.skel {
  background: linear-gradient(90deg, var(--paper-sink) 25%, var(--paper-deep) 50%, var(--paper-sink) 75%);
  background-size: 200% 100%; border-radius: var(--r-sm);
  animation: skel 1.2s linear infinite; color: transparent;
}
@keyframes skel { to { background-position: -200% 0; } }

/* ---- Utility ---- */
[hidden] { display: none !important; }
.mono { font-family: var(--ff-mono); }
.bn { font-family: var(--ff-bn); }
.muted { color: var(--ink-mute); }
.soft { color: var(--ink-soft); }
.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;
}
