:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --text: #1f2421;
  --muted: #6b716d;
  --border: #e2ded6;
  --accent: #2f7d6d;
  --accent-text: #ffffff;
  --danger: #b23a2c;
  --today: #fff4d6;
  --other-month: #faf9f7;
  --hover: #efece6;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161917;
    --card: #20241f;
    --text: #e8ebe8;
    --muted: #9aa29d;
    --border: #33392f;
    --accent: #4fae98;
    --accent-text: #0f1a17;
    --danger: #e0705f;
    --today: #3a3420;
    --other-month: #1b1e1b;
    --hover: #2a2f29;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.15rem; }

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: .92rem; }
.spacer { flex: 1; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 130px; }
.row.end { justify-content: flex-end; }

label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }

input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  border-radius: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  background: none;
  color: var(--text);
}
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
button.ghost { border-color: var(--border); }
button.ghost:hover { background: var(--bg); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.icon { padding: 4px 12px; font-size: 1.3rem; line-height: 1; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.auth-card p { margin: 0; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab { flex: 1; padding: 6px; }
.tab.active { background: var(--card); box-shadow: 0 1px 2px rgb(0 0 0 / .12); font-weight: 600; }

/* app shell */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; }
.me { display: flex; align-items: center; gap: 6px; font-size: .95rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.content {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 16px;
}

/* calendar */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-head h2 { min-width: 9.5em; text-align: center; }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays span { text-align: center; font-size: .8rem; color: var(--muted); padding-bottom: 6px; }
.days { border-top: 1px solid var(--border); border-left: 1px solid var(--border); }

.day {
  min-height: 84px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px;
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer;
  text-align: left;
  border-radius: 0;
  background: var(--card);
}
.day.other { background: var(--other-month); color: var(--muted); }
.day:hover { background: var(--hover); }
.day.today .num { background: var(--accent); color: var(--accent-text); }
.num {
  font-size: .82rem; width: 1.8em; height: 1.8em;
  display: grid; place-items: center; border-radius: 50%;
}

.bar {
  position: relative;
  height: 1.45rem;
  margin: 0 -4px;
}
.bar.first { margin-left: 0; border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.bar.last { margin-right: 0; border-top-right-radius: 6px; border-bottom-right-radius: 6px; }
/* Name + holiday note, stretched over the booked days of this week row; cut off with … when too long. */
.bar .label {
  position: absolute; z-index: 1; left: 6px; top: 0;
  width: calc(var(--span) * (100% + 5px) - 14px);
  line-height: 1.45rem;
  font-size: .78rem; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
}
.bar .label b { font-weight: 700; }
.bar .label .info { color: inherit; font-weight: 400; opacity: .9; }

/* upcoming list */
.list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; }
.list li {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.list li:first-child { border-top: 0; }
.list .who { font-weight: 600; }
.list .when { color: var(--muted); font-size: .92rem; }
.list .grow { flex: 1; min-width: 0; }
.list .note { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }

/* dialogs */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 20px;
  width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog p { margin: 0; }

/* range picker in booking dialog */
.range-summary { display: flex; align-items: center; gap: 8px; }
.range-field {
  flex: 1; display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
.range-field span { font-size: .78rem; color: var(--muted); }
.range-field.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.range-arrow { color: var(--muted); }

.mini { border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
.mini-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.mini-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); row-gap: 2px; }
.mini-grid.weekdays span { text-align: center; font-size: .72rem; color: var(--muted); padding-bottom: 4px; }
.mini-day {
  height: 36px; padding: 0; border-radius: 0;
  font-size: .9rem; text-align: center;
}
.mini-day:hover:not(:disabled) { background: var(--hover); border-radius: 8px; }
.mini-day.other { color: var(--muted); opacity: .6; }
.mini-day.today { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.mini-day.booked {
  cursor: not-allowed; color: var(--muted);
  background: repeating-linear-gradient(135deg, transparent 0 4px, color-mix(in srgb, var(--c) 35%, transparent) 4px 6px);
}
.mini-day.in-range { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.mini-day.in-range:hover { border-radius: 0; }
.mini-day.range-start, .mini-day.range-end { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.mini-day.range-start { border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
.mini-day.range-end { border-top-right-radius: 8px; border-bottom-right-radius: 8px; }
.hint { margin: 8px 2px 0; font-size: .85rem; }

button.link { color: var(--accent); padding: 0; align-self: center; font-size: .9rem; }
button.link:hover { text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }
.info { color: var(--accent); margin: 0; font-size: .92rem; }
.info:empty { display: none; }

/* language select */
.auth-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lang-select {
  font: inherit; font-size: .9rem; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 8px; cursor: pointer;
}

/* user management */
dialog.wide { width: min(720px, calc(100vw - 32px)); }
.users li { cursor: default; flex-wrap: wrap; }
.users .grow { min-width: 180px; }
.user-actions { display: grid; grid-template-columns: auto auto auto; align-items: center; gap: 8px; margin-left: auto; }
.admin-toggle { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: .9rem; line-height: 1; cursor: pointer; }
.admin-toggle input { width: 18px; height: 18px; margin: 0; padding: 0; accent-color: var(--accent); }
button.small { padding: 5px 10px; font-size: .85rem; }
.reset-box { background: var(--bg); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.reset-box p { font-size: .9rem; }
#reset-link { flex: 1; min-width: 0; font-size: .85rem; }

/* settings dialog */
.settings-section { border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.settings-section h3 { margin: 0; font-size: 1rem; }
.settings-section p { margin: 0; font-size: .9rem; }
.form-msg { flex: 1; align-self: center; font-size: .9rem; }
.form-msg.error { color: var(--danger); }
.form-msg.ok { color: var(--accent); }

@media (max-width: 600px) {
  .icon-btn span { display: none; }
  .topbar { gap: 6px; padding: 8px 10px; }
  .topbar .brand { font-size: 1rem; }
  .topbar button, .topbar .lang-select { padding: 6px 8px; font-size: .85rem; }
  .day { min-height: 58px; padding: 2px; }
  .bar { height: 1.15rem; margin: 0 -2px; }
  .bar .label { font-size: .66rem; line-height: 1.15rem; left: 3px; width: calc(var(--span) * (100% + 3px) - 8px); }
  .bar .label .info { display: none; }
  .cal-head h2 { min-width: 0; flex: 1; font-size: 1rem; }
  #new-booking { width: 100%; order: 10; }
  .me .name { display: none; }
}
