:root {
  --navy: #143457;
  --navy-2: #1d4672;
  --ink: #1b2430;
  --ink-2: #4a5566;
  --muted: #6b7686;
  --line: #dfe3ea;
  --line-2: #c9d0db;
  --bg: #f4f6f9;
  --card: #ffffff;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --danger: #c0352b;
  --danger-bg: #fdecea;
  --warn-bg: #fff6e0;
  --warn-line: #f0c96a;
  --ok: #1f7a4d;
  --ok-bg: #e5f4ec;
  --pre-bg: #eef1f5;
  --active-bg: #e6effd;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
p { margin: 0 0 12px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; }
.center { text-align: center; }

/* controls */
button, input, select, textarea { font: inherit; color: inherit; }
button {
  height: 34px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line-2);
  background: #fff; cursor: pointer; font-weight: 550; white-space: nowrap;
}
button:hover { background: #f1f4f8; }
button:disabled { opacity: .6; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { background: #185ec9; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger-outline { color: var(--danger); border-color: #e7b3ae; }
button.danger-outline:hover { background: var(--danger-bg); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: #e9edf3; }
button.small { height: 28px; padding: 0 10px; font-size: 13px; }
button.block { width: 100%; margin-top: 6px; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; height: 32px; width: 32px; padding: 0; color: var(--muted); }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search], input[type=date], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: var(--radius); background: #fff;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, button:focus-visible, tr.row:focus-visible {
  outline: 2px solid rgba(31, 111, 235, .35); outline-offset: 1px; border-color: var(--accent);
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-weight: 600; font-size: 13px; color: var(--ink-2); }
.req { color: var(--danger); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.hint.over { color: var(--danger); font-weight: 600; }
.error { color: var(--danger); margin: 6px 0 0; min-height: 0; }
.error:empty { display: none; }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: var(--radius); padding: 10px 12px; margin-top: 10px; display: grid; gap: 3px; }
.warn[hidden] { display: none; }
.checks { display: flex; gap: 16px; flex-wrap: wrap; min-height: 36px; align-items: center; }
.checks.wrap { gap: 8px 18px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 450 !important; color: var(--ink) !important; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.copy-row { display: flex; gap: 8px; }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 24px; background: var(--navy); color: #fff;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; background: #fff; color: var(--navy); font-size: 12px; font-weight: 800; letter-spacing: .02em; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #c9d6e6; padding: 6px 12px; border-radius: 6px; font-weight: 550; }
.topbar nav a:hover { background: var(--navy-2); color: #fff; text-decoration: none; }
.topbar nav a.active { background: var(--navy-2); color: #fff; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.who-name { font-weight: 550; }
.who-role { margin-left: 8px; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--navy-2); color: #c9d6e6; }
.who button.ghost { color: #c9d6e6; }
.who button.ghost:hover { background: var(--navy-2); color: #fff; }
.page { max-width: 1400px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-head .count { display: block; margin-top: 2px; }
.page-head .sub { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.back { display: inline-block; margin-bottom: 10px; font-weight: 550; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: #f3e8ff; color: #6b2fa5; margin-left: 6px; vertical-align: 1px; }
.admin-card { border-color: #e3d3f5; }

/* list */
.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(130px, 180px)); gap: 8px; margin-bottom: 12px; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: 12px; font-weight: 650; color: var(--ink-2); background: #f8f9fb; border-bottom: 1px solid var(--line); padding: 0; white-space: nowrap; }
table.grid th:not(:has(button)) { padding: 9px 12px; }
.th-btn { all: unset; display: block; padding: 9px 12px; cursor: pointer; width: 100%; box-sizing: border-box; }
.th-btn:hover { color: var(--ink); background: #eef1f5; }
.th-btn:focus-visible { outline: 2px solid rgba(31, 111, 235, .35); }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tr:last-child td { border-bottom: 0; }
tr.row { cursor: pointer; }
tr.row:hover td { background: #f6f9fe; }
tr.inactive td { color: var(--muted); }
td.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
td.notes-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
td.row-actions { text-align: right; white-space: nowrap; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.pill-pre { background: var(--pre-bg); color: #4a5566; }
.pill-active { background: var(--active-bg); color: #1a4fa0; }
.pill-won { background: var(--ok-bg); color: var(--ok); }
.pill-lost { background: var(--danger-bg); color: var(--danger); }
.overdue { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.overdue summary { cursor: pointer; }
.overdue table { margin-top: 10px; background: #fff; border-radius: 8px; overflow: hidden; }
table.compact td, table.compact th { padding: 7px 10px !important; }

/* detail */
.assignees { list-style: none; margin: 0 0 12px; padding: 0; }
.assignees li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.assignees li:last-child { border-bottom: 0; }
.assign-form { display: grid; grid-template-columns: minmax(0, 1fr) 150px auto; gap: 8px; margin-bottom: 6px; }
.log { list-style: none; margin: 0; padding: 0; max-height: 480px; overflow-y: auto; }
.log li { padding: 9px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.log li:last-child { border-bottom: 0; }
.log-meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.log .old { color: var(--muted); text-decoration: line-through; }
.log .new { font-weight: 600; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--navy); }
.auth-card { width: 100%; max-width: 380px; background: #fff; border-radius: 12px; padding: 28px; display: grid; gap: 4px; }
.auth-card form { display: grid; gap: 14px; margin-top: 12px; }
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; margin-bottom: 14px; color: var(--navy); }
.auth-brand .brand-mark { background: var(--navy); color: #fff; }

/* dialogs and toasts */
.backdrop { position: fixed; inset: 0; background: rgba(15, 28, 46, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.dialog { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow: auto; background: #fff; border-radius: 12px; }
.dialog-wide { max-width: 640px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0 20px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-body { padding: 14px 20px 20px; }
.dialog-body > form { display: grid; gap: 14px; }
.dialog-body > form.form-grid { display: grid; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-weight: 550; transition: .2s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--danger); }

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar input[type=search] { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  .page { padding: 16px; }
  .topbar { padding: 0 16px; gap: 12px; }
  .who-name { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .assign-form { grid-template-columns: 1fr 1fr; }
  .assign-form button { grid-column: 1 / -1; }
  .page-head { flex-wrap: wrap; }
}
