:root {
  color-scheme: light;
  --color-coral: #e26d5c;
  --color-coral-deep: #c95340;
  --color-slate: #3d495b;
  --color-slate-deep: #2a3341;
  --color-sand: #ffe1a8;
  --color-sage: #c9cba3;
  --ink: #1f2733;
  --muted: #55606f;
  --muted-faint: #8a93a0;
  --line: #e6e3dc;
  --line-strong: #c9c4b8;
  --surface: #ffffff;
  --surface-soft: #f3f1ec;
  --page: #fbfaf7;
  --primary: var(--color-slate);
  --primary-hover: var(--color-slate-deep);
  --accent: var(--color-coral);
  --accent-hover: var(--color-coral-deep);
  --accent-soft: rgba(226, 109, 92, 0.12);
  --success: #4a5a36;
  --success-soft: rgba(201, 203, 163, 0.35);
  --warning: #8a5a08;
  --warning-soft: #fff3c4;
  --info: var(--color-slate);
  --info-soft: #edf0f4;
  --shadow: 0 10px 28px rgba(31, 39, 51, 0.1);
  font-family: "Cabin", "Segoe UI", Arial, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; stroke-width: 1.8; flex: 0 0 auto; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: 224px;
  flex-direction: column;
  border-top: 4px solid var(--accent);
  padding: 18px 14px 20px;
  color: #fff;
  background: var(--primary-hover);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  padding: 0 7px;
}

.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { color: inherit; font-size: 15px; line-height: 1.2; }
.sidebar-brand span { margin-top: 3px; color: rgba(255, 255, 255, 0.62); font-size: 12px; }

.brand-logo {
  display: block;
  width: auto;
  height: 52px;
  flex: 0 0 auto;
  object-fit: contain;
}

.sidebar-nav { display: grid; gap: 4px; margin-top: 36px; }

.nav-item {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 11px;
  border: 0;
  border-radius: 5px;
  padding: 0 12px;
  color: rgba(255, 255, 255, 0.74);
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 650;
}

.nav-item:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.nav-item.active { color: #fff; background: var(--accent); }

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 16px 7px 0;
}

.user-label { overflow: hidden; color: rgba(255, 255, 255, 0.72); font-size: 13px; text-overflow: ellipsis; }
.sidebar-footer .icon-button { color: rgba(255, 255, 255, 0.72); }

.main-content { min-height: 100vh; margin-left: 224px; padding: 32px clamp(24px, 4vw, 58px) 56px; }
.mobile-header, .mobile-nav { display: none; }

.view { display: none; width: min(1420px, 100%); margin: 0 auto; }
.view.active { display: block; }

.page-heading {
  display: flex;
  min-height: 62px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; line-height: 1.15; font-weight: 760; }
h2 { margin-bottom: 4px; font-size: 16px; line-height: 1.3; }
p { color: var(--muted); }

.heading-actions, .week-controls, .dialog-actions { display: flex; align-items: center; gap: 8px; }

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { background: var(--primary-hover); }
.button-primary:disabled { cursor: wait; opacity: 0.65; }
.button-secondary { border-color: var(--line-strong); color: var(--ink); background: var(--surface); }
.button-secondary:hover { border-color: var(--accent); color: var(--accent-hover); }
.button-full { width: 100%; }

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
}

.icon-button:hover { color: var(--accent-hover); background: var(--accent-soft); }

.control-band {
  display: grid;
  grid-template-columns: 160px 160px minmax(190px, 1fr) minmax(170px, 1fr) auto;
  align-items: end;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  background: var(--surface);
}

label { display: grid; gap: 6px; min-width: 0; }
label > span { color: var(--muted); font-size: 11px; font-weight: 750; }

input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--ink);
  outline: none;
  background: #fff;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
  margin: 14px 0 24px;
}

.metric-card {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 15px;
  background: var(--surface);
}

.metric-card span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.metric-card strong { display: block; margin-top: 9px; font-size: 22px; line-height: 1; }
.metric-card small { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; }

.section-block { margin-top: 14px; border-top: 1px solid var(--line-strong); padding: 20px 0 8px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-heading p { margin-bottom: 0; font-size: 13px; }

.status-pill {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.status-neutral { color: var(--muted); background: var(--surface-soft); }
.status-success { color: var(--success); background: var(--success-soft); }
.status-warning { color: var(--warning); background: var(--warning-soft); }
.status-error { color: var(--accent-hover); background: var(--accent-soft); }

.diagnostics-list { display: grid; gap: 8px; }

.diagnostic {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 11px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 5px;
  padding: 12px 14px;
  background: var(--surface);
}

.diagnostic.blocker { border-left-color: var(--accent); }
.diagnostic.warning { border-left-color: #d59a2b; }
.diagnostic svg { margin-top: 1px; }
.diagnostic.blocker svg { color: var(--accent-hover); }
.diagnostic.warning svg { color: var(--warning); }
.diagnostic strong { display: block; margin-bottom: 3px; font-size: 13px; }
.diagnostic p { margin-bottom: 0; font-size: 12px; line-height: 1.45; }

.schedule-block { margin-top: 24px; }
.week-controls { font-size: 12px; font-weight: 750; }
.table-scroll { overflow-x: auto; }
.empty-panel { display: grid; min-height: 160px; place-items: center; color: var(--muted); font-size: 13px; }

.data-table, .schedule-table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 12px; }
.data-table th, .data-table td, .schedule-table th, .schedule-table td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; vertical-align: top; }
.data-table th, .schedule-table th { color: var(--muted); background: var(--surface-soft); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.data-table tbody tr:hover, .schedule-table tbody tr:hover { background: var(--surface-soft); }
.data-table input[type="number"] { width: 70px; min-height: 32px; padding: 4px 7px; }
.data-table input[type="text"] { min-width: 200px; min-height: 32px; padding: 4px 7px; }
.data-table select { min-height: 32px; padding: 4px 7px; }

.schedule-table { table-layout: fixed; min-width: 950px; }
.schedule-table th:first-child, .schedule-table td:first-child { position: sticky; left: 0; z-index: 2; width: 145px; background: var(--surface); }
.schedule-table thead th:first-child { background: var(--surface-soft); }
.schedule-person { font-weight: 760; }
.shift-entry { display: block; margin-bottom: 5px; border-left: 2px solid var(--accent); padding-left: 6px; line-height: 1.35; }
.shift-entry.sos { border-left-color: var(--info); }
.shift-entry small { display: block; color: var(--muted); }

.switch { position: relative; display: inline-block; width: 38px; min-width: 38px; height: 22px; flex: 0 0 38px; }
.switch input { width: 1px; height: 1px; opacity: 0; }
.switch-track { position: absolute; inset: 0; border-radius: 999px; background: #cbd4d1; transition: 0.15s ease; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.18); transition: 0.15s ease; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }

.role-badge { display: inline-flex; min-width: 54px; min-height: 24px; align-items: center; justify-content: center; border-radius: 3px; color: var(--info); background: var(--info-soft); font-size: 10px; font-weight: 850; }
.role-badge.class { color: var(--success); background: var(--success-soft); }

.workers-list { display: grid; gap: 10px; }
.worker-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.15fr) 120px 120px 115px minmax(260px, 2fr) 122px;
  align-items: end;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: var(--surface);
}
.worker-name-line { display: flex; align-items: center; gap: 8px; }
.worker-name-line input { font-weight: 760; }
.worker-state { display: flex; align-self: center; align-items: center; justify-content: flex-end; gap: 4px; }
.worker-state .switch { margin-right: 4px; }

.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.two-column .section-block { margin-top: 0; }
.inline-form { display: grid; grid-template-columns: 145px minmax(180px, 1fr) auto; align-items: end; gap: 10px; margin-bottom: 16px; }
.stack-form { display: grid; gap: 10px; margin-bottom: 16px; }
.form-row { display: flex; gap: 10px; }
.form-row > label { flex: 1 1 0; }
.form-row > .grow, .grow { flex-grow: 2; }
.record-list { display: grid; gap: 7px; }
.record-item { display: flex; min-height: 46px; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 7px 0; }
.record-item:last-child { border-bottom: 0; }
.record-item strong, .record-item span { display: block; }
.record-item strong { font-size: 12px; }
.record-item span { margin-top: 2px; color: var(--muted); font-size: 11px; }

dialog { width: min(560px, calc(100vw - 28px)); border: 0; border-radius: 7px; padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(42, 51, 65, 0.58); }
.dialog-form { display: grid; gap: 15px; padding: 22px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-heading h2 { margin: 0; font-size: 20px; }
.dialog-actions { justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 16px; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 60; max-width: 360px; transform: translateY(18px); border-radius: 5px; padding: 11px 14px; color: white; background: var(--primary); box-shadow: var(--shadow); font-size: 13px; opacity: 0; pointer-events: none; transition: 0.2s ease; }
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--accent-hover); }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: var(--page); }
.login-shell { display: grid; width: min(880px, 100%); grid-template-columns: 1fr 1fr; overflow: hidden; border-top: 4px solid var(--accent); border-radius: 6px; background: var(--surface); box-shadow: 0 24px 70px rgba(31, 39, 51, 0.16); }
.login-brand { display: flex; align-items: flex-start; gap: 22px; padding: 48px; color: #fff; background: var(--primary); }
.login-logo { display: block; width: auto; height: 104px; flex: 0 0 auto; object-fit: contain; }
.login-brand h1 { margin-bottom: 10px; color: #fff; font-size: 25px; }
.login-brand p { color: rgba(255, 255, 255, 0.72); }
.login-brand .eyebrow { color: var(--color-sand); }
.login-form { display: grid; gap: 16px; padding: 48px; }
.form-heading h2 { margin-bottom: 6px; font-size: 20px; }
.form-heading p { margin-bottom: 6px; font-size: 13px; }
.alert { border-radius: 4px; padding: 10px 12px; font-size: 12px; }
.alert-error { color: var(--accent-hover); background: var(--accent-soft); }
.dev-note { margin: 0; color: var(--muted); font-size: 11px; text-align: center; }

@media (max-width: 1100px) {
  .control-band { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .control-band .button { align-self: stretch; }
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .worker-row { grid-template-columns: repeat(3, 1fr); }
  .worker-row label:nth-child(5) { grid-column: 1 / 3; }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  body { padding-bottom: 68px; }
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 78px 16px 30px; }
  .mobile-header { position: fixed; inset: 0 0 auto 0; z-index: 30; display: flex; min-height: 62px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 10px 16px; background: rgba(255, 255, 255, 0.96); }
  .mobile-header .brand-logo { height: 42px; }
  .mobile-header .sidebar-brand strong { color: var(--ink); }
  .mobile-header .sidebar-brand span { color: var(--muted); }
  .status-dot { width: 10px; height: 10px; border-radius: 50%; background: #a4afac; }
  .status-dot.good { background: var(--success); }
  .status-dot.bad { background: var(--accent); }
  .mobile-nav { position: fixed; inset: auto 0 0 0; z-index: 35; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); padding: 5px 6px calc(5px + env(safe-area-inset-bottom)); background: #fff; }
  .mobile-nav .nav-item { display: grid; min-height: 50px; justify-items: center; gap: 2px; padding: 4px; color: var(--muted); font-size: 9px; }
  .mobile-nav .nav-item:hover { color: var(--accent-hover); background: transparent; }
  .mobile-nav .nav-item.active { color: var(--accent-hover); background: var(--accent-soft); }
  .mobile-nav svg { width: 19px; height: 19px; }
  .page-heading { align-items: flex-start; }
  .page-heading h1 { font-size: 23px; }
  .heading-actions { align-self: flex-end; }
  .heading-actions .button { width: 40px; padding: 0; }
  .heading-actions .button:not(#pdf-link) { width: auto; padding: 0 12px; }
  #pdf-link { font-size: 0; }
  .control-band { grid-template-columns: 1fr 1fr; gap: 10px; }
  .control-band label:nth-child(3), .control-band label:nth-child(4), .control-band .button { grid-column: 1 / -1; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-card { min-height: 88px; }
  .metric-card strong { font-size: 20px; }
  .section-heading { align-items: flex-start; }
  .diagnostic { padding: 11px; }
  .worker-row { grid-template-columns: 1fr 1fr; }
  .worker-row > label:first-child, .worker-row label:nth-child(5) { grid-column: 1 / -1; }
  .worker-state { grid-column: 1 / -1; }
  .inline-form { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { padding: 28px; }
  .login-form { padding: 28px; }
}

@media (max-width: 430px) {
  .page-heading { display: grid; }
  .heading-actions { width: 100%; }
  .heading-actions .button:not(#pdf-link) { flex: 1; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { padding: 12px; }
  .worker-row { grid-template-columns: 1fr; }
  .worker-row > label, .worker-row label:nth-child(5), .worker-state { grid-column: 1; }
}
