:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #d8dee8;
  --text: #172033;
  --muted: #637083;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header .brand {
  margin: 0;
  font-size: 18px;
  white-space: nowrap;
}

.app-header .tabs {
  flex-wrap: nowrap;
  gap: 4px;
  margin: 0;
  overflow-x: auto;
}

.app-header .tab {
  border-color: transparent;
}

.app-header .tab:not(.active):hover {
  background: var(--surface-2);
}

.tab-badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.tab-badge[hidden] {
  display: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Keyfile-Status oben rechts */
.keyfile-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.keyfile-chip::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.keyfile-chip[data-state="unlocked"] { border-color: #a7d7cc; background: #e8f5f1; color: #145c50; }
.keyfile-chip[data-state="locked"] { border-color: #bfdbfe; background: #eff6ff; color: #1e40af; }
.keyfile-chip[data-state="dirty"],
.keyfile-chip[data-state="new"] { border-color: #fcd34d; background: #fef0c7; color: #854d0e; }
.keyfile-chip[data-state="busy"] { color: #2563eb; }
.keyfile-chip[data-state="error"] { border-color: #fca5a5; background: #fef2f2; color: #b42318; }
#keyfilePanel[data-state="error"] { border-color: #fca5a5; background: #fffafa; }
#keyfilePanel[data-state="error"] .keyfile-badge { background: #fef2f2; color: #b42318; }
#keyfilePanel[data-state="error"] .keyfile-badge::before { background: #b42318; }

/* Benutzermenü */
.user-menu {
  position: relative;
}

.user-menu-button .current-user {
  color: var(--text);
}

.user-menu-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  display: grid;
  min-width: 180px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(23, 32, 51, 0.18);
}

.user-menu-popover[hidden] {
  display: none;
}

.user-menu-popover button {
  border: 0;
  text-align: left;
}

.user-menu-popover button:hover,
.user-menu-popover button:focus-visible {
  background: var(--surface-2);
}

/* Monatsauswahl + Statuszeile */
.month-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  min-height: 34px;
}

.month-bar .status {
  margin: 0;
}

.month-bar.month-hidden .month-nav {
  display: none;
}

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

.inline-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.legend-row .legend {
  justify-content: flex-start;
  gap: 6px;
}

.legend-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* Unter-Tabs in der Verwaltung */
.subtabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 14px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.subtab {
  border-color: transparent;
  background: transparent;
}

.subtab.active {
  background: #fff;
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(23, 32, 51, 0.08);
  font-weight: 600;
}

.subview {
  display: none;
}

.subview.active {
  display: block;
}

.view-intro {
  margin-bottom: 12px;
}

#keyfilePanel[hidden] {
  display: none;
}

h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

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

main {
  padding: 18px 28px 32px;
}

.toolbar,
.tabs,
.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

input,
select {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 8px;
}

button,
.button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 7px 11px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.button:hover {
  border-color: #aab4c2;
}

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

.primary:hover {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
}

.danger {
  border-color: #fecaca;
  color: var(--danger);
}

.tabs {
  margin-bottom: 12px;
}

.tab.active {
  background: #172033;
  border-color: #172033;
  color: #fff;
}

.status {
  min-height: 24px;
  margin-bottom: 12px;
  color: var(--muted);
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 12px;
}

.legend {
  justify-content: flex-end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 3px;
}

.matrix-wrap,
.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.matrix-wrap {
  overflow-x: hidden;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

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

th {
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
  color: #334155;
}

tfoot th {
  border-top: 2px solid var(--border);
  background: #e2e8f0;
}

tr:last-child td {
  border-bottom: 0;
}

th:last-child,
td:last-child {
  border-right: 0;
}

.matrix {
  table-layout: fixed;
  min-width: 0;
}

.matrix th.day {
  position: relative;
  width: auto;
  text-align: center;
  padding: 4px 2px;
  font-size: 11px;
  line-height: 1.05;
}

.matrix th.day span,
.matrix th.day strong {
  display: block;
}

.day-head {
  position: relative;
  min-height: 28px;
}

.matrix th.weekend {
  background: #d9dee7;
}

.matrix td.weekend {
  background: #f1f3f6;
}

.matrix th.person,
.matrix td.person {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 150px;
  background: #fff;
}

.matrix td.person {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matrix th.person {
  z-index: 3;
  background: var(--surface-2);
}

.matrix thead th.person {
  z-index: 4;
}

/* Zeilenköpfe (Namen) sehen aus wie normale Zellen */
.matrix tbody th.person {
  z-index: 2;
  background: #fff;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-shell {
  position: relative;
}

/* --- Monatsplan-Raster --- */
.matrix td.plan-cell {
  height: 30px;
  padding: 0;
  text-align: center;
  cursor: cell;
  user-select: none;
  -webkit-user-select: none;
}

.matrix td.plan-cell .cell-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
}

.cell-code {
  overflow: hidden;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.matrix td.plan-cell.selected {
  box-shadow: inset 0 0 0 9999px rgba(15, 118, 110, 0.22);
}

.matrix td.plan-cell.cursor,
.matrix td.plan-cell:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.matrix td.plan-cell:focus {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.matrix.brush-active td.plan-cell {
  cursor: crosshair;
  touch-action: none;
}

.matrix td.plan-cell.painting {
  box-shadow: inset 0 0 0 9999px rgba(15, 118, 110, 0.35);
}

.matrix td.plan-cell .comment-dot {
  right: 1px;
  top: 1px;
}

.matrix td.plan-cell .cell-warning {
  left: 1px;
  top: 1px;
  width: 12px;
  height: 12px;
  min-height: 12px;
  font-size: 9px;
}

.plan-hintbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
  margin: -4px 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.plan-selection-info {
  color: var(--text);
  font-weight: 600;
  min-height: 1.2em;
}

.plan-shortcuts kbd,
.help-content kbd {
  padding: 0 4px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  font: inherit;
  font-size: 11px;
}

button.legend-item {
  min-height: 26px;
  cursor: pointer;
}

button.legend-item.active {
  border-color: var(--primary);
  background: #ccfbf1;
  color: var(--text);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.35);
}

.eraser-swatch {
  background: repeating-linear-gradient(45deg, #fff 0 3px, #e2e8f0 3px 6px);
}

.person-short {
  margin-left: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.data-table td.person-cell {
  white-space: nowrap;
}

/* Warnsymbol im Tageskopf unter dem Datum statt über dem Wochentag */
.matrix th.day .day-head {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.matrix th.day .plan-warning.day-warning {
  position: static;
  width: 12px;
  height: 12px;
  min-height: 12px;
  margin-top: 2px;
  font-size: 9px;
}

/* Monatsplan: Spalten nicht unter Lesbarkeit quetschen, sondern seitlich
   scrollen; die Namensspalte bleibt dabei stehen. */
.matrix-wrap.plan-wrap {
  overflow-x: auto;
}

#planTable {
  min-width: 1200px;
}

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

/* --- Hilfe: Seitenleiste mit Suche und Inhaltsverzeichnis --- */
.help-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.help-sidebar {
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.help-search label {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 13px;
}

.help-search input {
  width: 100%;
  min-height: 38px;
}

.help-search-info {
  min-height: 1.2em;
  margin: 6px 0 4px;
  font-size: 12px;
}

.help-toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-toc a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
  text-decoration: none;
}

.help-toc a:hover {
  background: var(--surface-2);
}

.help-toc-topic > a {
  margin-top: 4px;
  font-weight: 700;
}

.help-toc-topic > ul {
  display: none;
  margin: 2px 0 6px 10px;
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

.help-toc-topic.open > ul,
.help-toc.searching .help-toc-topic > ul {
  display: block;
}

.help-toc li.active > a {
  background: #ccfbf1;
  color: var(--primary-strong);
}

.help-toc-count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 9px;
  background: #fde68a;
  color: #713f12;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.help-toc-count:empty {
  display: none;
}

.help-content {
  max-width: 900px;
  min-width: 0;
}

.help-topic {
  margin-bottom: 18px;
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  scroll-margin-top: 76px;
}

.help-topic h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.help-content p,
.help-content li,
.help-content dd,
.help-content td {
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

.help-content p.help-lead {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 15px;
}

.help-entry {
  padding: 14px 0 10px;
  border-top: 1px solid var(--border);
  scroll-margin-top: 76px;
}

.help-entry h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.help-entry p + p,
.help-entry ul + p,
.help-entry ol + p,
.help-entry table + p {
  margin-top: 8px;
}

.help-entry ul,
.help-entry ol {
  margin: 6px 0;
  padding-left: 22px;
}

.help-entry li + li {
  margin-top: 3px;
}

.help-content a {
  color: var(--primary-strong);
  font-weight: 600;
}

.help-content code {
  padding: 0 4px;
  border-radius: 4px;
  background: var(--surface-2);
  font-size: 12px;
}

.help-content p.help-warning {
  margin-top: 8px;
  padding: 8px 12px;
  border-left: 4px solid #f59e0b;
  border-radius: 6px;
  background: #fffbeb;
}

.help-table {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.help-table th,
.help-table td {
  padding: 6px 10px;
  vertical-align: top;
}

.help-table td:first-child {
  white-space: nowrap;
  font-weight: 600;
}

.help-glossary dt {
  margin-top: 10px;
  font-weight: 700;
}

.help-glossary dd {
  margin: 2px 0 0;
}

.help-content mark {
  padding: 0 1px;
  border-radius: 2px;
  background: #fde68a;
  color: inherit;
}

.help-no-results {
  padding: 24px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  text-align: center;
}

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

  .help-sidebar {
    position: static;
    max-height: none;
  }

  .help-toc-topic.open > ul {
    display: none;
  }

  .help-topic {
    padding: 16px;
  }
}

/* Soll/Ist je Zeile */
.matrix th.row-sum,
.matrix td.row-sum {
  width: 64px;
  padding: 2px 4px;
  text-align: right;
}

.row-sum-inner {
  display: grid;
  line-height: 1.1;
}

.row-sum-inner strong {
  font-size: 13px;
}

.row-sum-inner small {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.row-sum-inner.ok strong { color: var(--muted); }
.row-sum-inner.under strong { color: var(--danger); }
.row-sum-inner.over strong { color: #b45309; }

/* Besetzung pro Tag */
.matrix tfoot th.person {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: #e2e8f0;
}

.matrix tfoot td {
  padding: 2px 0;
  background: #f8fafc;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  color: #334155;
}

.matrix tfoot tr:first-child th,
.matrix tfoot tr:first-child td {
  border-top: 2px solid var(--border);
}

.matrix tfoot .plan-foot-night td,
.matrix tfoot .plan-foot-absence td {
  font-weight: 500;
  color: var(--muted);
}

/* Feiertage wie Wochenenden, heutiger Tag hervorgehoben */
.matrix th.holiday {
  background: #d9dee7;
}

.matrix td.holiday,
.matrix tfoot td.holiday {
  background: #f1f3f6;
}

.matrix th.holiday .day-head::after {
  content: "FT";
  display: block;
  font-size: 8px;
  font-weight: 800;
  color: #b42318;
}

.matrix th.today {
  background: var(--primary);
  color: #fff;
}

.matrix td.plan-cell.today {
  box-shadow: inset 2px 0 0 var(--primary), inset -2px 0 0 var(--primary);
}

.matrix td.plan-cell.today.selected {
  box-shadow: inset 2px 0 0 var(--primary), inset -2px 0 0 var(--primary), inset 0 0 0 9999px rgba(15, 118, 110, 0.22);
}

/* Warnsymbol ist ein Knopf */
button.plan-warning {
  padding: 0;
  cursor: pointer;
}

.hint-warning {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
}

/* Warnungen-Dialog */
.warning-dialog {
  width: min(520px, calc(100vw - 32px));
}

.warning-dialog-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.warning-dialog-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--danger);
  border-radius: 8px;
}

.warning-dialog-list li.confirmed {
  border-left-color: var(--primary);
}

.warning-dialog-list li div {
  display: grid;
  gap: 2px;
  font-size: 13px;
}

.warning-dialog-list li small {
  color: var(--muted);
}

/* Verwaltung */
.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.admin-bar .hint {
  max-width: 760px;
  font-size: 13px;
}

.data-table tr.dirty td {
  background: #fef9c3;
}

.data-table tr.dirty td:first-child {
  box-shadow: inset 4px 0 0 #eab308;
}

.data-table input.narrow {
  width: 76px;
}

.data-table td.number {
  text-align: right;
  white-space: nowrap;
}

.data-table td.center {
  text-align: center;
}

.data-table th small {
  font-weight: 500;
  color: var(--muted);
}

.code-chip {
  display: inline-block;
  min-width: 42px;
  padding: 3px 6px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.flag-chip {
  display: inline-block;
  margin: 1px 4px 1px 0;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: #334155;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Eingabefeld mit Vorschlägen über der Zelle */
.cell-editor {
  position: fixed;
  z-index: 50;
  width: 260px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(23, 32, 51, 0.22);
}

.cell-editor input {
  width: 100%;
  font-weight: 700;
  text-transform: uppercase;
}

.cell-editor ul {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.cell-editor li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.cell-editor li strong {
  min-width: 42px;
}

.cell-editor li span:last-child {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-editor li.active,
.cell-editor li:hover {
  background: #ccfbf1;
}

.cell-editor li.empty {
  color: var(--danger);
  cursor: default;
}

.cell-editor-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.plan-warning {
  position: absolute;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  min-height: 14px;
  border: 1px solid #fff;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(23, 32, 51, 0.18);
  pointer-events: auto;
}

.matrix th.day .plan-warning {
  display: inline-flex;
}

.plan-warning.open {
  background: var(--danger);
}

.plan-warning.confirmed {
  background: var(--primary);
}

.day-warning {
  top: -2px;
  right: 1px;
}

.cell-warning {
  left: -3px;
  top: -5px;
}

.comment-dot {
  position: absolute;
  right: -2px;
  top: -4px;
  width: 8px;
  height: 8px;
  min-height: 8px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #fff;
  background: #f59e0b;
  opacity: 0;
}

.comment-dot.has-comment,
.cell-shell:hover .comment-dot,
.comment-dot:focus-visible {
  opacity: 1;
}

.comment-dot:not(.has-comment) {
  background: #94a3b8;
}

.comment-dot:focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.current-user {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  display: grid;
  gap: 12px;
  width: min(340px, 90vw);
  padding: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
}

.login-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.month-nav button {
  min-width: 34px;
  padding: 7px 8px;
  font-weight: 700;
}

.data-table tr.clickable {
  cursor: pointer;
}

.data-table tr.clickable:hover td {
  background: #f0fdfa;
}

.data-table tr.selected-row td {
  background: #ccfbf1;
}

.year-wrap {
  margin-bottom: 16px;
}

.year-matrix td {
  height: 26px;
  padding: 2px 1px;
  text-align: center;
}

.year-matrix td.no-day {
  background: var(--surface-2);
}

.year-code {
  display: block;
  min-width: 0;
  padding: 3px 0;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.month-link {
  min-height: auto;
  border: 0;
  background: none;
  padding: 0;
  color: var(--primary-strong);
  font-weight: 600;
  cursor: pointer;
}

.month-link:hover {
  text-decoration: underline;
  border: 0;
}

.section-title {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
}

#statisticsView .section-title {
  margin-top: 16px;
}

#statisticsView .table-wrap {
  margin-bottom: 8px;
}

.hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.notice em {
  font-style: normal;
  font-weight: 700;
}

.data-table input,
.data-table select {
  width: 100%;
}

.data-table .flag-cell {
  min-width: 190px;
}

.data-table td.actions {
  white-space: nowrap;
  width: 1%;
}

.data-table .number {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

.positive {
  color: var(--primary-strong);
  font-weight: 700;
}

.negative {
  color: var(--danger);
  font-weight: 700;
}

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

.warning-panel {
  min-width: 0;
}

.warning-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.warning-card.warning {
  border-color: #f59e0b;
}

.warning-card.ok {
  border-color: #99f6e4;
}

.warning-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.warning-card-header h3 {
  margin: 0 0 3px;
  font-size: 14px;
  line-height: 1.2;
}

.warning-card-header p {
  font-size: 12px;
}

.warning-card-status {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 5px;
  white-space: nowrap;
}

.warning-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.warning-chip.warning {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.warning-chip.ok {
  border-color: #5eead4;
  background: #f0fdfa;
  color: var(--primary-strong);
}

.warning-chip.muted {
  color: var(--muted);
  font-weight: 600;
}

.warning-items {
  display: grid;
  align-content: start;
}

.warning-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.warning-item:last-child {
  border-bottom: 0;
}

.warning-item.warning {
  background: #fff8e6;
}

.warning-item.confirmed {
  background: #f8fafc;
  color: var(--muted);
}

.warning-date {
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.warning-content {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.warning-meta,
.warning-message {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-width: 0;
}

.warning-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.warning-message {
  color: var(--text);
}

.warning-type {
  color: #92400e;
  font-weight: 800;
}

.warning-confirmed {
  color: var(--muted);
  font-size: 12px;
}

.warning-actions {
  display: flex;
  align-items: flex-start;
}

.warning-actions button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.warning-empty {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 13px;
}

.warning-empty.ok {
  background: #f0fdfa;
  color: var(--primary-strong);
}

.inactive {
  color: var(--muted);
  background: #f8fafc;
}

@media (max-width: 900px) {
  .app-header {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 14px;
  }

  .app-header .tabs {
    order: 3;
    width: 100%;
  }

  main {
    padding: 14px;
  }

  .warning-board {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 620px) {
  .warning-card-header {
    flex-direction: column;
  }

  .warning-card-status {
    align-items: flex-start;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .warning-item {
    grid-template-columns: 1fr;
  }

  .warning-actions {
    justify-content: flex-start;
  }
}


#keyfilePanel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 14px;
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
#keyfilePanel[data-state="dirty"], #keyfilePanel[data-state="new"] {
  border-color: #d97706;
  background: #fffbeb;
}
#keyfilePanel[data-state="unlocked"] { border-color: #6aa99f; }
#keyfilePanel[data-state="locked"] { border-color: #93c5fd; }
#keyfilePanel[data-state="locked"] .keyfile-badge { background: #eff6ff; color: #1e40af; }
#keyfilePanel[data-state="locked"] .keyfile-badge::before { background: #2563eb; }
.keyfile-copy { min-width: 0; }
.keyfile-copy h2 { display: inline-block; margin: 0 0 0 8px; font-size: 16px; line-height: 1.3; vertical-align: middle; }
.keyfile-copy p { max-width: 740px; margin-top: 4px; line-height: 1.4; }
.keyfile-copy .keyfile-hint { margin-top: 2px; color: var(--muted); font-size: 12px; }
.keyfile-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}
.keyfile-badge::before { width: 8px; height: 8px; border-radius: 50%; background: #64748b; content: ""; }
#keyfilePanel[data-state="unlocked"] .keyfile-badge { background: #e8f5f1; color: #145c50; }
#keyfilePanel[data-state="unlocked"] .keyfile-badge::before { background: #16836f; }
#keyfilePanel[data-state="dirty"] .keyfile-badge,
#keyfilePanel[data-state="new"] .keyfile-badge { background: #fef0c7; color: #854d0e; }
#keyfilePanel[data-state="dirty"] .keyfile-badge::before,
#keyfilePanel[data-state="new"] .keyfile-badge::before { background: #b45309; }
#keyfilePanel[data-state="busy"] .keyfile-badge::before { background: #2563eb; }
.keyfile-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.keyfile-actions button { min-height: 44px; }
#keyfileLockButton { border-color: #b8c2d0; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}
#keyfilePasswordDialog,
.app-dialog { border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 18px 50px #0003; }
#keyfilePasswordDialog::backdrop,
.app-dialog::backdrop { background: #11182799; }
#keyfilePasswordDialog h2,
.app-dialog h2 { margin: 0 0 8px; font-size: 19px; }
#keyfilePasswordDialog label,
.app-dialog label { margin: 16px 0 6px; color: var(--text); font-size: 14px; }
.app-dialog .dialog-text { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; white-space: pre-line; }
.app-dialog .dialog-text:empty { display: none; }
.app-dialog .dialog-field-hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.app-dialog input { width: 100%; min-height: 44px; }
.app-dialog textarea { width: 100%; min-height: 96px; resize: vertical; font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.app-dialog textarea:focus-visible { outline: 3px solid #2563eb; outline-offset: 2px; }
.app-dialog .dialog-toggle { grid-column: 1 / -1; justify-self: start; margin-top: 10px; }
.app-dialog.wide { width: min(640px, calc(100vw - 32px)); }
.app-dialog .dialog-fields { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; max-height: min(62vh, 640px); overflow-y: auto; padding: 0 2px; }
.app-dialog .dialog-field { grid-column: 1 / -1; min-width: 0; }
.app-dialog .dialog-field.half { grid-column: auto; }
.app-dialog .dialog-heading { margin: 18px 0 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.app-dialog .dialog-field.check label { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; font-weight: 600; }
.app-dialog .dialog-field.check .dialog-field-hint { margin: 2px 0 0 26px; }
.app-dialog input[type="checkbox"] { width: 18px; min-height: 18px; height: 18px; margin: 0; }
.app-dialog input[type="color"] { padding: 2px; }
.app-dialog select { width: 100%; min-height: 44px; }
@media (max-width: 620px) {
  .app-dialog .dialog-field.half { grid-column: 1 / -1; }
}
.app-dialog button.primary.danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.app-dialog button.primary.danger:hover { border-color: #912018; background: #912018; }
.password-input-wrap { display: flex; gap: 8px; }
.password-input-wrap input { min-width: 0; flex: 1; min-height: 44px; }
.password-input-wrap button { min-height: 44px; }
#keyfilePasswordHint { margin: 10px 0 0; font-size: 13px; line-height: 1.45; }
.keyfile-password-error { min-height: 1.3em; margin: 8px 0 0; color: #b42318; font-size: 13px; line-height: 1.4; }
.keyfile-password-error:empty { display: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-actions button { min-height: 44px; }
@media (max-width: 700px) {
  #keyfilePanel { align-items: stretch; flex-direction: column; gap: 10px; padding: 12px; }
  .keyfile-actions { display: grid; grid-template-columns: 1fr; }
  .keyfile-actions button { width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  #keyfilePanel { transition: border-color 160ms ease, background-color 160ms ease; }
}
