:root {
  --primary: #3750ff;
  --primary-dark: #2336d6;
  --primary-soft: #eef1ff;
  --primary-ink: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --bg: #f5f6fa;
  --card: #ffffff;
  --border: #e5e7eb;
  --ok: #16a34a;
  --danger: #dc2626;
  --shadow: 0 10px 30px -18px rgba(17, 24, 39, .25);
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(55, 80, 255, .18), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, rgba(55, 80, 255, .10), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 34px 32px 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { width: 72px; height: 72px; object-fit: contain; margin: 0 auto 14px; display: block; }
.login-card h1 { font-size: 26px; letter-spacing: -.02em; }
.login-sub { color: var(--muted); font-size: 13px; margin: 4px 0 22px; }
.login-card form { text-align: left; }
.login-card label { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin: 0 0 5px 2px; text-transform: uppercase; letter-spacing: .06em; }
.login-card input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0 12px;
  margin-bottom: 14px;
  outline: none;
  background: #fbfbfd;
  transition: border-color .2s, background .2s;
}
.login-card input:focus { border-color: var(--primary); background: #fff; }
.login-card .btn { width: 100%; margin-top: 4px; }
.login-error { color: var(--danger); font-size: 12.5px; min-height: 18px; margin-top: 10px; text-align: center; }
.login-foot { color: var(--muted-2); font-size: 11px; margin-top: 18px; }

/* App */
.app { display: flex; min-height: 100dvh; }
.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; border-bottom: 1px solid var(--border); }
.brand img { width: 36px; height: 36px; object-fit: contain; }
.brand strong { display: block; font-size: 16px; letter-spacing: -.02em; }
.brand span { display: block; font-size: 10.5px; color: var(--muted-2); }
.nav { padding: 12px 10px 24px; overflow-y: auto; flex: 1; }
.nav-group {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 16px 10px 6px;
}
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #374151;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary-dark); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 64px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-title { min-width: 0; margin-right: auto; }
.topbar-title h1 { font-size: 17px; letter-spacing: -.02em; }
.topbar-title span { font-size: 12px; color: var(--muted); }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.content { padding: 24px 22px 40px; }

.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover { background: #f3f4f6; }
#menuToggle { display: none; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 12.5px; border-radius: 7px; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
}
.card-label { font-size: 10.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); }
.card-value { font-size: 26px; font-weight: 800; letter-spacing: -.03em; margin-top: 6px; }
.card-note { font-size: 12px; color: var(--muted); margin-top: 4px; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 15px; margin-right: auto; }
.panel-body { padding: 16px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #f1f2f5; white-space: nowrap; }
th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); background: #fafbfc; position: sticky; top: 0; }
tbody tr:hover { background: #f8f9fc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 30px; text-align: center; color: var(--muted); font-size: 13px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type="search"], .toolbar input[type="date"] {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  outline: none;
}
.toolbar input:focus { border-color: var(--primary); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  width: min(680px, 100%);
  max-height: 90dvh;
  background: #fff;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.45);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-body .field { display: flex; flex-direction: column; gap: 4px; }
.modal-body .field.full { grid-column: 1 / -1; }
.modal-body label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.modal-body input, .modal-body textarea {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  outline: none;
}
.modal-body textarea { height: 76px; padding: 8px 10px; resize: vertical; }
.modal-body input:focus, .modal-body textarea:focus { border-color: var(--primary); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); }

/* Menu tree */
.tree { font-size: 13px; }
.tree details { margin: 2px 0; }
.tree summary { cursor: pointer; padding: 5px 4px; font-weight: 600; }
.tree summary:hover { color: var(--primary-dark); }
.tree .leaf { padding: 4px 4px 4px 22px; color: var(--muted); }
.tree .leaf:hover { color: var(--primary-dark); }

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #111827;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }

@media (max-width: 980px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  #menuToggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 20px 0 60px -30px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: none; }
  .content { padding: 16px 14px 30px; }
  .topbar { padding: 0 14px; }
  .cards { grid-template-columns: 1fr; }
  .modal-body { grid-template-columns: 1fr; }
}
