:root {
  --brand: #14605f;
  --brand-dark: #0d4443;
  --brand-soft: #e3f0ef;
  --accent: #e8913a;
  --bg: #f4f6f7;
  --card: #ffffff;
  --text: #1c2b33;
  --muted: #64748b;
  --line: #e2e8f0;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info-soft: #e0f2fe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error-text { color: var(--bad); min-height: 1.2em; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---- auth ---- */
.auth-screen { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand-dark), var(--brand)); padding: 16px; }
.auth-card { background: var(--card); width: 100%; max-width: 380px; padding: 28px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; }
.brand-lg { font-size: 22px; font-weight: 750; color: var(--brand-dark); }
.brand-lg span { color: var(--accent); }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand-dark); color: #d6e7e6; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 18px 14px; font-size: 18px; font-weight: 750; color: #fff; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.brand span { color: var(--accent); }
.brand small { display: block; font-size: 11px; font-weight: 500; color: #9fc3c1; margin-top: 2px; }
#nav { flex: 1; overflow-y: auto; padding: 8px; }
#nav a { display: flex; align-items: center; justify-content: space-between; color: #d6e7e6; text-decoration: none; padding: 9px 12px; border-radius: 8px; margin-bottom: 2px; }
#nav a:hover { background: rgba(255, 255, 255, .07); }
#nav a.active { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 600; }
#nav .badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 12px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot .btn { color: #d6e7e6; border-color: rgba(255, 255, 255, .25); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; flex: 1; }
.menu-btn { display: none; }
.page { padding: 20px 24px 60px; display: flex; flex-direction: column; gap: 16px; }

/* ---- components ---- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
.toolbar input[type=checkbox] { min-width: 0; width: auto; margin: 0 4px 0 0; vertical-align: middle; }
.toolbar input[type=search] { min-width: 240px; }
.grid { display: grid; gap: 12px; }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; border-top: 3px solid var(--brand); }
.tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
.tile .value { font-size: 20px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .hint { color: var(--muted); font-size: 11px; margin-top: 4px; }
.tile.money { border-top-color: var(--accent); }
.tile.bad { border-top-color: var(--bad); }

input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #94a3b8; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; padding: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f8fafc; position: sticky; top: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafc; }
.empty { color: var(--muted); padding: 20px; text-align: center; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #eef2f6; color: #334155; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: #0369a1; }
.pill.brand { background: var(--brand-soft); color: var(--brand-dark); }

.bar { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--brand); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { border-left: 3px solid var(--brand-soft); padding: 2px 0 2px 10px; }
.timeline li.human { border-left-color: var(--brand); }

.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.kanban-col { background: #eef2f4; border-radius: var(--radius); padding: 8px; min-height: 120px; }
.kanban-col h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 4px 4px 8px; display: flex; justify-content: space-between; }
.kanban-card { background: #fff; border-radius: 8px; padding: 9px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.kanban-card:hover { outline: 2px solid var(--brand-soft); }

/* ---- drawer / modal / toast ---- */
.drawer { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 20; display: flex; justify-content: flex-end; }
.drawer-panel { background: var(--bg); width: min(760px, 100%); height: 100%; overflow-y: auto; padding: 20px; position: relative; display: flex; flex-direction: column; gap: 14px; }
.drawer-close { position: absolute; top: 14px; right: 14px; }
#drawer-body { display: flex; flex-direction: column; gap: 14px; }
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; width: min(620px, 100%); max-height: 92vh; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: #334155; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; }
.form-grid label.check input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 10px; z-index: 40; max-width: 420px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
.toast.error { background: var(--bad); }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 16px; background: var(--warn-soft); padding: 10px 12px; border-radius: 8px; user-select: all; }
.notice { background: var(--info-soft); border-radius: 8px; padding: 10px 12px; }
.notice.warn { background: var(--warn-soft); }
.items-editor .item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 32px; gap: 6px; margin-bottom: 6px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 15; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .page { padding: 14px; }
  .kv { grid-template-columns: 1fr; }
}
