:root {
  --bg: #f4f6fa; --card: #ffffff; --ink: #1b2437; --muted: #6b7690; --line: #e3e8f1;
  --brand: #2f5bea; --brand-ink: #ffffff; --brand-soft: #e8eefe;
  --side: #121a2e; --side-ink: #c9d2e8; --side-active: #22304f;
  --ok: #138a52; --ok-bg: #e2f6ec; --warn: #a15c00; --warn-bg: #fff1d6;
  --bad: #c0392b; --bad-bg: #fde8e5; --info: #1f5fbf; --info-bg: #e3eefc;
  --purple: #6a3fc0; --purple-bg: #efe8fb; --gray-bg: #eceff5;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
a { color: var(--brand); }
small, .muted { color: var(--muted); }

.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: 0 8px 30px rgba(20, 30, 60, .08); }
.login-card h1 { margin-bottom: 4px; }
.login-card .logo-full { display: block; width: 250px; max-width: 80%; height: auto; margin: 0 auto 14px; }
.login-card p { margin: 0 0 18px; color: var(--muted); }

label.f { display: block; margin: 0 0 12px; font-weight: 600; font-size: 13px; }
label.f > span { display: block; margin-bottom: 4px; }
label.f small { font-weight: 400; }
input, select, textarea { width: 100%; font: inherit; color: inherit; padding: 8px 10px; border: 1px solid #cfd6e4; border-radius: 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; margin-right: 6px; }
textarea { min-height: 80px; resize: vertical; }
.inline-input { width: auto; }
.check { display: flex; align-items: center; gap: 6px; margin: 4px 0 12px; font-weight: 500; }
.check input { margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
@media (max-width: 640px) { .row2, .row3 { grid-template-columns: 1fr; } }

.btn { font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); cursor: pointer; }
.btn:hover { filter: brightness(.95); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--brand); }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }

#app-view { display: flex; min-height: 100vh; }
#sidebar { width: 220px; flex: 0 0 220px; background: var(--side); color: var(--side-ink); padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
#sidebar .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 14px; display: flex; align-items: center; gap: 10px; }
#sidebar .brand img { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 9px; background: #fff; padding: 2px; object-fit: contain; }
#sidebar .brand small { display: block; color: #8d9abd; font-weight: 400; font-size: 12px; }
#sidebar a { display: flex; align-items: center; justify-content: space-between; color: var(--side-ink); text-decoration: none; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
#sidebar a:hover { background: #1a2542; }
#sidebar a.active { background: var(--side-active); color: #fff; }
.pill { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
#content-wrap { flex: 1; min-width: 0; }
#topbar { display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 10px 24px; border-bottom: 1px solid var(--line); background: var(--card); }
#main { padding: 22px 24px 60px; max-width: 1400px; }
@media (max-width: 900px) {
  #app-view { flex-direction: column; }
  #sidebar { width: auto; flex: none; height: auto; position: static; display: flex; gap: 4px; overflow-x: auto; padding: 8px; }
  #sidebar .brand { display: none; }
  #sidebar a { white-space: nowrap; }
  #main { padding: 16px 12px 60px; }
}

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.page-head .tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.error { border-color: var(--bad); color: var(--bad); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.note { background: var(--info-bg); color: var(--info); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi b { display: block; font-size: 24px; line-height: 1.1; }
.kpi span { color: var(--muted); font-size: 12.5px; }

.tbl-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
td.wrap, th.wrap { white-space: normal; min-width: 180px; }
th { background: #f8f9fc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tr.dim td { color: var(--muted); }
td.num, th.num { text-align: right; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; margin-right: 4px; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-purple { background: var(--purple-bg); color: var(--purple); }
.b-gray { background: var(--gray-bg); color: var(--muted); }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.leave-card { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; }
.leave-card .who { font-weight: 700; }
.leave-card .actions { display: flex; gap: 8px; }
@media (max-width: 640px) { .leave-card { grid-template-columns: 1fr; } }

.modal-back { position: fixed; inset: 0; background: rgba(15, 22, 40, .5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 14px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal.wide { max-width: 760px; }
.modal-head { padding: 16px 20px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 14px 20px; }
.modal-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-error { color: var(--bad); background: var(--bad-bg); border-radius: 8px; padding: 8px 10px; margin: 0 20px 6px; display: none; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); }
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.photos figure { margin: 0; text-align: center; }
.photos img { width: 100%; max-height: 360px; object-fit: contain; border-radius: 10px; background: #eef1f7; }
.photos figcaption { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
@media (max-width: 640px) { .photos { grid-template-columns: 1fr; } }
.copybox { background: #f4f6fa; border: 1px dashed #b8c2d9; border-radius: 8px; padding: 10px; word-break: break-all; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; margin: 8px 0; }

#toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1b2437; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: 360px; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }

.dows { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.dows label { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-weight: 500; }
.legend { color: var(--muted); font-size: 12.5px; margin-top: 10px; line-height: 1.7; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 4px 12px; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; } }
