:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --text: #172026;
  --muted: #64727d;
  --line: #d8dee4;
  --primary: #12665f;
  --primary-dark: #0a4a45;
  --blue: #1769c2;
  --blue-dark: #0f4d91;
  --accent: #b75e24;
  --night: #253858;
  --danger: #ad2727;
  --ok: #217346;
  --warning: #a76300;
  --shadow: 0 16px 38px rgba(23, 32, 38, 0.1);
}

body.dark-mode {
  color-scheme: dark;
  --bg: #111820;
  --panel: #18222b;
  --panel-soft: #202c36;
  --text: #eef4f7;
  --muted: #a8b5bf;
  --line: #33424d;
  --primary: #39a891;
  --primary-dark: #268773;
  --blue: #4e9af0;
  --blue-dark: #2f75c4;
  --accent: #e39a54;
  --night: #9fb9f0;
  --danger: #ff7b72;
  --ok: #62c584;
  --warning: #e9b85f;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.28);
}

* {
  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;
}

body.auth-pending {
  overflow: hidden;
}

body.auth-pending .app-shell {
  display: none;
}

body.auth-pending .login-screen,
body.authenticated .login-screen {
  display: grid;
}

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

.login-screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-clock {
  justify-self: center;
  min-width: 8.5ch;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--primary);
}

.login-panel h1 {
  margin: 0;
  font-size: 1.6rem;
}

.login-subtitle {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.login-message {
  margin: 0;
  min-height: 1.25em;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-message.error {
  color: var(--danger);
}

.login-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.login-actions button {
  width: 100%;
}

@media (max-width: 480px) {
  .login-actions {
    grid-template-columns: 1fr;
  }
}

button,
input,
select {
  font: inherit;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 9px;
}

textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px;
  font: inherit;
}

textarea:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(18, 102, 95, 0.14);
}

body.dark-mode input,
body.dark-mode select,
body.dark-mode button,
body.dark-mode textarea {
  background: #121a22;
  color: var(--text);
}

input:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(18, 102, 95, 0.14);
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 0 14px;
  font-weight: 700;
}

button:hover {
  border-color: var(--primary);
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

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

.blue:hover {
  background: var(--blue-dark);
}

.danger {
  color: var(--danger);
}

.icon-button {
  width: 42px;
  min-height: 42px;
  padding: 0;
  font-size: 1.15rem;
}

.active-toggle {
  border-color: var(--primary);
  background: #eef8f6;
  color: var(--primary-dark);
}

.locked-banner {
  display: none;
  border: 1px solid rgba(33, 115, 70, 0.28);
  border-radius: 8px;
  background: #f1f8f4;
  color: var(--ok);
  font-weight: 800;
  padding: 10px 12px;
  margin-bottom: 14px;
}

body.dark-mode .locked-banner,
body.dark-mode .validation-popover.ok {
  background: #15291f;
}

body.dark-mode .validation-popover {
  background: #2a1a1d;
}

body.dark-mode .day-card.weekend {
  background: #2d281e;
}

body.dark-mode .day-card[data-shift="vacation"] {
  background: #1f2d24;
}

body.dark-mode .day-card[data-shift="freeAfterNight"] {
  background: #20262f;
}

body.dark-mode .day-card[data-shift="night"],
body.dark-mode .day-card[data-shift="longNight"] {
  background: #1e2a3c;
}

body.dark-mode .event-pill {
  background: #3a2b12;
  color: #ffd88f;
}

body.month-locked .locked-banner {
  display: block;
}

.app-shell {
  width: min(1440px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 18px;
  margin-bottom: 16px;
}

.header-mascot {
  align-self: center;
  justify-self: center;
}

.header-mascot img {
  display: block;
  width: 154px;
  height: 84px;
  image-rendering: auto;
}

body.dark-mode .header-mascot img {
  content: url("./police-car-dark.gif");
}

.topbar-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-user {
  display: grid;
  gap: 8px;
  justify-items: end;
  padding-top: 6px;
}

#logoutButton {
  min-height: 38px;
  padding: 0 12px;
}

.user-greeting {
  margin: 4px 0 0;
  min-height: 1.1em;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.utility-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.validation-popover {
  display: none;
  width: 100%;
  max-height: 170px;
  overflow: auto;
  border: 1px solid rgba(173, 39, 39, 0.28);
  border-radius: 8px;
  background: #fff7f7;
  color: var(--danger);
  padding: 10px;
  font-size: 0.86rem;
  font-weight: 750;
  margin-bottom: 8px;
}

.validation-popover.show {
  display: grid;
  gap: 6px;
}

.validation-popover.ok {
  border-color: rgba(33, 115, 70, 0.28);
  background: #f1f8f4;
  color: var(--ok);
}

.validation-popover p {
  margin: 0;
  color: inherit;
}

.settings-page {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: start;
  justify-content: end;
  background: rgba(23, 32, 38, 0.26);
  padding: 24px;
}

body.settings-open .settings-page {
  display: flex;
}

.settings-panel {
  width: min(420px, 100%);
  border: 1px solid rgba(23, 32, 38, 0.08);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.settings-subheader {
  margin-top: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(23, 32, 38, 0.32);
}

.modal-backdrop.open {
  display: flex;
}

.modal-panel {
  width: min(720px, 100%);
  max-height: min(84vh, 900px);
  overflow: auto;
  display: grid;
  gap: 16px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid rgba(23, 32, 38, 0.08);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.admin-panel {
  width: min(1120px, 100%);
}

.admin-subheader {
  margin-top: 8px;
}

.admin-create-form {
  padding: 2px 0 6px;
}

.admin-create-form h3 {
  margin: 0;
  font-size: 0.98rem;
}

.admin-user-list {
  display: grid;
  gap: 8px;
}

.admin-user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.admin-user-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.admin-user-actions {
  display: flex;
  gap: 8px;
  justify-content: end;
  flex-wrap: wrap;
}

.admin-user-row button {
  min-height: 34px;
  padding: 0 12px;
}

.admin-user-row input {
  min-height: 34px;
}

.admin-message {
  margin: 0;
  min-height: 1.25em;
  color: var(--muted);
  font-size: 0.92rem;
}

body.admin-authenticated .app-shell,
body.admin-authenticated .login-screen {
  display: none;
}

body.admin-authenticated .modal-backdrop {
  display: flex;
  align-items: start;
  justify-content: center;
  background: var(--bg);
}

body.admin-authenticated .modal-panel {
  box-shadow: none;
  max-height: none;
  min-height: calc(100vh - 48px);
}

body.admin-authenticated .admin-panel {
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.05rem;
}

p {
  color: var(--muted);
}

.helper-text {
  margin: -4px 0 10px;
  font-size: 0.84rem;
}

.month-controls,
.toolbar,
.stat,
.calendar-panel,
.side-panel {
  background: var(--panel);
  border: 1px solid rgba(23, 32, 38, 0.08);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.month-controls {
  display: grid;
  grid-template-columns: 42px minmax(180px, auto) 42px;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.month-controls strong {
  text-align: center;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

.tabs {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  min-width: 96px;
}

.duz-view {
  display: none;
}

body.duz-tab .planner-view {
  display: none;
}

body.duz-tab .duz-view {
  display: block;
}

body.duz-tab .toolbar {
  display: none;
}

.duz-panel {
  background: var(--panel);
  border: 1px solid rgba(23, 32, 38, 0.08);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

#duzTotal {
  font-size: 1.6rem;
  color: var(--primary);
}

.duz-table-wrap {
  overflow-x: auto;
}

.duz-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.duz-table th,
.duz-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.duz-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.duz-table td:last-child,
.duz-table th:last-child {
  text-align: right;
}

body.month-locked .toolbar,
body.month-locked .calendar-panel,
body.month-locked .side-panel,
body.month-locked .dashboard {
  box-shadow: none;
}

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

.stat {
  padding: 16px;
  min-height: 104px;
}

.stat span,
.stat small {
  display: block;
  color: var(--muted);
}

.stat span {
  margin-bottom: 5px;
  font-size: 0.84rem;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-bottom: 5px;
  font-size: 1.55rem;
}

.stat small {
  font-size: 0.8rem;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

.calendar-panel,
.side-panel {
  padding: 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 12px;
}

.section-header p {
  margin-bottom: 0;
}

.section-header.compact {
  margin-top: 4px;
  margin-bottom: 8px;
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: 42px repeat(7, minmax(118px, 1fr));
  gap: 8px;
}

.weekday-row {
  margin-bottom: 8px;
}

.weekday-row span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.week-column-label,
.week-cell {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.week-cell {
  align-self: stretch;
}

.day-card {
  min-height: 124px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.day-card.outside {
  visibility: hidden;
}

.day-card.weekend {
  background: #fff8ef;
}

.day-card[data-shift="vacation"] {
  background: #eef7ec;
}

.day-card[data-shift="freeAfterNight"] {
  background: #f1f3f7;
}

.holiday-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  opacity: 0.52;
}

.day-card.invalid {
  border-color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(173, 39, 39, 0.22);
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.day-number {
  font-size: 1.15rem;
  font-weight: 850;
}

.day-name {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.shift-select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 8px;
}

.shift-select:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(18, 102, 95, 0.14);
}

body.month-locked .shift-select:disabled {
  appearance: none;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  font-weight: 850;
  opacity: 1;
  padding: 0;
}

.shift-time {
  align-self: end;
  min-height: 22px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.event-list {
  display: grid;
  gap: 4px;
  margin-top: 2px;
}

.event-pill {
  overflow: hidden;
  border-radius: 6px;
  background: #fff1d6;
  color: #6f4100;
  padding: 3px 5px;
  font-size: 0.72rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-card[data-shift="early"] .shift-time,
.day-card[data-shift="late"] .shift-time {
  color: var(--primary);
}

.day-card[data-shift="night"],
.day-card[data-shift="longNight"] {
  background: #eef2fa;
}

.day-card[data-shift="night"] .shift-time,
.day-card[data-shift="longNight"] .shift-time {
  color: var(--night);
}

.day-card[data-shift="longDay"] .shift-time {
  color: var(--accent);
}

.day-card[data-shift="eightHour"] .shift-time {
  color: var(--blue);
}

.day-card[data-shift="vacation"] .shift-time,
.day-card[data-shift="freeAfterNight"] .shift-time {
  color: var(--muted);
}

.vacation-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.vacation-toggle input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.side-panel {
  display: grid;
  gap: 18px;
}

.calendar-settings {
  display: none;
}

body.planning-mode .calendar-settings {
  display: block;
}

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

.compact-stack {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.check-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  color: var(--text);
}

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

.calendar-choice-list {
  display: grid;
  gap: 6px;
}

.calendar-choice {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px;
}

body.dark-mode .calendar-choice {
  background: #121a22;
  color: var(--text);
}

.calendar-choice input {
  width: 16px;
  min-height: 16px;
}

.calendar-choice small {
  color: var(--muted);
}

.week-list,
.shift-list,
.validation-list {
  display: grid;
  gap: 8px;
}

.metric-row,
.week-row,
.message {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  font-size: 0.9rem;
}

.week-row {
  align-items: center;
}

.metric-row strong {
  white-space: nowrap;
}

.week-main {
  display: grid;
  gap: 2px;
}

.week-main small {
  color: var(--muted);
}

.week-target {
  display: grid;
  grid-template-columns: 68px 18px;
  align-items: center;
  gap: 6px;
}

.week-target input {
  width: 68px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 8px;
  text-align: right;
}

.week-target input:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(18, 102, 95, 0.14);
}

body.month-locked .week-target input:disabled {
  border-color: transparent;
  background: transparent;
  color: var(--text);
  font-weight: 850;
  opacity: 1;
}

.message {
  display: block;
  border-color: rgba(100, 114, 125, 0.22);
}

.message.ok {
  border-color: rgba(33, 115, 70, 0.35);
  color: var(--ok);
}

.message.error {
  border-color: rgba(173, 39, 39, 0.35);
  color: var(--danger);
}

.message.warning {
  border-color: rgba(167, 99, 0, 0.35);
  color: var(--warning);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .weekday-row,
  .calendar-grid {
    grid-template-columns: 42px repeat(7, minmax(96px, 1fr));
    overflow-x: auto;
  }
}

@media (max-width: 760px) {
  .topbar {
    display: grid;
    align-items: start;
    grid-template-columns: 1fr auto;
  }

  .header-mascot {
    grid-column: 2;
    grid-row: 1;
  }

  .header-mascot img {
    width: 116px;
    height: 64px;
  }

  .topbar-actions {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: space-between;
  }

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

  .calendar-panel {
    overflow-x: auto;
  }

  .weekday-row,
  .calendar-grid {
    min-width: 802px;
  }
}

@media (max-width: 520px) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  .month-controls {
    width: 100%;
  }
}
