:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef3f5;
  --ink: #172024;
  --muted: #66737a;
  --line: #dbe2e5;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --warn: #b76e00;
  --ok: #147d3f;
  --shadow: 0 10px 28px rgba(24, 36, 42, 0.08);
}

* { box-sizing: border-box; }

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

body:not(.authenticated) .sidebar,
body:not(.authenticated) .shell {
  display: none;
}

body.authenticated .auth-screen {
  display: none;
}

.auth-screen {
  grid-column: 1 / -1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(140deg, #102326 0%, #20484b 46%, #f6f7f9 46%);
}

.auth-panel {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 18px;
  align-items: start;
  padding: 22px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-brand {
  grid-column: 1 / -1;
  color: var(--ink);
}

.auth-form {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-form h1,
.auth-form h2 {
  margin-bottom: 4px;
}

.secondary-auth {
  background: #f8fbfb;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 18px;
  background: #102326;
  color: #f3fbfa;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #d8f3ef;
  color: #0d5f59;
  font-weight: 800;
}

.brand strong { display: block; font-size: 18px; }
.brand small { color: #a9c3c0; }

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: #dbeceb;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #1d3a3e;
  color: #ffffff;
}

.sidebar-status {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #b7d1ce;
  font-size: 13px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--warn);
}

.status-dot.online { background: #39b56a; }

.shell {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  min-height: 42px;
  display: grid;
  justify-content: end;
  gap: 2px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.user-chip strong,
.user-chip span {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip span {
  color: var(--muted);
  font-size: 12px;
}

.admin-only {
  display: none;
}

body.platform-admin .admin-only {
  display: block;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 { font-size: 30px; }
h2 { font-size: 18px; }

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 22px;
}

.view { display: none; }
.view.active { display: grid; gap: 18px; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

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

.metric {
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 26px;
  line-height: 1.15;
}

.two-column,
.work-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.agenda-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

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

.inline-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.inline-form:last-child { border-bottom: 0; }

.span-2 { grid-column: span 2; }

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

input, select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
}

input:focus, select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--accent);
}

.primary,
form button,
.row-action {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  white-space: nowrap;
}

.primary:hover,
form button:hover,
.row-action:hover {
  background: var(--accent-strong);
}

.row-action.secondary {
  background: var(--surface-soft);
  color: var(--ink);
}

.row-action.danger {
  background: #fbe9e7;
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f8fbfb;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.badge.ok { background: #e7f7ed; color: var(--ok); }
.badge.warn { background: #fff4df; color: var(--warn); }
.badge.danger { background: #fbe9e7; color: var(--danger); }

.empty {
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #102326;
  color: #ffffff;
  box-shadow: var(--shadow);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1100px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow: auto;
  }
  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
  }
  .sidebar-status { margin-top: 0; margin-left: auto; }
  .metrics-grid,
  .two-column,
  .work-grid,
  .agenda-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .shell { padding: 16px; }
  .sidebar { padding: 14px; }
  .brand small, .sidebar-status { display: none; }
  .metrics-grid,
  .two-column,
  .work-grid,
  .agenda-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
  .span-2 { grid-column: auto; }
  .inline-form { grid-template-columns: 1fr; }
  .auth-panel { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .user-chip { justify-content: start; }
  h1 { font-size: 24px; }
}
