:root {
  --primary: #1e3a5f;
  --primary-hover: #17304f;
  --primary-soft: #e8eef6;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1f2933;
  --muted: #6b7480;
  --faint: #9aa2ad;
  --green: #1f7a4d; --green-bg: #e3f4ea;
  --yellow: #8a6100; --yellow-bg: #fdf3d7;
  --red: #b42318; --red-bg: #fde8e6;
  --grey: #4b5563; --grey-bg: #eef0f3;
  --blue: #1e3a5f; --blue-bg: #e8eef6;
  --radius: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text); background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius);
  cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { background: #f0f2f5; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--red); }
.btn-danger-solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger-solid:hover { background: #962017; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #eef0f3; }
.btn svg { width: 15px; height: 15px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: #fff;
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30, 58, 95, .12); }
.invalid { border-color: var(--red) !important; box-shadow: 0 0 0 3px rgba(180, 35, 24, .1) !important; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card label { display: block; font-weight: 500; margin: 12px 0 4px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 18px; height: 38px; }
.login-err { color: var(--red); margin-top: 10px; min-height: 20px; }
.login-demo { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- layout ---------- */
.layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.brand { padding: 18px 18px 14px; font-weight: 700; font-size: 15px; color: var(--primary); display: flex; align-items: center; gap: 8px; }
.brand svg { width: 20px; height: 20px; }
.nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: transparent;
  border-radius: var(--radius); cursor: pointer; color: var(--grey); text-align: left; margin-bottom: 2px;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: #f0f2f5; color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-badge { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; font-weight: 600; border-radius: 10px; padding: 1px 7px; }
.user-box { border-top: 1px solid var(--border); padding: 12px 14px; font-size: 12px; color: var(--muted); }
.user-box select { margin: 4px 0 8px; height: 30px; font-size: 13px; }
.user-box .btn { width: 100%; justify-content: center; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 16px 24px 12px; flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 19px; font-weight: 650; margin-right: auto; }
.menu-btn { display: none; }
.content { flex: 1; overflow-y: auto; padding: 0 24px 32px; }

/* ---------- stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  cursor: pointer; text-align: left; border-left: 3px solid var(--border);
}
.stat:hover { border-color: var(--border-strong); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--faint); }
.stat.alert { border-left-color: var(--red); }
.stat.alert .value { color: var(--red); }
.stat.info { border-left-color: var(--primary); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar input[type=search] { width: 230px; }
.toolbar select { width: auto; min-width: 130px; }
.check-label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--grey); user-select: none; }
.bulkbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--primary-soft); border: 1px solid #cdd9e8;
  padding: 7px 10px; border-radius: var(--radius); margin-bottom: 10px;
}
.bulkbar select { width: auto; height: 28px; font-size: 13px; }
.bulkbar strong { margin-right: 6px; }

/* ---------- table ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap; background: #fafbfc; cursor: pointer; user-select: none; position: sticky; top: 0;
}
.list th.nosort { cursor: default; }
.list th .arrow { color: var(--faint); font-size: 10px; margin-left: 3px; }
.list td { padding: 9px 10px; border-bottom: 1px solid #eef0f3; vertical-align: middle; white-space: nowrap; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: #f7f9fc; }
.list tbody tr.selected { background: var(--primary-soft); }
.list tbody tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.list td.num, .list th.num { text-align: right; font-variant-numeric: tabular-nums; }
.list td.wrap { white-space: normal; min-width: 180px; max-width: 280px; }
.list .co { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 12px; }
.list .chk { width: 34px; }
.red-text { color: var(--red); font-weight: 600; }
.more-row { text-align: center; padding: 10px; color: var(--muted); }

/* ---------- tags ---------- */
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag-green { background: var(--green-bg); color: var(--green); }
.tag-yellow { background: var(--yellow-bg); color: var(--yellow); }
.tag-red { background: var(--red-bg); color: var(--red); }
.tag-grey { background: var(--grey-bg); color: var(--grey); }
.tag-blue { background: var(--blue-bg); color: var(--blue); }
.tags { display: inline-flex; gap: 4px; flex-wrap: wrap; }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty p { margin: 0 0 14px; }

/* ---------- overview ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.panel-card { padding: 14px 16px; }
.panel-card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 650; }
.panel-card .hint { color: var(--muted); font-size: 12px; margin: -6px 0 10px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.todo-item { display: flex; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid #eef0f3; cursor: pointer; }
.todo-item:last-child { border-bottom: 0; }
.todo-item:hover { background: #f7f9fc; }
.todo-item .grow { flex: 1; min-width: 0; }
.todo-item .grow .sub { color: var(--muted); font-size: 12px; }

/* ---------- side panel ---------- */
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 440px; max-width: 100%; background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; z-index: 20;
  transform: translateX(100%); transition: transform .18s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 14px 18px 0; border-bottom: 1px solid var(--border); }
.drawer-title { display: flex; align-items: flex-start; gap: 10px; }
.drawer-title h3 { margin: 0; font-size: 16px; flex: 1; }
.drawer-title .sub { color: var(--muted); font-size: 12px; font-weight: 400; display: block; margin-top: 2px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 4px; border-radius: 6px; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: #eef0f3; color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.tabs { display: flex; gap: 18px; margin-top: 12px; }
.tab { border: 0; background: transparent; padding: 8px 0; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 18px; }
.drawer-foot { border-top: 1px solid var(--border); padding: 12px 18px; display: flex; gap: 8px; align-items: center; }
.drawer-foot .spacer { flex: 1; }
.alert-box { border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.alert-box.warn { background: var(--yellow-bg); color: var(--yellow); }
.alert-box.bad { background: var(--red-bg); color: var(--red); }
.alert-box.ok { background: var(--green-bg); color: var(--green); }
.alert-box .grow { flex: 1; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; padding: 0; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f.full { grid-column: 1 / -1; }
.f label { font-size: 12.5px; font-weight: 500; color: var(--grey); }
.f label .req { color: var(--red); }
.f .check-label { height: 34px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--border); margin-left: 5px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--primary); }
.timeline .meta { font-size: 12px; color: var(--muted); }
.note-box { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.note-box .row { display: flex; gap: 8px; align-items: center; }
.note-box .row .hint { flex: 1; font-size: 12px; color: var(--muted); }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(16, 24, 40, .35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { max-width: 760px; }
.modal-head { padding: 16px 18px 6px; display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 6px 18px 12px; overflow-y: auto; }
.modal-foot { padding: 12px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; }
.map-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 10px 0; }
.preview { font-size: 12px; }
.preview td, .preview th { padding: 5px 8px; }
.toasts { position: fixed; top: 60px; right: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2933; color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 13px; max-width: 320px; animation: tin .15s ease; }
.toast.err { background: var(--red); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--grey-bg); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 13px; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 0 4px; font-size: 15px; line-height: 1; }
.chip button:hover { color: var(--red); }
.chip.locked { padding-right: 10px; }
.add-row { display: flex; gap: 6px; }
.add-row input { height: 30px; }
.rule-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.rule-row label { flex: 1; }
.rule-row input { width: 110px; height: 30px; }

/* ---------- mobile ---------- */
.backdrop { display: none; }
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; transform: translateX(-100%); transition: transform .18s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .3); z-index: 35; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px 10px; }
  .topbar h2 { font-size: 17px; }
  .topbar .hide-sm { display: none; }
  .content { padding: 0 16px 24px; }
  .toolbar input[type=search] { width: 100%; }
  .toolbar select { flex: 1; min-width: 0; }
  .drawer { position: fixed; width: 100%; border-left: 0; z-index: 45; }
  .fgrid { grid-template-columns: 1fr; }
  .map-grid { grid-template-columns: 1fr; }
  table.list thead { display: none; }
  table.list, .list tbody, .list tr, .list td { display: block; width: 100%; }
  .list tbody tr { border-bottom: 1px solid var(--border); padding: 8px 10px; position: relative; }
  .list td { border: 0; padding: 2px 0; white-space: normal; text-align: left !important; }
  .list td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12px; }
  .list td.chk { position: absolute; right: 8px; top: 8px; width: auto; }
  .list td.co-cell::before { content: none; }
  .list tbody tr.overdue { box-shadow: inset 3px 0 0 var(--red); }
  .list tbody tr.overdue td:first-child { box-shadow: none; }
}
