:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #162126;
  --muted: #68767d;
  --line: #dbe2e6;
  --primary: #087f8c;
  --primary-dark: #05606b;
  --accent: #d95d39;
  --ok: #26734d;
  --warn: #a96d00;
  --danger: #b42318;
  --shadow: 0 10px 28px rgba(22, 33, 38, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

body.locked .sidebar,
body.locked .app {
  display: none;
}

.login-view {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: var(--bg);
  z-index: 20;
}
body.locked .login-view {
  display: grid;
}
.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-size: 24px;
  margin-bottom: 4px;
}
.login-brand {
  color: var(--ink);
  margin-bottom: 6px;
}
.login-brand small {
  color: var(--muted);
}

button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}
button:hover { background: var(--primary-dark); }
button.secondary { background: #e7eef0; color: var(--ink); }
button.secondary:hover { background: #d6e1e5; }
button.danger { background: var(--danger); }
button.small { padding: 6px 9px; font-size: 13px; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #11292f;
  color: white;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #d95d39;
  font-size: 26px;
  font-weight: 800;
}
.brand small {
  display: block;
  color: #b9c8cc;
  margin-top: 2px;
}
nav {
  display: grid;
  gap: 8px;
}
.nav-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #dce7ea;
  font-weight: 650;
}
.nav-btn:hover, .nav-btn.active {
  background: #21444c;
  color: white;
}

.app {
  min-width: 0;
  padding: 24px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; margin-bottom: 14px; }
.topbar p { color: var(--muted); margin-top: 4px; }
.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-weight: 700;
}

.view { display: none; }
.view.active { display: block; }
.grid {
  display: grid;
  gap: 18px;
}
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-list { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
.panel, .metrics article, .filters {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel { padding: 18px; margin-bottom: 18px; }
.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(135px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metrics article { padding: 16px; }
.metrics span {
  display: block;
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 4px;
}
.metrics small, .muted { color: var(--muted); }

.form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-self: start;
}
.form h2, .form .full, .form button { grid-column: 1 / -1; }
label {
  display: grid;
  gap: 6px;
  color: #415057;
  font-size: 13px;
  font-weight: 700;
}
input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: white;
}
textarea { resize: vertical; }
.search { max-width: 280px; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.section-head h2 { margin-bottom: 0; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
th, td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  color: #4c5c63;
  font-size: 12px;
  text-transform: uppercase;
}
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  background: #e7eef0;
  color: #30434a;
}
.badge.ok { background: #dff2e8; color: var(--ok); }
.badge.warn { background: #fff0cf; color: var(--warn); }
.badge.danger { background: #fee4e2; color: var(--danger); }

.alerts {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}
.alert {
  border-left: 4px solid var(--accent);
  background: #fff7ed;
  padding: 11px 13px;
  border-radius: 6px;
  color: #704214;
  font-weight: 700;
}
.history-empty, .empty {
  color: var(--muted);
  padding: 12px 0;
}
.history-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.history-item strong { display: block; margin-bottom: 4px; }

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 14px;
  padding: 16px;
  margin-bottom: 18px;
}
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  background: #11292f;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }
  nav {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .form-list, .grid.two { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .app { padding: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions, .topbar-actions button, .topbar-actions select { width: 100%; }
  nav { grid-template-columns: 1fr 1fr; }
  .metrics, .filters, .form { grid-template-columns: 1fr; }
  h1 { font-size: 24px; }
}
