:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1a2332;
  --text-muted: #5b6b80;
  --primary: #d92b2b;
  --primary-dark: #b71f1f;
  --primary-soft: #fdecec;
  --navy: #16233a;
  --navy-2: #1f3254;
  --accent: #2f7bd9;
  --green: #1f9d55;
  --green-soft: #e6f6ed;
  --amber: #b7791f;
  --amber-soft: #fdf3e0;
  --red-soft: #fdecec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #16233a 0%, #1f3254 55%, #2a4168 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 36px 34px; width: 100%; max-width: 400px;
}
.login-badge { font-size: 46px; text-align: center; }
.login-card h1 { text-align: center; font-size: 24px; margin-top: 4px; }
.login-card .muted { text-align: center; margin: 4px 0 24px; }
.login-card label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--surface-2);
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,123,217,.15); }
.login-card .btn { margin-top: 20px; }
.hint { margin-top: 16px; font-size: 12px; color: var(--text-muted); text-align: center; background: var(--surface-2); padding: 8px; border-radius: 8px; }
.error-text { color: var(--primary); font-size: 13px; min-height: 18px; margin: 10px 0 0; text-align: center; }

/* ---------- Shell ---------- */
.app-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy); color: #cdd8ea; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-icon { font-size: 28px; }
.brand-name { font-weight: 700; color: #fff; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: #8fa1bf; }
.nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px;
  color: #cdd8ea; cursor: pointer; font-weight: 500; margin-bottom: 2px; border: none; background: none; width: 100%; font-size: 13.5px; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .nav-ico { font-size: 17px; width: 22px; text-align: center; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer .btn-ghost {
  background: rgba(255,255,255,0.10);
  color: #fff;
  border-color: rgba(255,255,255,0.25);
}
.sidebar-footer .btn-ghost:hover {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border-color: rgba(255,255,255,0.35);
}
.user-chip { font-size: 12.5px; padding: 8px 10px; background: rgba(255,255,255,.06); border-radius: 8px; margin-bottom: 10px; }
.user-chip .role { color: #8fa1bf; font-size: 11px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 26px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 19px; }
.page-sub { font-size: 12.5px; color: var(--text-muted); }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.content { padding: 24px 26px 60px; max-width: 1280px; width: 100%; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } .app-shell { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h3 { font-size: 14.5px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h3 { margin-bottom: 0; }
.card .link { font-size: 12.5px; color: var(--accent); cursor: pointer; text-decoration: none; }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat .stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .stat-value { font-size: 26px; font-weight: 750; margin-top: 2px; }
.stat .stat-foot { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; cursor: pointer; border: 1px solid transparent; transition: background .12s, border-color .12s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #2667b3; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--primary); border-color: #f3c4c4; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--text-muted); padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: 9px 12px; border-bottom: 2px solid var(--border); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.tbl a.row-link { color: var(--navy); font-weight: 600; cursor: pointer; text-decoration: none; }
.tbl a.row-link:hover { color: var(--primary); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--primary); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: #e8f1fb; color: var(--accent); }
.badge.gray { background: #eef1f5; color: var(--text-muted); }
.badge.navy { background: #e7ebf3; color: var(--navy); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px;
  font-family: inherit; background: var(--surface-2); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,123,217,.12); background: #fff; }
.field textarea { resize: vertical; min-height: 72px; }
.field .help { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .search { flex: 1; min-width: 180px; max-width: 340px; position: relative; }
.toolbar input[type=search], .toolbar input[type=text], .toolbar select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; background: var(--surface); width: 100%;
}
.toolbar select { width: auto; }
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--accent); }
.toolbar .spacer { flex: 1; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .5); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 720px;
  animation: pop .16s ease;
}
.modal.wide { max-width: 980px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px 22px; }

/* ---------- Toast ---------- */
.toast-container { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: 13.5px; max-width: 380px; animation: slidein .2s ease;
}
.toast.success { background: #166534; }
.toast.error { background: #b91c1c; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty .big { font-size: 40px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 4px 16px; }
.kv dt { color: var(--text-muted); font-size: 12.5px; font-weight: 600; }
.kv dd { margin: 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 18px 0 10px; font-weight: 700; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 12px; margin: 2px 3px 2px 0; }
.chip .x { cursor: pointer; color: var(--text-muted); font-weight: 700; }
.checklist { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.checklist label { display: flex; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.checklist label:hover { background: var(--surface-2); }
.action-group { margin-bottom: 10px; }
.action-group .group-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 8px 0 4px; }
.action-group .chk { display: inline-flex; gap: 7px; align-items: center; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; margin: 2px 4px 2px 0; cursor: pointer; font-size: 12.5px; background: var(--surface-2); }
.action-group .chk:hover { border-color: var(--accent); background: #eef5fd; }
.action-group .chk input { accent-color: var(--accent); }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.bar-row .lbl { width: 120px; color: var(--text-muted); text-align: right; }
.bar-track { flex: 1; height: 16px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 8px; }
.bar-fill.accent { background: var(--accent); }
.bar-row .val { width: 40px; font-weight: 700; }
.file-drop {
  border: 2px dashed var(--border); border-radius: 12px; padding: 40px 20px; text-align: center; cursor: pointer;
  color: var(--text-muted); transition: border-color .15s, background .15s;
}
.file-drop:hover, .file-drop.dragover { border-color: var(--accent); background: #eef5fd; }
.file-drop .big { font-size: 38px; }
.code-block { background: var(--navy); color: #d7e3f5; border-radius: 10px; padding: 14px 16px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow: auto; }
.alert { border-radius: 10px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 12px; }
.alert.warn { background: var(--amber-soft); color: #7c5a10; border: 1px solid #f0dcae; }
.alert.info { background: #e8f1fb; color: #1d4f88; border: 1px solid #cfe2f6; }
.alert.good { background: var(--green-soft); color: #14663c; border: 1px solid #bfe6d0; }
