:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dbe3ef;
  --text: #171b26;
  --muted: #667085;
  --blue: #3867f4;
  --blue-dark: #244bd6;
  --blue-soft: #edf2ff;
  --red: #d92d20;
  --red-soft: #fff1f0;
  --yellow: #b7791f;
  --yellow-soft: #fff8df;
  --shadow: 0 18px 45px rgba(22, 34, 58, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 14px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
}

button:hover { background: #eef3fb; }
button:disabled { cursor: not-allowed; opacity: 0.6; }
button.primary, .primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 10px 24px rgba(56, 103, 244, 0.22);
}
button.primary:hover, .primary:hover { background: var(--blue-dark); }
button.secondary, .secondary { background: #fff; border: 1px solid var(--line); color: var(--text); }
button.danger, .danger { color: var(--red); border-color: #f4c7c3; background: var(--red-soft); }

input, select, textarea {
  width: 100%;
  border: 1px solid #cfd8e6;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: 0;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(56, 103, 244, 0.12);
}

[hidden] { display: none !important; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: 10px 0 30px rgba(22, 34, 58, 0.04);
  overflow-y: auto;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

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

.side-brand strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.side-brand span:last-child {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.side-nav button {
  justify-content: flex-start;
  width: 100%;
  border: 0;
  background: transparent;
  color: #667085;
  text-align: left;
  box-shadow: none;
}

.side-nav button.active {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 10px 22px rgba(56, 103, 244, 0.2);
}

.app-main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 28px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 4px !important;
  color: var(--blue) !important;
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.session-badge, .build-badge, .ui-version, .pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.ui-version { background: #f1f5f9; color: #64748b; }

.settings-menu {
  position: relative;
}

.settings-menu summary {
  list-style: none;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  font-weight: 800;
  cursor: pointer;
}

.settings-menu summary::-webkit-details-marker { display: none; }

.settings-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: min(420px, calc(100vw - 32px));
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
}

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

.settings-field {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.layout {
  display: grid;
  gap: 18px;
  padding: 22px 28px 36px;
}

.login-panel {
  padding: 48px 28px;
}

.login-card {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(300px, 1.1fr);
  gap: 24px;
  max-width: 920px;
  margin: 0 auto;
  padding: 26px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-copy h2 { margin: 6px 0; font-size: 28px; }
.login-copy p { margin: 0; color: var(--muted); line-height: 1.5; }
.login-kicker { color: var(--blue); font-size: 12px; font-weight: 850; text-transform: uppercase; }

.login-grid {
  display: grid;
  gap: 12px;
  align-content: start;
}

.login-grid label, .form-body label, .compact-form-body label, .runtime-grid label {
  display: grid;
  gap: 7px;
  color: #475467;
  font-size: 12px;
  font-weight: 800;
}

.login-error {
  grid-column: 1 / -1;
  border: 1px solid #fecaca;
  background: var(--red-soft);
  color: #b42318;
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 800;
}

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

.metric, .metrics article {
  min-height: 104px;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 12px 25px rgba(22, 34, 58, 0.05);
}

.metric:first-child {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.metric span, .metrics span {
  display: block;
  color: inherit;
  opacity: 0.72;
  font-size: 12px;
  font-weight: 850;
}

.metric strong, .metrics strong {
  display: block;
  margin-top: 12px;
  font-size: 28px;
  line-height: 1;
}

.metric.urgent { background: var(--red-soft); border-color: #fecaca; }
.metric.warn { background: var(--yellow-soft); border-color: #fde68a; }

.view { display: none; }
.view.active { display: block; }

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(22, 34, 58, 0.05);
  overflow: hidden;
}

.panel + .panel { margin-top: 16px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2, .panel-head h3, .panel-head h4 {
  margin: 0;
  font-size: 18px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.runtime-grid, .form-body, .compact-form-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 20px;
}

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

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

.inline-check {
  display: flex !important;
  align-items: center;
  gap: 10px !important;
}

.inline-check input {
  width: auto;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}

.content-grid, .editor-grid, .assignment-tables {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(360px, 1fr);
  gap: 18px;
}

.left-stack {
  min-width: 0;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: #667085;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 850;
}

.card-list, .alert-list, #centralRows, #personaRows, #assignmentRows {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.card, .record-card, .alert-card, .assignment-card, .device-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.card h3, .record-card h3, .alert-card h3 { margin: 0 0 6px; }
.muted, small { color: var(--muted); }

.assignment-layout {
  display: grid;
  gap: 18px;
}

.assignment-stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  padding: 18px 20px;
}

.assignment-stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.assignment-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.assignment-stats strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

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

.selfie-manager {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 16px;
}

.selfie-manager-head, .selfie-editor-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.selfie-manager h3, .selfie-manager h4 { margin: 0; }
.selfie-manager p { margin: 4px 0 0; color: var(--muted); }

.selfie-workspace {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
  margin-top: 14px;
}

.selfie-strip, .selfie-editor-grid {
  display: grid;
  gap: 12px;
}

.selfie-editor-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.selfie-editor-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.image-preview {
  min-height: 120px;
  border: 1px dashed #cfd8e6;
  border-radius: 8px;
  background: #fff;
}

.file-note { color: var(--muted); font-size: 12px; }
.selfie-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

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

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }
  .side-nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .side-nav button { width: auto; }
  .summary-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid, .editor-grid, .assignment-tables { grid-template-columns: 1fr; }
  .runtime-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
  }
  .top-actions { justify-content: flex-start; }
  .layout { padding: 16px; }
  .summary-band, .metrics, .runtime-grid, .form-body, .compact-form-body, .assignment-forms, .assignment-stats, .selfie-workspace, .selfie-editor-grid, .login-card {
    grid-template-columns: 1fr;
  }
  .settings-popover {
    left: 0;
    right: auto;
  }
}
