:root {
  --bg: #f5f6fa; --surface: #ffffff; --surface-2: #f0f2f7; --border: #e3e6ee;
  --text: #171a26; --muted: #646b80; --accent: #4f46e5; --accent-soft: #eef0ff; --accent-text: #3f37c9;
  --green: #12805c; --green-soft: #e3f6ee; --red: #c4302b; --red-soft: #fdeceb;
  --amber: #a15c07; --amber-soft: #fff4e0; --blue: #1f6fd1; --blue-soft: #e6f0fd;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 1px 8px rgba(20, 24, 40, .04);
  --radius: 12px; --sidebar: 248px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117; --surface: #171a23; --surface-2: #1e2230; --border: #2a2f3e;
    --text: #e8eaf1; --muted: #9399ad; --accent: #7c74ff; --accent-soft: #24234a; --accent-text: #b3aeff;
    --green: #4cc79a; --green-soft: #133227; --red: #ff7b72; --red-soft: #3a1a1a;
    --amber: #f0b44c; --amber-soft: #36290f; --blue: #6fb0ff; --blue-soft: #15263d;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.5; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14.5px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; font-weight: 800; }
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); }
.nav { padding: 6px 10px; flex: 1; overflow-y: auto; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.nav .ico { width: 20px; text-align: center; }
.nav .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.sidebar-user { border-top: 1px solid var(--border); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.sidebar-user .who { flex: 1; min-width: 0; }
.sidebar-user .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; }
.main { flex: 1; min-width: 0; padding: 24px 32px 48px; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.stat .hint { font-size: 12.5px; color: var(--muted); }
.stat.danger .value { color: var(--red); }
.stat.ok .value { color: var(--green); }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; font-size: 13.5px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.new { background: var(--blue-soft); color: var(--blue); }
.badge.in_progress { background: var(--amber-soft); color: var(--amber); }
.badge.review { background: var(--accent-soft); color: var(--accent-text); }
.badge.done, .badge.approved, .badge.submitted { background: var(--green-soft); color: var(--green); }
.badge.returned, .badge.overdue, .badge.missing, .badge.urgent { background: var(--red-soft); color: var(--red); }
.badge.high { background: var(--amber-soft); color: var(--amber); }
.badge.low { background: var(--surface-2); color: var(--muted); }
.badge.normal { display: none; }
.badge.submitted { background: var(--blue-soft); color: var(--blue); }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12.5px; flex-shrink: 0; }
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person .meta { min-width: 0; }
.person .meta b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .meta span { color: var(--muted); font-size: 12.5px; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; color: var(--text); }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* Forms */
.form { max-width: 720px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13.5px; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.field .error, .errorlist { color: var(--red); font-size: 12.5px; margin: 4px 0 0; padding: 0; list-style: none; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.field.checkbox label { display: flex; gap: 8px; align-items: center; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters input, .filters select { width: auto; min-width: 160px; }
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 13px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.messages { margin-bottom: 16px; }
.msg { padding: 10px 14px; border-radius: 10px; background: var(--green-soft); color: var(--green); font-weight: 500; margin-bottom: 8px; }
.msg.error { background: var(--red-soft); color: var(--red); }
.msg.info { background: var(--blue-soft); color: var(--blue); }

/* Kanban */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 300px; }
.column.drop { outline: 2px dashed var(--accent); }
.column-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; font-weight: 700; }
.tcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.tcard:active { cursor: grabbing; }
.tcard.dragging { opacity: .5; }
.tcard a.t { color: var(--text); font-weight: 600; display: block; margin-bottom: 8px; }
.tcard .row { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12.5px; color: var(--muted); }
.tcard.overdue { border-left: 3px solid var(--red); }
.due.late { color: var(--red); font-weight: 600; }

/* Org */
.dep-block { border-left: 4px solid var(--accent); }
.dep-children { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); margin-top: 14px; }
.sub-dep { background: var(--surface-2); border-radius: 10px; padding: 14px; }
.people { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.people a:hover { text-decoration: none; }
.people a:hover b { color: var(--accent-text); }

/* Services */
.service { display: flex; gap: 14px; align-items: flex-start; color: var(--text); }
.service:hover { text-decoration: none; border-color: var(--accent); }
.service .ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; flex-shrink: 0; }
.service b { display: block; font-size: 15px; }
.service .url { color: var(--accent-text); font-size: 12.5px; }

/* Comments */
.comment { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: 0; }
.comment .body { flex: 1; min-width: 0; white-space: pre-wrap; word-wrap: break-word; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.desc { white-space: pre-wrap; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; padding: 0 0 18px; font-size: 20px; }

.notif { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); color: var(--text); }
.notif.unread b::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 8px; vertical-align: middle; }

/* Responsive */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; }
  .backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .topbar .brand { padding: 0; }
  .topbar .spacer { flex: 1; }
  .main { padding: 18px 16px 40px; }
  .g2, .g3, .g4, .g-main, .form-row { grid-template-columns: minmax(0, 1fr); }
  .stat-row.g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board { grid-template-columns: repeat(4, minmax(250px, 82vw)); }
  .kv { grid-template-columns: 110px 1fr; }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
}
.filters input[type=checkbox] { min-width: 0; width: 16px; flex: none; }
