/* ClioConnect review portal */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #182033;
  --muted: #64708a;
  --line: #e3e8ef;
  --accent: #2357c6;
  --accent-soft: #e9f0fd;
  --accent-text: #ffffff;
  --warn-bg: #fff6e5;
  --warn-text: #8a4b00;
  --error: #b42318;
  --error-bg: #fdecea;
  --side-bg: #ffffff;
  --side-text: #3b4660;
  --side-muted: #8a94a8;
  --side-hover: #f1f4f9;
  --side-active: #e9f0fd;
  --side-strong: #111a2e;
  --side-line: #e3e8ef;
  --side-bar: #2357c6;
  --side-avatar-bg: #e9f0fd;
  --side-avatar-fg: #2357c6;
  --side-switch-bg: #f1f4f9;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --radius: 12px;
  --radius-sm: 8px;
}
/* Dark: follows the system unless the user picked Light; or forced by picking Dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e131d;
    --surface: #161d2a;
    --surface-2: #1b2332;
    --text: #e6eaf2;
    --muted: #97a2b8;
    --line: #283246;
    --accent: #7aa6ff;
    --accent-soft: #1d2b47;
    --accent-text: #0b1220;
    --warn-bg: #3a2a10;
    --warn-text: #ffcf8a;
    --error: #ff8a80;
    --error-bg: #3a1a1a;
    --side-bg: #0a0f18;
    --side-text: #c4cde0;
    --side-muted: #6f7b94;
    --side-hover: #151d2c;
    --side-active: #1e2a42;
    --side-strong: #ffffff;
    --side-line: rgba(255, 255, 255, .08);
    --side-bar: #6d9bff;
    --side-avatar-bg: #2b3d66;
    --side-avatar-fg: #dce6ff;
    --side-switch-bg: rgba(255, 255, 255, .06);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
  }
}
:root[data-theme="dark"] {
    --bg: #0e131d;
    --surface: #161d2a;
    --surface-2: #1b2332;
    --text: #e6eaf2;
    --muted: #97a2b8;
    --line: #283246;
    --accent: #7aa6ff;
    --accent-soft: #1d2b47;
    --accent-text: #0b1220;
    --warn-bg: #3a2a10;
    --warn-text: #ffcf8a;
    --error: #ff8a80;
    --error-bg: #3a1a1a;
    --side-bg: #0a0f18;
    --side-text: #c4cde0;
    --side-muted: #6f7b94;
    --side-hover: #151d2c;
    --side-active: #1e2a42;
    --side-strong: #ffffff;
    --side-line: rgba(255, 255, 255, .08);
    --side-bar: #6d9bff;
    --side-avatar-bg: #2b3d66;
    --side-avatar-fg: #dce6ff;
    --side-switch-bg: rgba(255, 255, 255, .06);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.01em; margin: .2rem 0 1.1rem; }
h2 { font-size: 1.12rem; font-weight: 620; margin: 1.8rem 0 .7rem; }
h3 { font-size: 1rem; font-weight: 600; margin: 1.2rem 0 .5rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
.icon { width: 18px; height: 18px; flex: none; }

/* --- layout ----------------------------------------------------------------- */
body.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.content { min-width: 0; }
main { max-width: 1240px; margin: 0 auto; padding: 28px 32px 48px; }
body.plain main { max-width: 480px; padding-top: 8px; }

.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--side-bg); color: var(--side-text); padding: 18px 12px; border-right: 1px solid var(--side-line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #4f86f7, #2357c6); color: #fff; font-weight: 700; font-size: 1.05rem; box-shadow: 0 4px 12px rgba(35, 87, 198, .35); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: var(--side-strong); font-size: 1rem; letter-spacing: .01em; }
.brand-text small { color: var(--side-muted); font-size: .76rem; }
.menu-toggle { display: none; margin-left: auto; background: none; border: 0; color: var(--side-strong); padding: 6px; cursor: pointer; }
.sidebar nav { flex: 1; overflow-y: auto; }
.nav-section { margin: 18px 10px 6px; font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted); }
.nav-link { display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin: 2px 0; border-radius: var(--radius-sm); color: var(--side-text); font-weight: 500; }
.nav-link:hover { background: var(--side-hover); color: var(--side-strong); text-decoration: none; }
.nav-link.active { background: var(--side-active); color: var(--side-strong); box-shadow: inset 3px 0 0 var(--side-bar); }
.me { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--side-line); padding: 14px 4px 0; margin-top: 12px; }
.me form { margin: 0; }
.me-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--radius-sm); color: var(--side-text); }
.me-link:hover, .me-link.active { background: var(--side-hover); text-decoration: none; }
.me-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.me-text strong { color: var(--side-strong); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { color: var(--side-muted); font-size: .75rem; }
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--side-avatar-bg); color: var(--side-avatar-fg); font-weight: 600; flex: none; }
.icon-button { background: none; border: 0; color: var(--side-muted); padding: 8px; border-radius: var(--radius-sm); cursor: pointer; display: grid; place-items: center; }
.icon-button:hover { background: var(--side-hover); color: var(--side-strong); filter: none; }

.plain-brand { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 56px 0 8px; font-size: 1.2rem; }

.impersonation { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; padding: 9px 16px; background: var(--warn-bg); color: var(--warn-text); border-bottom: 1px solid rgba(138, 75, 0, .2); font-size: .92rem; }
.impersonation button { background: var(--warn-text); color: var(--surface); padding: 4px 14px; }

@media (max-width: 860px) {
  body.app { display: block; }
  .sidebar { position: static; height: auto; padding: 10px 12px; }
  .brand { padding: 2px 4px; }
  .menu-toggle { display: block; }
  .sidebar nav, .sidebar .me { display: none; }
  .sidebar.open nav, .sidebar.open .me { display: flex; }
  .sidebar.open nav { flex-direction: column; padding-top: 8px; }
  main { padding: 18px 16px 40px; }
}

/* --- surfaces --------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.narrow { max-width: 460px; margin: 24px auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.box { color: var(--text); transition: transform .12s ease, box-shadow .12s ease; }
.box:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); text-decoration: none; }
.box h2 { margin: 0 0 8px; color: var(--accent); font-size: 1.1rem; }
.box p { margin: 4px 0; color: var(--muted); }
.box strong { color: var(--text); }
.muted { color: var(--muted); }
.error { color: var(--error); background: var(--error-bg); padding: 10px 14px; border-radius: var(--radius-sm); font-weight: 500; }
.notice { background: var(--accent-soft); padding: 10px 14px; border-radius: var(--radius-sm); }
.crumbs { color: var(--muted); margin: 0 0 4px; font-size: .9rem; }

/* --- forms and buttons ------------------------------------------------------ */
label { display: block; margin: 0 0 14px; font-weight: 500; font-size: .93rem; }
label.check { display: inline-flex; gap: 7px; align-items: center; margin: 4px 16px 4px 0; font-weight: 400; }
input, select, button, textarea { font: inherit; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select { display: block; width: 100%; margin-top: 6px; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=file] { display: block; margin-top: 8px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 0 0 14px; padding: 10px 14px; }
legend { padding: 0 6px; color: var(--muted); font-size: .88rem; }
button, .button { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--accent); color: var(--accent-text); font-weight: 550; cursor: pointer; text-decoration: none; transition: filter .12s, background .12s; }
button:hover, .button:hover { filter: brightness(1.08); text-decoration: none; }
button.secondary, .button.secondary { background: var(--surface); color: var(--accent); border-color: var(--line); }
button.secondary:hover, .button.secondary:hover { background: var(--accent-soft); filter: none; }
button.link { background: none; color: var(--accent); padding: 0; border: 0; font-weight: 500; }
.button.small { padding: 4px 11px; font-size: .86rem; }
form.inline { display: inline; }

/* --- tables ----------------------------------------------------------------- */
table.list { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 24px; overflow: hidden; font-size: .93rem; }
table.list th { text-align: left; padding: 10px 14px; background: var(--surface-2); color: var(--muted); font-size: .76rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; border-bottom: 1px solid var(--line); }
table.list td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover td { background: var(--surface-2); }
table.list tr.other td { color: var(--muted); }
tr.flag td { background: var(--warn-bg); }
@media (max-width: 860px) { table.list { display: block; overflow-x: auto; } }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.reason { color: var(--muted); font-size: .9em; }
.detail { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8em; word-break: break-all; color: var(--muted); }
table.sortable th { cursor: pointer; user-select: none; }
table.sortable th:hover { color: var(--text); }
table.sortable th[aria-sort="ascending"]::after { content: " ▲"; font-size: .7em; }
table.sortable th[aria-sort="descending"]::after { content: " ▼"; font-size: .7em; }

/* --- page pieces ------------------------------------------------------------ */
.confirm-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.confirm-bar span { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.filters label { margin: 0; min-width: 140px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 14px; }
.item-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.item-layout aside { position: sticky; top: 20px; }
@media (max-width: 1000px) { .item-layout { grid-template-columns: 1fr; } .item-layout aside { position: static; } }
.subject { font-size: 1.3rem; margin-top: 0; word-break: break-word; }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .93rem; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; word-break: break-word; }
pre.body { white-space: pre-wrap; word-break: break-word; font: inherit; border-top: 1px solid var(--line); padding-top: 14px; margin-bottom: 0; max-height: 70vh; overflow: auto; }
img.page { max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.matter-select { margin-bottom: 10px; }
.other-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.qr { display: flex; justify-content: center; margin: 12px 0; }
.qr svg { width: 220px; height: 220px; background: #fff; padding: 10px; border-radius: var(--radius-sm); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.thumbs figure { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s; }
.thumbs figure:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.thumbs img { width: 100%; height: 230px; object-fit: contain; background: #fff; border-radius: 6px; }
.thumbs figcaption { font-size: .86em; margin-top: 8px; word-break: break-word; }

.lightbox { position: fixed; inset: 0; background: rgba(8, 12, 20, .9); display: flex; align-items: center; justify-content: center; z-index: 10; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 86vw; max-height: 84vh; background: #fff; border-radius: 6px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.lightbox button { position: absolute; background: rgba(255, 255, 255, .08); border: 0; color: #fff; font-size: 2rem; line-height: 1; padding: 10px 16px; border-radius: 50%; }
.lightbox button:hover { background: rgba(255, 255, 255, .18); }
.lb-close { top: 16px; right: 18px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lb-caption { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: #dfe6f3; margin: 0; }
.lb-caption a { color: #9cc2ff; }
.card > h1:first-child, .card > h2:first-child { margin-top: 0; }

/* --- filing: chips, dock, drag and drop, toast, paid badges ----------------- */
.panel-label { margin: 16px 0 6px; font-size: .74rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.small { font-size: .85rem; }
kbd { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; margin-right: 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); color: var(--muted); font: 600 .72rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px 6px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 500; }
.chip:hover { background: var(--accent-soft); border-color: var(--accent); filter: none; }
.chip.current { background: var(--accent-soft); border-color: var(--accent); }
.chip.static { padding: 4px 12px; cursor: default; }

.file-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
.dock { position: sticky; top: 20px; padding: 16px; max-height: calc(100vh - 40px); overflow-y: auto; }
.dock h2 { margin: 0 0 4px; font-size: 1rem; }
.dock .panel-label { margin-top: 14px; }
.drop { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 10px; margin: 4px 0; border: 1.5px dashed var(--line); border-radius: var(--radius-sm); background: var(--surface-2); font-size: .92rem; transition: background .1s, border-color .1s, transform .1s; }
.drop small { width: 100%; margin-left: 2px; font-size: .78rem; }
.drop.over { border-color: var(--accent); border-style: solid; background: var(--accent-soft); transform: scale(1.02); }
.drop[hidden] { display: none; }
.dock-search { margin: 6px 0 !important; }
.thumbs figure[draggable="true"] { cursor: grab; }
.thumbs figure.dragging { opacity: .45; }
.thumbs figure.filing { opacity: .6; }
.thumbs figure.gone { transform: scale(.9); opacity: 0; transition: transform .2s, opacity .2s; }
@media (max-width: 1000px) { .file-layout { grid-template-columns: 1fr; } .dock { position: static; max-height: none; } }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; padding: 11px 18px; border-radius: 999px; background: #1b2640; color: #fff; box-shadow: var(--shadow-lg); z-index: 20; font-size: .93rem; }
.toast[hidden] { display: none; }
.toast .undo { color: #9cc2ff; font-weight: 600; }

.paid-form { margin-top: 6px; }
.paid-badge { padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--warn-bg); color: var(--warn-text); border: 1px solid transparent; }
.paid-badge.is-paid { background: #e3f5ec; color: #16794c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .paid-badge.is-paid { background: #133826; color: #6fd8a3; } }
:root[data-theme="dark"] .paid-badge.is-paid { background: #133826; color: #6fd8a3; }

.cat-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cat-row input[name=name] { width: 170px !important; display: inline-block !important; margin: 0 !important; }
.cat-row input[name=description] { flex: 1; min-width: 160px; display: inline-block !important; margin: 0 !important; }
.cat-row select { width: auto !important; display: inline-block !important; margin: 0 !important; }
.toast { bottom: 64px; }
.chips + form.assign label { margin-top: 18px; }

/* Theme switch in the sidebar's user area */
.theme-switch { display: flex; gap: 2px; padding: 3px; margin: 0 4px 10px; border-radius: 999px; background: var(--side-switch-bg); }
.theme-switch form { flex: 1; margin: 0; }
.theme-switch button { width: 100%; justify-content: center; padding: 5px 0; border-radius: 999px; background: none; color: var(--side-muted); font-size: .78rem; font-weight: 600; }
.theme-switch button:hover { color: var(--side-strong); filter: none; }
.theme-switch button.on { background: var(--side-surface, var(--surface)); color: var(--side-strong); box-shadow: var(--shadow); }
.sidebar-foot { margin-top: 12px; border-top: 1px solid var(--side-line); padding-top: 12px; }
.sidebar-foot .me { border-top: 0; margin-top: 0; padding-top: 0; }
@media (max-width: 860px) { .sidebar .sidebar-foot { display: none; } .sidebar.open .sidebar-foot { display: block; } .sidebar.open .sidebar-foot .me { display: flex; } }

/* --- possible cases ---------------------------------------------------------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin: 6px 0 14px; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.segmented a { padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 550; font-size: .9rem; }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.on { background: var(--accent-soft); color: var(--accent); }
.segmented .count { display: inline-block; min-width: 20px; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .76rem; text-align: center; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: .76rem; font-weight: 600; vertical-align: middle; margin-left: 6px; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
h1 .pill { font-size: .8rem; }
