/* ==========================================================
   Boilerplate — design tokens
   Black & white, one metallic-gold accent. Outfit for everything.
   ========================================================== */
:root {
  --ink: #000000;
  --paper: #FFFFFF;
  --canvas: #F6F5F2;
  --line: #E4E1DA;
  --line-strong: #CFCAC0;
  --muted: #6E6A63;
  --gold: #C9A868;
  --gold-soft: #F4ECD9;
  --gold-deep: #9E7B3B;
  --metal: linear-gradient(135deg, #9E7B3B 0%, #E8D3A6 42%, #C9A868 58%, #F3E6C7 78%, #9E7B3B 100%);
  --danger: #B42318;
  --danger-soft: #FCEBE9;
  --ok: #1E7B4E;
  --ok-soft: #E6F4EC;
  --warn: #8A5A00;
  --warn-soft: #FFF3D6;
  --radius: 6px;
  --sidebar: 248px;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--canvas);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
.lede { color: var(--muted); max-width: 60ch; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 2px; }

/* ---------- App shell (sidebar layout) ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: block; margin: 0 0 1.5rem; }
.brand img { width: 150px; height: auto; display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  position: relative;
  text-decoration: none;
  padding: 0.55rem 0.75rem 0.55rem 1rem;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 500;
}
.nav a:hover { color: var(--ink); background: var(--canvas); }
.nav a.active { color: var(--ink); background: var(--gold-soft); }
.nav a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 3px;
  background: var(--metal);
}
.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line); }
.who { display: flex; flex-direction: column; margin-bottom: 0.5rem; }
.who span { color: var(--muted); font-size: 0.8125rem; }
.link-quiet { color: var(--muted); font-size: 0.875rem; }

.content { flex: 1; min-width: 0; padding: 2rem 2.5rem 3rem; max-width: 1180px; }
.foot {
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 3rem; padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 0.8125rem;
}
.foot img { width: 72px; height: auto; }

/* ---------- Page header with the metallic rule ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem;
  margin-bottom: 1.75rem;
}
.page-head h1 { position: relative; display: inline-block; padding-bottom: 0.6rem; }
.page-head h1::after {
  content: '';
  position: absolute; left: 0; bottom: 0;
  width: 56px; height: 3px; border-radius: 3px;
  background: var(--metal);
}
.page-head .lede { margin: 0.5rem 0 0; }
.crumbs { font-size: 0.875rem; color: var(--muted); margin-bottom: 0.5rem; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

/* ---------- Panels & grids ---------- */
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.panel-head p { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.5rem; }
.stat strong { display: block; font-size: 2rem; font-weight: 600; line-height: 1.1; }
.stat span { color: var(--muted); }
.stat a { text-decoration: none; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th, .table td { text-align: left; padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-weight: 500; color: var(--muted); font-size: 0.8125rem; }
.table tr:last-child td { border-bottom: 0; }
.table a { text-decoration: none; font-weight: 500; }
.table a:hover { text-decoration: underline; }
.table .actions { text-align: right; white-space: nowrap; }
.empty { color: var(--muted); padding: 1rem 0; }
.empty a { font-weight: 500; }

/* ---------- Chips ---------- */
.chip {
  display: inline-block; padding: 0.15rem 0.55rem; margin: 0 0.25rem 0.25rem 0;
  border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: 0.8125rem; background: var(--paper);
}
.chip.gold { border-color: var(--gold); background: var(--gold-soft); }
.chip.off { color: var(--muted); border-style: dashed; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 0.9rem; }
.form.inline { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.875rem; color: var(--muted); }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=number], .field input[type=search], .field select, .field textarea {
  font: inherit; padding: 0.55rem 0.7rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
}
.field textarea { resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--gold-deep); outline: none; box-shadow: 0 0 0 3px var(--gold-soft); }
.check { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9375rem; }
.check input { width: 16px; height: 16px; accent-color: var(--ink); }
.help { font-size: 0.8125rem; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 500; font-size: 0.9375rem;
  padding: 0.55rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--ink); background: var(--ink); color: var(--paper);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #222; border-color: #222; }
.btn-gold { background: var(--metal); border-color: var(--gold-deep); color: var(--ink); }
.btn-gold:hover { filter: brightness(1.04); background: var(--metal); border-color: var(--gold-deep); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-quiet:hover { background: var(--canvas); border-color: var(--line-strong); }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; padding: 0.35rem 0.5rem; font-size: 0.875rem; }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.875rem; }
form.inline-form { display: inline; }

/* ---------- Flash messages ---------- */
.flashes { margin-bottom: 1.25rem; display: grid; gap: 0.5rem; }
.flash {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem 0.9rem; border-radius: var(--radius); border: 1px solid;
  font-size: 0.9375rem;
}
.flash.success { background: var(--ok-soft); border-color: #BFE3CD; color: var(--ok); }
.flash.error { background: var(--danger-soft); border-color: #F1C2BD; color: var(--danger); }
.flash.warning { background: var(--warn-soft); border-color: #F0DCA6; color: var(--warn); }
.flash-x { background: none; border: 0; font-size: 1.1rem; cursor: pointer; color: inherit; line-height: 1; }

/* ---------- Approval chain ---------- */
.chain { display: grid; gap: 0.75rem; }
.chain-level {
  display: grid; grid-template-columns: 44px 1fr; gap: 1rem; align-items: start;
  padding: 0.9rem 0; border-top: 1px solid var(--line);
}
.chain-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.chain-level:first-child { border-top: 0; }
.chain-order {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--metal); color: var(--ink); font-weight: 600;
}
.chain-level h3 { margin-bottom: 0.25rem; }
.chain-approvers { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; margin-bottom: 0.5rem; }
.chain-level .form.inline { display: flex; gap: 0.5rem; align-items: center; }
.chain-level .form.inline .field { flex: 1; min-width: 0; }
.chain-level .form.inline select { width: 100%; }
/* Approval progress states: done = signed off, now = waiting on this level */
.chain-order.done { background: var(--ok-soft); color: var(--ok); border: 1px solid #BFE3CD; }
.chain-order.now { background: var(--ink); color: var(--paper); }

/* ---------- Pending-approvals badge + dashboard callout ---------- */
.count-bubble {
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px;
  background: var(--metal);
  color: var(--ink); font-size: 0.75rem; font-weight: 700; line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 1px 2px rgba(0, 0, 0, 0.25);
  vertical-align: middle;
}
.count-bubble.big { min-width: 36px; height: 36px; font-size: 1.05rem; }
.callout-gold { border-color: var(--gold); background: var(--gold-soft); }
.callout-row { display: flex; align-items: center; gap: 1rem; }
.callout-row > div { flex: 1; }
.callout-row h2 { margin-bottom: 0.15rem; }

/* Multi-department checkbox picker */
.check-grid {
  display: grid; gap: 0.4rem;
  max-height: 200px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 0.6rem 0.75rem;
}
.check-grid .check { display: flex; align-items: center; gap: 0.5rem; }

/* ---------- User detail: stat tiles + activity timeline ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}
.stat {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 0.75rem 0.9rem;
}
.stat .n { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.timeline { display: grid; }
.timeline-row {
  display: grid; grid-template-columns: 150px 110px 1fr;
  gap: 0.75rem; align-items: baseline;
  padding: 0.55rem 0; border-top: 1px solid var(--line);
}
.timeline-row:first-child { border-top: 0; }
@media (max-width: 720px) {
  .timeline-row { grid-template-columns: 1fr; gap: 0.15rem; }
}

/* ---------- Letter builder ---------- */
.fleuron {
  background: var(--metal);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--gold-deep);
  font-size: 1.05em; margin-right: 0.15rem;
}
.builder-grid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .builder-grid { grid-template-columns: 1fr; } }
.result-card {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 0.7rem 0.85rem; margin-bottom: 0.6rem;
  cursor: grab; background: var(--paper);
}
.result-card:active { cursor: grabbing; }
.result-card .snippet { margin: 0.35rem 0; }
.letter-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.letter-item {
  border: 1px solid var(--line); border-left: 3px solid var(--gold, #C9A868);
  border-radius: 8px; padding: 0.7rem 0.85rem; background: var(--paper);
}
.letter-item.dragging { opacity: 0.45; }
.letter-item-head { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.letter-item-actions { margin-left: auto; display: flex; gap: 0.3rem; }
.drag-handle { cursor: grab; letter-spacing: -2px; color: var(--line-strong, #999); user-select: none; }

/* ---------- Centered auth / error pages ---------- */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 2rem; }
.card {
  width: 100%; max-width: 400px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 2rem 2rem 1.75rem;
}
.card .logo { width: 170px; height: auto; display: block; margin: 0 auto 1.25rem; }
.card h1 { font-size: 1.375rem; padding-bottom: 0.6rem; margin-bottom: 1rem; position: relative; }
.card h1::after { content: ''; position: absolute; left: 0; bottom: 0; width: 48px; height: 3px; border-radius: 3px; background: var(--metal); }
.card .form { margin-top: 0.5rem; }
.card .btn { width: 100%; margin-top: 0.25rem; }
.card .aside { margin-top: 1.25rem; font-size: 0.875rem; color: var(--muted); }
.card .aside a { color: var(--ink); }
.msg { margin-top: 1rem; padding: 0.7rem 0.9rem; border-radius: var(--radius); font-size: 0.9375rem; display: none; border: 1px solid; }
.msg.show { display: block; }
.msg.success { background: var(--ok-soft); border-color: #BFE3CD; color: var(--ok); }
.msg.error { background: var(--danger-soft); border-color: #F1C2BD; color: var(--danger); }
.msg.info { background: var(--gold-soft); border-color: var(--gold); color: var(--ink); }
.code-input { font-size: 1.5rem; letter-spacing: 0.35em; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex: none; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); padding: 1rem 1.25rem; }
  .brand { margin-bottom: 0.75rem; }
  .brand img { width: 120px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a.active::before { display: none; }
  .sidebar-foot { display: none; }
  .content { padding: 1.5rem 1.25rem 2.5rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
