:root {
  --bg: #f6f4f1;
  --panel: #ffffff;
  --ink: #141414;
  --muted: #6f6b68;
  --line: #e2ddd7;
  --accent: #c2262e;
  --hour: 64px; /* height of one hour in the day grid */
  --day-start: 8;
  --day-end: 20;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label input, label select, label textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
}
label input:focus, label select:focus, label textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.btn { background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px; font-weight: 500; }
.btn:hover { background: var(--accent); }
.btn.small { padding: 8px 14px; font-size: 14px; }
.ghost { padding: 11px 16px; color: var(--muted); }
.danger { padding: 11px 16px; color: var(--accent); }
.error { color: var(--accent); font-size: 14px; margin: 4px 0 10px; }
.hint { color: var(--muted); font-size: 13px; margin: -4px 0 12px; }
[hidden] { display: none !important; }

/* Login */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card { background: var(--panel); border-radius: 18px; padding: 32px 28px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06); }
.login-card { width: 100%; max-width: 360px; }
.login-logo { display: block; width: 220px; margin: 0 auto 28px; }
.login-card .btn { width: 100%; margin-top: 6px; }

/* Bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.icon { width: 36px; height: 36px; border-radius: 10px; font-size: 20px; display: grid; place-items: center; }
.icon:hover, .today:hover { background: var(--bg); }
.today { padding: 0 12px; height: 36px; border-radius: 10px; border: 1px solid var(--line); font-size: 14px; }
#date { border: 0; background: none; width: 0; opacity: 0; padding: 0; margin: 0; }
.title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; cursor: pointer; }
.views { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.view { padding: 0 12px; height: 34px; font-size: 14px; }
.view.active { background: var(--ink); color: #fff; }
.menu {
  position: absolute; right: 10px; top: 54px; z-index: 6;
  display: grid; min-width: 220px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
.menu[hidden] { display: none; }
.menu button { text-align: left; padding: 11px 14px; border-radius: 10px; }
.menu button:hover { background: var(--bg); }

/* Day view */
.calendar { padding-bottom: 90px; }
.day {
  display: grid; grid-template-columns: 48px 1fr 1fr;
  background: var(--panel);
}
.day .head { position: sticky; top: 52px; z-index: 4; background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: center; font-weight: 600; font-size: 14px; }
.day .head.corner { border-right: 1px solid var(--line); }
.day .head .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.times { position: relative; border-right: 1px solid var(--line); padding-top: 8px; }
.times div { height: var(--hour); font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.col { position: relative; border-right: 1px solid var(--line); padding-top: 8px; }
.col:last-child { border-right: 0; }
.slot { height: var(--hour); border-bottom: 1px solid var(--line); background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) / 2 - 1px), #f1eeea calc(var(--hour) / 2 - 1px), #f1eeea calc(var(--hour) / 2)); }
.slot.closed { background: repeating-linear-gradient(135deg, #f7f5f2 0 6px, #efece8 6px 7px); }
.appt {
  position: absolute; left: 3px; right: 3px; overflow: hidden;
  padding: 4px 7px; border-radius: 8px; color: #fff; font-size: 12px; line-height: 1.25;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); cursor: pointer;
}
.appt b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt span { display: block; opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt.short { padding: 1px 7px; font-size: 11px; min-height: 16px; line-height: 14px; }
.appt.short span { display: none; }
.buffer { position: absolute; left: 3px; right: 3px; border-radius: 0 0 6px 6px; opacity: 0.25; background: repeating-linear-gradient(135deg, currentColor 0 3px, transparent 3px 6px); pointer-events: none; }
.now { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 2; pointer-events: none; }
.now::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* Week view */
.week { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); overflow-x: auto; }
.week .wday { background: var(--panel); min-height: 60vh; }
.week .wday.today-col { background: #fffaf2; }
.week .wday h4 { margin: 0; padding: 10px 8px 6px; font-size: 13px; font-weight: 600; text-align: center; border-bottom: 1px solid var(--line); cursor: pointer; }
.week .wday h4 small { display: block; font-weight: 400; color: var(--muted); }
.week .chip { margin: 6px 6px 0; padding: 5px 8px; border-radius: 8px; color: #fff; font-size: 12px; cursor: pointer; }
.week .chip b { font-weight: 600; }
.week .chip span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.9; }
.week .empty { padding: 20px 8px; text-align: center; color: var(--muted); font-size: 12px; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 5;
  width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 30px;
  box-shadow: 0 8px 24px rgba(194, 38, 46, 0.4);
}

/* Dialogs */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(20, 20, 20, 0.45); }
dialog form, .dialog-body { padding: 22px 22px 18px; }
dialog h2 { margin: 0 0 16px; font-size: 20px; font-weight: 600; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.buttons { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.spacer { flex: 1; }

/* Services editor */
.service-cat { margin: 14px 0 6px; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.service-row { display: grid; grid-template-columns: 1.2fr 2fr 64px 90px auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.service-row input { padding: 7px 9px; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; background: #fff; }
.service-row input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.service-row.inactive input { color: var(--muted); background: var(--bg); }
.service-row .acts { display: flex; gap: 2px; }
.service-row .acts button { width: 30px; height: 30px; border-radius: 8px; font-size: 15px; color: var(--muted); }
.service-row .acts button:hover { background: var(--bg); color: var(--ink); }
.service-row.new { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

/* Search */
.results { max-height: 50vh; overflow: auto; margin-top: 10px; }
.results button { display: block; width: 100%; text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.results button:hover { background: var(--bg); }
.results small { color: var(--muted); display: block; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 20; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }
.toast[hidden] { display: none; }

@media (max-width: 560px) {
  .title { font-size: 13px; }
  .today { padding: 0 9px; }
  .row { grid-template-columns: 1fr 1fr; }
  .service-row { grid-template-columns: 1fr 1fr; }
  .service-row input[name="name"] { grid-column: 1 / -1; }
  .service-row .acts { grid-column: 2; justify-content: flex-end; }
  dialog { width: calc(100% - 12px); }
  .day .head { font-size: 13px; }
  :root { --hour: 72px; }
}
