:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #142033;
  --muted: #64748b;
  --line: #dbe2ea;
  --blue: #0b63ce;
  --blue-strong: #084a9b;
  --green: #098768;
  --red: #c43b48;
  --amber: #a86507;
  --shadow: 0 20px 55px rgba(15, 23, 42, .09);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(11,99,206,.10), transparent 38%),
    var(--bg);
}

.login-screen.authenticated {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-card img.login-logo {
  display: block;
  width: 320px;
  max-width: 100%;
  height: auto;
  max-height: 92px;
  object-fit: contain;
  margin: 4px auto 8px;
}

.login-card form {
  display: grid;
  gap: 14px;
}

.login-card h1 {
  font-size: 24px;
}

.restricted-title {
  color: var(--red);
}

.login-card .otp-group {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.login-card .otp-group input {
  flex: 0 0 48px;
  width: 48px;
  height: 56px;
  min-height: 56px;
  padding: 0;
  text-align: center;
  font-size: 24px;
  font-weight: 850;
  line-height: 1;
}

.full-button {
  width: 100%;
}

.link-button {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 850;
}

.admin-app {
  min-height: 100vh;
  display: none;
  grid-template-columns: 238px minmax(0, 1fr);
}

.admin-app.unlocked {
  display: grid;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: #fff;
  overflow-y: auto;
}

.brand {
  min-height: 70px;
  display: flex;
  align-items: center;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.brand img {
  width: 190px;
  max-width: 100%;
  max-height: 52px;
  object-fit: contain;
}

#nav {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.nav-section {
  margin: 20px 0 8px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.nav-btn {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #334155;
  font-weight: 760;
  text-align: left;
}

.nav-btn.active {
  color: #062657;
  background: #dfe8f5;
}

.nav-spacer {
  flex: 1;
  min-height: 18px;
}

.logout-btn {
  margin-top: auto;
  color: var(--red);
}

.logout-btn .nav-icon {
  color: var(--red);
}

.nav-icon {
  width: 18px;
  height: 18px;
  color: #64748b;
}

main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.15; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
p, .subtitle { color: var(--muted); }

.top-actions, .split {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary, .ghost, .icon-btn, .danger {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  font-weight: 850;
}

.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.primary:hover { background: var(--blue-strong); }
.ghost:hover, .icon-btn:hover { background: #f1f5f9; }

.danger {
  border-color: rgba(196, 59, 72, .2);
  background: rgba(196, 59, 72, .1);
  color: var(--red);
}

.icon-btn {
  width: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.content { padding: 18px; }

.kpi {
  min-height: 128px;
  display: grid;
  align-content: space-between;
  gap: 12px;
}

.kpi .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.kpi strong {
  font-size: 28px;
  line-height: 1;
}

.kpi .trend {
  font-size: 12px;
  color: var(--muted);
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.filters {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
}

input, select, textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 92px;
  padding-top: 10px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(11, 99, 206, .55);
  box-shadow: 0 0 0 4px rgba(11, 99, 206, .1);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

th, td {
  padding: 12px 13px;
  border-bottom: 1px solid rgba(15, 23, 42, .08);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  background: #f8fafc;
}

tr:last-child td { border-bottom: 0; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475569;
  font-size: 12px;
  font-weight: 850;
}

.pill.ok { background: rgba(9, 135, 104, .12); color: var(--green); }
.pill.warn { background: rgba(168, 101, 7, .13); color: var(--amber); }
.pill.bad { background: rgba(196, 59, 72, .12); color: var(--red); }

.activity-list {
  display: grid;
  gap: 10px;
}

.activity {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.activity-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #edf5ff;
  color: var(--blue);
  font-weight: 900;
}

.form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.full { grid-column: 1 / -1; }

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(15, 23, 42, .42);
  z-index: 20;
}

.modal.open { display: flex; }

.dialog {
  width: min(760px, 100%);
  max-height: 92vh;
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .22);
}

.dialog-head {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

#modalBody {
  padding: 18px;
}

.dialog-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  display: none;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 8px;
  background: rgba(15, 23, 42, .92);
  color: #fff;
  font-weight: 760;
  z-index: 30;
}

.toast.show { display: block; }

@media (max-width: 980px) {
  .admin-app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
  }
  main { padding: 18px; }
  .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .topbar, .toolbar { align-items: flex-start; flex-direction: column; }
  .top-actions, .filters, .split { width: 100%; }
  .top-actions button, .filters label, .filters button { flex: 1 1 160px; }
  .form { grid-template-columns: 1fr; }
}
