/* Theme matches the ProjectFlow app: dark navy surfaces, #3B82F6 primary, Inter. Light variant follows the OS setting. */
:root {
  --bg: #11141d; --surface: #171b26; --side: #131621; --text: #e2e8f0; --muted: #8c9ab0; --line: #2a2f3f;
  --brand: #3b82f6; --brand-dark: #60a5fa; --brand-soft: #1a2a4a;
  --green: #34d399; --green-bg: #11302a; --amber: #fbbf24; --amber-bg: #38290f;
  --red: #f87171; --red-bg: #3b1a1d; --blue: #60a5fa; --blue-bg: #172a4a; --grey-bg: #222838;
  --radius: 8px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #eef3f9; --surface: #ffffff; --side: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
    --brand: #3b82f6; --brand-dark: #2563eb; --brand-soft: #e5efff;
    --green: #12805c; --green-bg: #e3f6ee; --amber: #a15c07; --amber-bg: #fff2d9;
    --red: #b42318; --red-bg: #fde8e6; --blue: #1d5fc4; --blue-bg: #e5efff; --grey-bg: #f1f5f9; color-scheme: light; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: clamp(13px, 0.2vw + 10px, 15px)/1.45 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; cursor: pointer; } a:hover { text-decoration: underline; }
h1 { font-size: 1.45em; margin: 0; } h2 { font-size: 1.07em; margin: 0; } h3 { margin: 0 0 8px; font-size: 1em; }
.muted { color: var(--muted); } .small { font-size: .86em; } .right { text-align: right; } th.right, td.right { text-align: center; } .mono { font-family: ui-monospace, Menlo, monospace; }

/* layout */
.shell { display: grid; grid-template-columns: clamp(180px, 15vw, 280px) minmax(0, 1fr); height: 100vh; height: 100dvh; width: 100%; }
.side { background: var(--side); border-right: 1px solid var(--line); padding: 1.3em .85em; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15em; padding: 4px 10px 1.3em; }
.logo i { width: 2.1em; height: 2.1em; flex: none; border-radius: 50%; background: color-mix(in srgb, var(--brand) 25%, transparent); border: 1px solid color-mix(in srgb, var(--brand) 45%, transparent); display: grid; place-items: center; color: var(--brand); font-style: normal; font-weight: 800; font-size: .9em; }
.logo small { display: block; font-weight: 400; color: var(--muted); font-size: .8em; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; color: var(--text); }
.nav a:hover { background: var(--grey-bg); text-decoration: none; }
.nav a.on { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; box-shadow: inset 3px 0 0 var(--brand); }
.nav .count { margin-left: auto; background: var(--red); color: #fff; font-size: .8em; border-radius: 9px; padding: 0 6px; }
.side .who { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: .86em; overflow-wrap: anywhere; }
main { padding: clamp(16px, 2.2vw, 44px) clamp(14px, 2.6vw, 56px) 60px; width: 100%; min-width: 0; height: 100%; overflow-y: auto; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.head p { margin: 2px 0 0; color: var(--muted); }

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card { box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.card > header { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.card .body { padding: clamp(12px, 1.6vw, 20px); }
.card:has(> table) { overflow-x: auto; }
.card > header { flex-wrap: wrap; gap: 8px; }
main > * { max-width: 1600px; margin-inline: auto; }
.grid { display: grid; gap: 16px; } .g4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 13em), 1fr)); } .g2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 26em), 1fr)); }
.stat { padding: 16px; } .stat .n { font-size: 1.8em; font-weight: 700; margin-top: 2px; } .stat .l { color: var(--muted); } .stat .s { font-size: .86em; margin-top: 2px; color: var(--muted); }
.stat.warn .n { color: var(--red); }
table { width: 100%; border-collapse: collapse; }
th { text-align: center; vertical-align: middle; font-weight: 600; font-size: .86em; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: center; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: var(--bg); }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .86em; font-weight: 600; white-space: nowrap; }
.b-green { background: var(--green-bg); color: var(--green); } .b-amber { background: var(--amber-bg); color: var(--amber); }
.b-red { background: var(--red-bg); color: var(--red); } .b-blue { background: var(--blue-bg); color: var(--blue); } .b-grey { background: var(--grey-bg); color: var(--muted); }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 6px; cursor: pointer; }
button:hover { background: var(--grey-bg); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; } button.primary:hover { background: #2563eb; border-color: #2563eb; }
button.sm { padding: 4px 10px; font-size: .86em; } button.danger { color: var(--red); } button:disabled { opacity: .55; cursor: wait; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .86em; margin-bottom: 4px; }
label .req { color: var(--red); }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; } .toolbar input { max-width: 22em; flex: 1 1 14em; } .toolbar select { width: auto; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--brand-dark); border-color: var(--brand); font-weight: 600; } .tabs a:hover { text-decoration: none; color: var(--text); }
.kv { display: grid; grid-template-columns: minmax(6.5em, max-content) minmax(0, 1fr); gap: 8px 14px; } .kv dd { overflow-wrap: anywhere; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; } .gap { gap: 14px; }

/* form + modal */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16em), 1fr)); gap: 14px 16px; } .form .full { grid-column: 1 / -1; }
.form h3 { grid-column: 1 / -1; margin: 6px 0 -4px; padding-top: 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-size: .86em; }
.overlay { position: fixed; inset: 0; background: rgba(8,10,18,.65); display: grid; place-items: start center; padding: 5vh 16px; overflow: auto; z-index: 10; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; width: 100%; max-width: min(46em, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal > header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal .body { padding: 20px; } .modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.note { background: var(--brand-soft); color: var(--brand-dark); padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.note.warn { background: var(--amber-bg); color: var(--amber); }
.err { color: var(--red); font-size: 13px; min-height: 18px; }
.toast { position: fixed; bottom: 22px; right: 22px; max-width: min(380px, calc(100vw - 32px)); font-size: 1em; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--brand); color: var(--text); padding: 11px 16px; border-radius: 9px; z-index: 20; max-width: 380px; }
.secret { background: var(--grey-bg); padding: 10px 12px; border-radius: 8px; font-family: ui-monospace, Menlo, monospace; margin-top: 8px; user-select: all; }
.thread { display: grid; gap: 10px; margin: 14px 0; } .msg { background: var(--bg); border-radius: 8px; padding: 10px 12px; } .msg.staff { background: var(--brand-soft); }
.list-item { display: flex; justify-content: space-between; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--line); cursor: pointer; } .list-item:last-child { border: 0; } .list-item:hover { background: var(--bg); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 26em; padding: 28px; display: grid; gap: 14px; }

/* responsive */
@media (max-width: 1100px) {
  .shell { grid-template-columns: clamp(170px, 20vw, 220px) minmax(0, 1fr); }
  th, td { padding-inline: 12px; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .side { height: auto; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: .6em .8em; }
  .logo { padding: 2px 4px; }
  .nav { display: flex; flex-wrap: nowrap; gap: 2px; overflow-x: auto; flex: 1 1 100%; order: 3; padding-bottom: 2px; scrollbar-width: thin; }
  .nav a { padding: 7px 10px; white-space: nowrap; flex: none; }
  .nav a.on { box-shadow: inset 0 -3px 0 var(--brand); }
  .side .who { margin: 0 0 0 auto; border: 0; padding: 2px 4px; text-align: right; }
  main { padding: 16px 14px 50px; }
  .head { margin-bottom: 14px; }
  .tabs { overflow-x: auto; }
  .tabs a { white-space: nowrap; }
  .overlay { padding: 2vh 10px; }
  .modal .body, .modal > header, .modal footer { padding-inline: 14px; }
}
@media (max-width: 520px) {
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; } .kv dt { margin-top: 8px; font-size: .86em; }
  .toolbar input, .toolbar select { max-width: none; width: 100%; flex: 1 1 100%; }
  .row { flex-wrap: wrap; }
  .login .card { padding: 20px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 12px; } .stat .n { font-size: 1.5em; }
}
@media (pointer: coarse) { button, .btn, input, select { min-height: 40px; } button.sm { min-height: 34px; } .nav a { min-height: 40px; } }
@media (min-width: 1800px) { html { font-size: 17px; } }

/* text never spills past its box: long strings (emails, URLs) wrap, normal words keep whole, flex/grid children may shrink.
   Table cells only break inside long strings; narrow screens scroll the table sideways instead of crushing the columns. */
.card, .modal, .stat, .note, .msg, .list-item, .head, h1, h2, h3, p, label, dd, dt, .logo, .secret, pre, .toast { overflow-wrap: anywhere; }
td, th { overflow-wrap: break-word; }
td .small, td .muted { overflow-wrap: anywhere; }
td:first-child { min-width: 9em; }
td .badge, td button, th { white-space: nowrap; }
.grid > *, .form > *, .head > *, .row > *, .list-item > *, .card, .modal, .kv > * { min-width: 0; }
.badge { max-width: 100%; text-align: center; }
button, .btn { max-width: 100%; }
input, select, textarea { min-width: 0; max-width: 100%; }
.secret, pre { word-break: break-all; }
td { min-width: 5em; }
td .small { display: inline-block; max-width: 18em; }

/* Clients table: cell text wraps to fit the column instead of forcing one long line */
th { white-space: normal; }
td, td .small, td .muted { white-space: normal; overflow-wrap: anywhere; }
td .small { display: block; max-width: none; }

/* collapsible menu panel (desktop) */
.shell { transition: grid-template-columns .2s ease; }
.side-toggle { margin-left: auto; flex: none; padding: 2px 8px; line-height: 1.2; }
.shell.collapsed { grid-template-columns: 64px minmax(0, 1fr); }
.shell.collapsed .side { padding-inline: .5em; align-items: stretch; }
.shell.collapsed .logo { flex-direction: column; padding-inline: 0; gap: 8px; }
.shell.collapsed .label { display: none; }
.shell.collapsed .nav a { justify-content: center; position: relative; padding-inline: 0; }
.shell.collapsed .nav .count { position: absolute; top: 2px; right: 4px; margin: 0; font-size: .65em; }
.shell.collapsed .side .who { text-align: center; padding-inline: 0; font-size: .75em; }
@media (max-width: 820px) { .side-toggle { display: none; } .shell.collapsed { grid-template-columns: minmax(0, 1fr); } .shell.collapsed .label { display: revert; } }
