/* Design tokens (light) */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #eef0f3;
  --text: #1b1e22;
  --text-muted: #5b6572;
  --border: #dde1e6;
  --primary: #2e6f8e;
  --primary-contrast: #ffffff;
  --primary-tint: rgba(46, 111, 142, 0.12);
  --danger: #c0392b;
  --success: #2e7d32;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
html[data-theme="dark"] {
  --bg: #14171a;
  --surface: #1e2226;
  --surface-alt: #262b30;
  --text: #eceef0;
  --text-muted: #9aa4ad;
  --border: #33393f;
  --primary: #62a8cc;
  --primary-contrast: #06202b;
  --primary-tint: rgba(98, 168, 204, 0.18);
  --danger: #e57373;
  --success: #81c784;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #14171a;
    --surface: #1e2226;
    --surface-alt: #262b30;
    --text: #eceef0;
    --text-muted: #9aa4ad;
    --border: #33393f;
    --primary: #62a8cc;
    --primary-contrast: #06202b;
    --primary-tint: rgba(98, 168, 204, 0.18);
    --danger: #e57373;
    --success: #81c784;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
}
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 10px; }
.text-muted, .muted { color: var(--text-muted); }

/* Icons */
.ui-icon { width: 18px; height: 18px; vertical-align: middle; flex: none; }
.icon-btn .ui-icon { width: 20px; height: 20px; }
html[data-theme="dark"] .ui-icon { filter: invert(1) brightness(1.8); }
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] .ui-icon { filter: invert(1) brightness(1.8); }
}
html[data-theme="dark"] .ui-icon.brand-logo { filter: none; }

/* Page shell */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title {
  flex: 0 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 600; font-size: 1.05rem; color: var(--text); text-decoration: none;
}
.topbar-actions {
  display: flex; align-items: center; gap: 8px;
  margin-left: auto; flex: 0 1 auto; min-width: 0;
  overflow-x: auto; white-space: nowrap; scrollbar-width: none;
}
.topbar-actions::-webkit-scrollbar { display: none; }
.topbar-actions:empty { display: none; }
.topbar-actions > * { flex: none; }
.topbar-actions + .account-menu, .topbar-title + .account-menu { margin-left: auto; }
.topbar-actions ~ .account-menu { margin-left: 0; }
.account-menu { position: relative; flex: none; }
.account-menu-panel {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 240px; max-width: 80vw; max-height: calc(100vh - 70px);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); z-index: 50;
}
.account-menu-panel.open { display: block; }
.account-menu-section { padding: 4px 0; }
.account-menu-section + .account-menu-section { border-top: 1px solid var(--border); }
.account-menu-section:not(:has(> *)) { display: none; }
.account-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 14px; background: transparent; border: 0; border-radius: 0;
  color: var(--text); font: inherit; font-size: 0.95rem; text-align: left; text-decoration: none; cursor: pointer;
}
.account-menu-item:hover, .account-menu-item:active, .account-menu-item:focus-visible { background: var(--surface-alt); }
.account-menu-item .bubble { margin-left: auto; }
.account-menu-section form { margin: 0; }

.page { max-width: 900px; margin: 0 auto; padding: 12px 12px 90px; }

/* Cards, buttons, forms */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; background: var(--surface-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font: inherit; font-size: 0.95rem; text-decoration: none; cursor: pointer;
}
.btn:disabled, .btn.disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }
.btn-block { display: flex; width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: var(--radius);
  color: var(--text); font-size: 1.2rem; padding: 6px 10px; min-height: 40px; min-width: 40px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-alt); }

input[type="text"], input[type="password"], input[type="date"], input[type="datetime-local"],
input[type="number"], input[type="url"], input[type="email"], input[type="search"], input[type="tel"],
textarea, select {
  width: 100%; padding: 10px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); font: inherit; font-size: 1rem;
}
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: 0.85rem; color: var(--text-muted); margin: 8px 0 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row label { margin: 0; color: var(--text); font-size: 0.95rem; }
.checkbox-row input[type="checkbox"] { width: 22px; height: 22px; flex: none; }
.field-hint { font-size: 0.85rem; color: var(--text-muted); margin: 4px 0 0; }

.flash-stack { margin-bottom: 12px; }
.flash { padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); margin-bottom: 8px; }
.flash-success { border-color: var(--success); color: var(--success); }
.flash-error { border-color: var(--danger); color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
th { background: var(--surface-alt); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem;
  background: var(--surface-alt); border: 1px solid var(--border); color: var(--text);
}
.badge-info { background: var(--primary-tint); border-color: var(--primary); color: var(--primary); }
.badge-error { background: transparent; border-color: var(--danger); color: var(--danger); }
.bubble {
  display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; text-align: center; color: #fff;
}
.bubble-info { background: #2e6f8e; }
.bubble-error { background: #c0392b; }
html[data-theme="dark"] .bubble-info { background: #3d7f9f; }
html[data-theme="dark"] .bubble-error { background: #b3443a; }

/* List rows */
.list-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.list-row:active { background: var(--surface-alt); }
.list-row-content { flex: 1 1 auto; min-width: 0; }
a.list-row-link { color: inherit; text-decoration: none; }
.list-row-second-line { font-size: 0.85rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-important { border-color: var(--danger); }
.list-row .bubble { margin-left: auto; }
.list-row.busy, tr.busy { opacity: 0.5; pointer-events: none; }
.list-card > .list-row:last-child { margin-bottom: 0; }

/* Per-item menu */
.row-menu { position: relative; flex: none; }
.row-menu-panel {
  display: none; position: absolute; right: 0; top: 100%; min-width: 210px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 40; padding: 4px 0;
}
.row-menu-panel.open { display: block; }
.row-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px;
  background: transparent; border: 0; color: var(--text); font: inherit; font-size: 0.95rem;
  text-align: left; text-decoration: none; cursor: pointer;
}
.row-menu-item:hover, .row-menu-item:focus-visible { background: var(--surface-alt); }
.row-menu-item-danger { color: var(--danger); }
.row-menu-divider { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
body.ms-active .row-menu { display: none; }

/* Filter card */
.filter-details > summary { cursor: pointer; font-weight: 600; list-style: none; }
.filter-details > summary::-webkit-details-marker { display: none; }
.filter-details > summary::before { content: "▸ "; }
.filter-details[open] > summary::before { content: "▾ "; }
.filter-details-body { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-top: 10px; }
.filter-details-body > div { min-width: 110px; }
.filter-details-body .filter-search { flex: 1 1 160px; }
.pager { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.pager-text { align-self: center; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tab-btn {
  padding: 10px 14px; background: transparent; border: 0; border-bottom: 3px solid transparent;
  color: var(--text-muted); font: inherit; cursor: pointer; white-space: nowrap;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
#settings-tabs { scroll-margin-top: 70px; }

/* Log table and details popup */
.log-table td.col-glyph { width: 28px; text-align: center; padding: 6px 2px; }
.log-table td.col-time { white-space: nowrap; }
.log-table tr.log-row { cursor: pointer; }
.log-table tr.log-row:hover td { background: var(--surface-alt); }
.log-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.log-date-row td { font-weight: 600; color: var(--text-muted); background: var(--surface-alt); }
@media (max-width: 640px) { .col-low-priority { display: none; } }
.log-popup-overlay {
  display: none; position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0.6);
  align-items: center; justify-content: center;
}
.log-popup-overlay.open { display: flex; }
.log-popup-card {
  position: relative; width: 90%; max-width: 480px; max-height: 85vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 36px;
}
.log-popup-field { margin-bottom: 12px; }
.log-popup-field label { margin: 0 0 2px; }
.log-popup-field div { white-space: pre-wrap; word-break: break-word; }
.log-popup-nav {
  position: absolute; top: 50%; transform: translateY(-50%); background: transparent; border: 0;
  color: var(--text); font-size: 2rem; line-height: 1; cursor: pointer; padding: 4px 6px;
}
.log-popup-prev { left: 0; }
.log-popup-next { right: 0; }

/* Dialogs and overlays */
.lightbox-overlay {
  display: none; position: fixed; inset: 0; z-index: 220; background: rgba(0, 0, 0, 0.6);
  align-items: center; justify-content: center;
}
.lightbox-overlay.open { display: flex; }
.lightbox-overlay .card { max-width: 360px; width: 90%; margin: 0; }
#leave-guard-modal { z-index: 230; }
.fullscreen-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 200; background: var(--bg);
  flex-direction: column;
}
.fullscreen-modal-overlay.open { display: flex; }
.fullscreen-modal-body { flex: 1 1 auto; overflow-y: auto; padding: 12px; }
.fullscreen-modal-footer { flex: none; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface); }

/* Split button */
.split-btn { position: relative; display: inline-flex; }
.split-btn-main { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-btn-toggle { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 0; }
.split-btn .row-menu-panel { left: 0; right: auto; }
.split-btn-check { display: inline-block; width: 1em; }

/* Multi-selection (shared rules for lists, tables and grids) */
.ms-checkbox {
  display: none; flex: none; width: 22px; height: 22px; border: 2px solid var(--border); border-radius: 6px;
  align-items: center; justify-content: center; color: var(--primary-contrast); font-size: 0.8rem;
}
body.ms-active .ms-checkbox { display: inline-flex; }
.ms-col { display: none; width: 28px; text-align: center; }
body.ms-active .ms-col { display: table-cell; }
.list-row.ms-selected { background: var(--primary-tint); border-color: var(--primary); }
.list-row.ms-selected .ms-checkbox, tr.ms-selected .ms-checkbox { background: var(--primary); border-color: var(--primary); }
tr.ms-selected td { background: var(--primary-tint); }
.pa-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--pa-thumb-width, 250px), 1fr)); gap: 10px; }
.pa-card.ms-selected { box-shadow: inset 0 0 0 3px var(--primary); }
.multiselect-bar {
  display: none; position: sticky; top: 56px; z-index: 15; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px 10px; margin-bottom: 12px;
}
body.ms-active .multiselect-bar { display: flex; }
.ms-counter { flex: 1 1 auto; }
.ms-menu-wrap { position: relative; flex: none; }

/* Login */
.login-card { max-width: 380px; margin: 40px auto 0; }
.login-card .btn { margin-top: 14px; }

/* Administration */
.user-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.user-row-checks { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.user-row-actions { display: flex; justify-content: flex-end; }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch-row-text { flex: 1 1 auto; min-width: 0; }
.changed-note { font-size: 0.85rem; color: var(--text-muted); margin: 10px 0; }
.row-menu-panel > .row-menu-divider:first-child { display: none; }

/* Month calendar of a resource */
.res-cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.res-cal th { text-align: center; font-weight: 600; font-size: 0.85rem; padding: 4px 2px; }
.res-cal td { text-align: center; vertical-align: top; height: 3.2rem; padding: 4px 2px; }
.res-cal td.res-cal-empty { background: transparent; border-color: transparent; }
.res-cal-day { display: block; font-size: 0.95rem; }
.res-cal-today .res-cal-day { font-weight: 700; text-decoration: underline; }
.res-cal-marks { display: flex; justify-content: center; gap: 4px; min-height: 10px; margin-top: 4px; }
.res-cal-mark { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.res-cal-booked { background: var(--danger); }
.res-cal-blocked { background: var(--primary); }
.res-cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.res-cal-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 0.9rem; }
.res-cal-legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Notices inside pages (spec 7.5): a hint box; the error variant warns, e.g. about a locked guest. */
.notice { padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); margin: 0 0 12px; }
.notice-warning, .notice-info { border-color: var(--primary); }
.notice-error { border-color: var(--danger); color: var(--danger); }

/* Editor of the terms and conditions (spec 13.10) */
.terms-toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.terms-surface { min-height: 12em; max-height: 32em; overflow: auto; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.terms-surface:focus { outline: 2px solid var(--primary); }
.terms-source { width: 100%; font-family: monospace; }
.terms-text { line-height: 1.5; }

/* Day and month side by side (period dates) */
.inline-fields { display: flex; gap: 8px; }
.inline-fields > * { flex: 1 1 0; min-width: 0; }

[hidden] { display: none !important; }
