/* Case Hub — shared design tokens, centered login card, dashboard shell.
   claude.ai/downloads-inspired: warm cream, minimal, centered. */

:root {
  --bg:        #faf9f5;
  --surface:   #ffffff;
  --surface-2: #f4f2ec;
  --border:    #e8e4db;
  --border-hi: #d9d3c6;
  --text:      #191919;
  --muted:     #6b6b6b;
  --accent:    #c96442;
  --accent-hi: #ba5a3c;
  --success:   #1f7a1f;
  --danger:    #b91c1c;
  --focus:     rgba(201, 100, 66, .22);

  /* Comment-card role tints (light bg + left-edge accent) */
  --admin:     #c96442;
  --admin-bg:  #fbeade;
  --admin-bd:  #f0c9ae;
  --user:      #2b6cff;
  --user-bg:   #e4ecff;
  --user-bd:   #bed0f6;
  --caretaker: #3b82f6;
  --solicitor: #a855f7;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font: 14.5px/1.55 ui-sans-serif, -apple-system, BlinkMacSystemFont,
    "Inter", "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }

/* --- Login / verify / profile ----------------------------------------- */

body.auth {
  display: flex; min-height: 100vh; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.auth .wrap {
  width: 100%; max-width: 440px; display: flex; flex-direction: column;
  align-items: center; gap: 24px;
}
.wordmark { font-size: clamp(22px, 5vw, 28px); font-weight: 700;
  letter-spacing: -.025em; color: var(--text); text-align: center;
  margin: 0; white-space: nowrap; }
.wordmark .dot { color: var(--accent); }
.tagline { color: var(--muted); font-size: 14px; text-align: center;
  margin: -16px 0 0; }

.card {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 28px 28px 24px; box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.card h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.card p.sub { color: var(--muted); margin: 0 0 18px; font-size: 13.5px; }

label.field { display: block; margin-bottom: 14px; }
label.field > .lbl { font-size: 12.5px; color: var(--muted); font-weight: 600;
  margin-bottom: 6px; display: block; }
input[type="email"], input[type="text"], input.code {
  width: 100%; padding: 11px 13px;
  background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14.5px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
input[disabled] { background: #f7f4ec; color: var(--muted); cursor: not-allowed; }
input.code {
  font-size: 22px; letter-spacing: 10px; text-align: center;
  font-variant-numeric: tabular-nums; font-weight: 600;
}

.row { display: flex; gap: 8px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border: 0; border-radius: 9px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  cursor: pointer; transition: background .15s;
}
.btn:hover:not(:disabled) { background: var(--accent-hi); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text);
  border: 1px solid var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.full { width: 100%; }

.hint { color: var(--muted); font-size: 12.5px; margin-top: 12px; text-align: center; }
.err  { color: var(--danger); font-size: 13px; margin-top: 10px; }
.ok   { color: var(--success); font-size: 13px; margin-top: 10px; }

.link-btn { background: transparent; border: 0; color: var(--accent);
  cursor: pointer; padding: 0; font: inherit; }
.link-btn:hover { text-decoration: underline; }

/* --- Dashboard shell --------------------------------------------------- */

body.app { display: flex; min-height: 100vh; overflow: hidden; }
#sidebar {
  width: 260px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100vh; overflow: auto;
}
#sidebar .brand { padding: 18px 20px; font-size: 15px; font-weight: 700;
  letter-spacing: -.015em; border-bottom: 1px solid var(--border);
  line-height: 1.3; }
#sidebar .brand .dot { color: var(--accent); }
#sidebar .who { padding: 12px 20px; font-size: 12.5px; color: var(--muted);
  border-bottom: 1px solid var(--border); }
#sidebar .who b { color: var(--text); display: block; font-size: 13.5px;
  font-weight: 600; margin-bottom: 2px; }
#sidebar .who .role { display: inline-block; font-size: 10.5px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px; text-transform: uppercase;
  letter-spacing: .06em; margin-top: 4px;
  background: var(--admin-bg); color: var(--admin); }
#sidebar .who .role.user { background: var(--user-bg); color: var(--user); }

#sidebar .section { padding: 14px 10px 6px; }
#sidebar .section-title { font-size: 11px; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted); font-weight: 700;
  padding: 0 10px 6px; }
#sidebar a.nav, #sidebar button.nav {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 12px; border-radius: 7px; color: var(--text);
  background: transparent; border: 0; cursor: pointer; text-align: left;
  font-size: 13.5px; text-decoration: none; font-weight: 500;
}
#sidebar a.nav:hover, #sidebar button.nav:hover { background: var(--surface-2); }
#sidebar a.nav.active { background: var(--surface-2); font-weight: 600; }
#sidebar .nav-sub { padding-left: 28px; }
#sidebar .nav-sub a.nav { font-size: 13px; padding: 6px 10px; color: var(--muted); }
#sidebar .nav-sub a.nav.active { color: var(--text); }

/* --- Main pane --------------------------------------------------------- */

#main { flex: 1; overflow: auto; height: 100vh; background: var(--bg); }
.pane { padding: 28px clamp(24px, 4vw, 56px) 80px; }
.pane > h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em;
  margin: 0 0 4px; }
.pane > .sub { color: var(--muted); margin: 0 0 28px; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px 24px; margin-bottom: 18px;
}
.panel h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border);
  margin: -4px -4px 20px; padding: 0 4px; }
.tabs .tab { padding: 10px 16px; border: 0; background: transparent;
  color: var(--muted); font-weight: 600; cursor: pointer; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { color: var(--text); border-bottom-color: var(--accent); }

.iframe-wrap { width: 100%; height: calc(100vh - 220px); min-height: 520px;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.iframe-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }

/* --- Reference documents ---------------------------------------------- */

.doc-list { display: grid; gap: 10px; }
.doc {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 14px;
  align-items: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
}
.doc .ico { display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; background: #fbeade; color: var(--accent);
  border-radius: 8px; font-size: 18px; }
.doc .meta .fn { font-weight: 600; }
.doc .meta .sz { color: var(--muted); font-size: 12px; }
.doc .actions { display: flex; gap: 6px; }
.doc .actions .btn { padding: 7px 12px; font-size: 12.5px; }

.uploader { border: 2px dashed var(--border-hi); border-radius: 10px;
  padding: 20px; text-align: center; color: var(--muted);
  transition: border-color .15s, background .15s; cursor: pointer; }
.uploader.drag { border-color: var(--accent); background: #fbf2ec; color: var(--text); }

/* --- Reference Documents · section cards ----------------------------- */
#sections-root { display: flex; flex-direction: column; gap: 14px; }

.section-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px 22px;
  transition: box-shadow .15s, transform .05s;
  position: relative;
}
.section-card.dragging    { opacity: .4; }
.section-card.drop-target-above { box-shadow: inset 0 3px 0 0 var(--accent); }
.section-card.drop-target-below { box-shadow: inset 0 -3px 0 0 var(--accent); }
.section-card.unsectioned { background: var(--surface-2); border-style: dashed; }

.section-card .sec-head {
  display: flex; align-items: center; gap: 10px;
}
.section-card .sec-title {
  flex: 1; font-size: 17px; font-weight: 700; letter-spacing: -.005em;
}
.section-card .sec-body {
  margin: 10px 0 14px; padding: 12px 14px;
  background: var(--surface-2); border-radius: 8px;
  font-size: 14px; line-height: 1.6; color: var(--text);
}
.section-card .sec-body:empty { display: none; }
.section-card .sec-body b,
.section-card .sec-body strong { font-weight: 700; }
.section-card .sec-body u { text-decoration: underline; }
.section-card .sec-body i,
.section-card .sec-body em { font-style: italic; }
.section-card .sec-body p  { margin: 0 0 8px; }
.section-card .sec-body p:last-child { margin-bottom: 0; }

.section-card .sec-empty {
  color: var(--muted); font-size: 13px; padding: 12px 0;
  font-style: italic;
}

.section-card .sec-controls {
  display: flex; gap: 4px; align-items: center;
  opacity: 0; transition: opacity .15s;
}
.section-card:hover .sec-controls { opacity: 1; }

.section-card .drag-handle {
  cursor: grab; color: var(--muted); padding: 4px 6px;
  user-select: none;
}
.section-card .drag-handle:active { cursor: grabbing; }

/* Smaller icon-only button variant for inline controls */
.btn.small { padding: 5px 8px; font-size: 12px; font-weight: 500; }
.btn.ghost.small { border: 1px solid transparent; }
.btn.ghost.small:hover { border-color: var(--border); }

/* Doc rows nest inside section cards — tighter spacing than the old
   standalone .doc-list */
.section-card .doc-list { gap: 8px; }
.section-card .doc {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* --- Members list ----------------------------------------------------- */
.member-row { display: grid; grid-template-columns: 1fr auto; gap: 10px;
  padding: 10px 12px; border-radius: 8px; }
.member-row:hover { background: var(--surface-2); }
.member-row .who { display: flex; gap: 10px; align-items: center; }
.member-row .nick { font-weight: 600; }
.member-row .em { color: var(--muted); font-size: 12.5px; }
.member-row .role-chip { font-size: 10.5px; font-weight: 700; padding: 2px 7px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .05em;
  background: var(--user-bg); color: var(--user); }
.member-row .role-chip.superadmin { background: var(--admin-bg); color: var(--admin); }
.member-row .pending { background: var(--surface-2); color: var(--muted);
  border: 1px dashed var(--border-hi); }

/* --- Modal / dialog --------------------------------------------------- */
#modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 100; display: none; align-items: center; justify-content: center;
  padding: 20px; }
#modal-bg.open { display: flex; }
.modal { background: var(--surface); border-radius: 14px;
  padding: 26px 28px; width: 100%; max-width: min(580px, 95vw);
  max-height: 92vh; overflow: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { color: var(--muted); margin: 0 0 16px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 14px; }

/* --- Toast ----------------------------------------------------------- */
#toast { position: fixed; bottom: max(24px, env(safe-area-inset-bottom, 24px));
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; transition: all .2s; z-index: 200;
  pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Modal — dvh-aware on mobile so soft keyboards don't clip ------- */
.modal { max-height: min(92vh, calc(100dvh - 20px)); }

/* ===========================================================================
   Mobile — off-canvas sidebar drawer + responsive polish
   All rules below are media-gated; desktop is untouched.
   =========================================================================== */

/* Hamburger + backdrop are injected by app.js; hidden on desktop. */
#hamburger, #sidebar-backdrop { display: none; }

/* Touch devices (no hover): show normally-hidden hover-reveal controls
   so Reference-Documents admins can see the edit/delete/reorder buttons. */
@media (hover: none) {
  .section-card .sec-controls { opacity: 1; }
  .section-card .drag-handle  { display: none; }  /* HTML5 drag is dead on touch */
}

/* Slightly bigger hit target for the drag handle on desktop too. */
.section-card .drag-handle { padding: 10px; }

/* Disabled Up/Down arrows (first section can't move up, last can't move down). */
.section-card .sec-controls .btn[disabled] { opacity: .35; cursor: not-allowed; }

@media (max-width: 800px) {
  /* Prevent double-scroll when the drawer is open. */
  body.app { overflow: hidden; }

  /* Sidebar becomes an off-canvas drawer. */
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    z-index: 50; width: min(280px, 86vw);
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.18);
  }
  body.app.sidebar-open #sidebar { transform: translateX(0); }

  #sidebar-backdrop {
    display: block;
    position: fixed; inset: 0; z-index: 40;
    background: rgba(0,0,0,.4);
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
  }
  body.app.sidebar-open #sidebar-backdrop { opacity: 1; pointer-events: auto; }

  /* Hamburger bar across the top of #main. */
  #hamburger {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 30;
    padding: 10px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  #hamburger .burger {
    background: transparent; border: 1px solid var(--border);
    border-radius: 8px; padding: 7px 11px; cursor: pointer;
    font-size: 18px; line-height: 1; color: var(--text);
  }
  #hamburger .burger:hover { background: var(--surface-2); }
  #hamburger .brand-mini {
    font-size: 14px; font-weight: 700; letter-spacing: -.01em;
  }
  #hamburger .brand-mini .dot { color: var(--accent); }

  /* Tighter pane padding on mobile. */
  .pane { padding: 18px 16px 64px; }
  .pane > h1 { font-size: 22px; }

  /* Iframe-wrap was forcing min-height: 520px, which is taller than many
     phone viewports. Use dynamic viewport height instead. */
  .iframe-wrap {
    min-height: 0;
    height: calc(100dvh - 210px);
    height: calc(100vh - 210px);   /* fallback */
    height: calc(100dvh - 210px);  /* override if dvh supported */
  }

  /* Tabs: allow horizontal scroll instead of wrapping awkwardly. */
  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab { white-space: nowrap; flex-shrink: 0; font-size: 13px; padding: 10px 14px; }

  /* Section card: tighter padding on mobile. */
  .section-card { padding: 16px 16px; }
  .section-card .sec-title { font-size: 16px; }

  /* Doc row stacks vertically on narrow screens so long filenames don't
     squeeze the action buttons. */
  .doc { grid-template-columns: 44px 1fr; row-gap: 8px; }
  .doc .actions { grid-column: 1 / -1; flex-wrap: wrap; }

  /* Member row: stack actions below on narrow screens. */
  .member-row { grid-template-columns: 1fr; row-gap: 6px; }
}

/* Login OTP: 10px letter-spacing overflows ~360px phones. Pull it in. */
@media (max-width: 420px) {
  input.code { letter-spacing: 6px; font-size: 19px; }
  .card { padding: 22px 20px 20px; }
  body.auth { padding: 24px 14px; }
}
