:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #172033;
  --muted: #667085;
  --border: #d7dde8;
  --primary: #1f6feb;
  --primary-strong: #185abc;
  --success: #157f3b;
  --warning: #b7791f;
  --danger: #c2410c;
  --info: #0f766e;
  --shadow: 0 18px 50px rgba(16, 24, 40, .08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --surface: #182233;
  --surface-2: #223047;
  --text: #eef4ff;
  --muted: #a8b3c7;
  --border: #334155;
  --primary: #6aa7ff;
  --primary-strong: #8bbaff;
  --success: #54c67a;
  --warning: #f4b350;
  --danger: #ff8a65;
  --info: #5eead4;
  --shadow: 0 18px 50px rgba(0, 0, 0, .26);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

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

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

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

label input,
label select,
label textarea {
  color: var(--text);
  font-weight: 500;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 22px 16px;
}

.brand,
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1f6feb, #14b8a6);
  color: white;
  font-weight: 900;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 28px;
}

.nav a {
  display: block;
  border-radius: 8px;
  color: var(--muted);
  padding: 10px 12px;
  font-weight: 700;
}

.nav a.active,
.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav-section {
  display: block;
  margin: 10px 12px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav a.nav-child {
  margin-left: 14px;
  padding-left: 18px;
  border-left: 2px solid var(--border);
}

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

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

.topbar h1,
.content-panel h2,
.profile-header h2 {
  margin: 0;
}

.topbar-actions,
.button-row,
.profile-actions,
.actions-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.user-chip {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--muted);
  background: var(--surface);
}

.summary-grid,
.panel-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.quick-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.summary-tile,
.metric-panel,
.content-panel,
.profile-header {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-tile,
.metric-panel {
  padding: 16px;
}

.summary-tile p,
.metric-panel span {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-tile strong,
.metric-panel strong {
  display: block;
  font-size: 24px;
  line-height: 1.15;
}

.metric-panel a {
  display: inline-block;
  margin-top: 8px;
  font-weight: 800;
}

.content-panel {
  padding: 16px;
  margin-bottom: 16px;
}

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

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

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

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

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}

td {
  color: var(--text);
}

.nested-table {
  min-width: 660px;
}

.nested-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-2) 40%, transparent);
  padding: 12px;
}

.nested-block h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.expand-row {
  display: none;
}

.expand-row.open {
  display: table-row;
}

.form-drawer {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 12px 0;
  background: color-mix(in srgb, var(--surface-2) 38%, transparent);
}

.form-drawer summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 800;
}

.form-grid,
.inline-grid {
  display: grid;
  gap: 12px;
}

.form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 0 14px 14px;
}

.inline-grid {
  grid-template-columns: 1.3fr 1.5fr .7fr .8fr .9fr auto;
  align-items: end;
  margin-top: 12px;
}

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

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.stack {
  display: grid;
  gap: 12px;
}

.primary-button,
.ghost-button,
.danger-button,
.tiny-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover {
  background: var(--primary-strong);
  text-decoration: none;
}

.ghost-button,
.tiny-button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.ghost-button:hover,
.tiny-button:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.danger-button {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.tiny {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.full {
  width: 100%;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge-success {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 14%, transparent);
}

.badge-warning {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 16%, transparent);
}

.badge-danger {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

.badge-muted {
  color: var(--muted);
  background: var(--surface-2);
}

.badge-info,
.badge-neutral {
  color: var(--info);
  background: color-mix(in srgb, var(--info) 13%, transparent);
}

.flash {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-weight: 700;
}

.flash-success {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 13%, transparent);
}

.flash-error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 13%, transparent);
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

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

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 22px;
}

.login-card {
  width: min(440px, 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-brand {
  margin-bottom: 20px;
}

.login-brand h1,
.login-brand p {
  margin: 0;
}

.login-brand p {
  color: var(--muted);
}

.row-logo,
.row-photo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.row-photo {
  border-radius: 50%;
}

.avatar-dot {
  display: inline-block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #94a3b8, #14b8a6);
}

.password-mask {
  display: inline-block;
  min-width: 72px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.eye-icon,
.theme-icon,
.plus-icon {
  position: relative;
  display: inline-block;
}

.eye-icon {
  width: 18px;
  height: 11px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.eye-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.plus-icon {
  width: 14px;
  height: 14px;
}

.plus-icon::before,
.plus-icon::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 2px;
}

.plus-icon::before {
  width: 14px;
  height: 2px;
  top: 6px;
}

.plus-icon::after {
  width: 2px;
  height: 14px;
  left: 6px;
}

.theme-icon {
  width: 17px;
  height: 17px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.theme-icon::after {
  content: "";
  position: absolute;
  right: -2px;
  top: -2px;
  width: 9px;
  height: 18px;
  background: var(--surface);
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

.profile-photo {
  width: 74px;
  height: 74px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.profile-photo.placeholder {
  display: inline-block;
  background: linear-gradient(135deg, #64748b, #0ea5e9);
}

.profile-actions {
  margin-left: auto;
}

.chart {
  width: 100%;
  max-height: 260px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-2) 28%, transparent);
  margin: 8px 0 16px;
}

.score-pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  color: var(--muted);
  font-weight: 800;
}

.kpi-form {
  gap: 16px;
}

.scale-help {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.scale-help span {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.kpi-category {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.category-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
}

.category-title h3 {
  margin: 0;
  font-size: 15px;
}

.kpi-table {
  min-width: 980px;
}

.kpi-table th:not(:first-child),
.kpi-table td:not(:first-child) {
  width: 46px;
  text-align: center;
}

.kpi-table input[type="radio"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 16px;
  }

  .summary-grid,
  .panel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

@media (max-width: 700px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .panel-title,
  .profile-header {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-actions {
    margin-left: 0;
  }

  .nav,
  .summary-grid,
  .panel-grid,
  .form-grid,
  .inline-grid,
  .scale-help {
    grid-template-columns: 1fr;
  }

  .summary-tile strong,
  .metric-panel strong {
    font-size: 21px;
  }

  .topbar-actions,
  .button-row,
  .actions-cell {
    width: 100%;
  }

  .button-row > *,
  .topbar-actions > form,
  .topbar-actions button,
  .actions-cell > * {
    flex: 1 1 auto;
  }
}
