:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #111014;
  --surface: #1a181e;
  --surface-2: #211e26;
  --border: #34303a;
  --muted: #aaa3b1;
  --text: #f6f2f8;
  --accent: #b56cff;
  --teal: #35c9b3;
  --blue: #759ad9;
  --danger: #ff7f8b;
  --hour-height: 64px;
  --axis-width: 54px;
  --day-count: 3;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; }
button, input, select { font: inherit; }
button, select, input { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app { height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.topbar {
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) 12px 9px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 16, 20, .94);
  backdrop-filter: blur(16px);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark, .auth-logo {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 38px; height: 38px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--blue), var(--teal));
  color: #151219; font-weight: 900; font-size: 20px;
}
.brand h1 { margin: 0; font-size: 17px; line-height: 1.1; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw; }
.top-actions { display: flex; gap: 5px; }
.icon-button {
  width: 38px; height: 38px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font-size: 21px;
}
.icon-button:active { background: var(--surface-2); }

.auth-panel { flex: 1; overflow: auto; padding: 28px 18px calc(28px + var(--safe-bottom)); display: grid; place-items: center; }
.auth-card { max-width: 430px; padding: 28px 24px; border: 1px solid var(--border); border-radius: 24px; background: var(--surface); text-align: center; box-shadow: 0 24px 80px rgba(0,0,0,.3); }
.auth-logo { width: 62px; height: 62px; margin: 0 auto 18px; border-radius: 18px; font-size: 32px; }
.auth-card h2 { margin: 0 0 10px; font-size: 25px; }
.auth-card > p { color: var(--muted); line-height: 1.55; }
.privacy-copy { font-size: 11px; }

.primary-button, .secondary-button, .danger-button, .text-button, .small-button, .today-button, .mode-button, .nav-button, .fab {
  border: 0; border-radius: 12px; padding: 11px 15px; font-weight: 750;
}
.primary-button { background: var(--accent); color: #17131a; }
.secondary-button { background: #35303b; color: var(--text); }
.danger-button { background: rgba(255,127,139,.15); color: #ff9ba5; border: 1px solid rgba(255,127,139,.3); }
.text-button { background: transparent; color: #d7c0ff; }
.small-button { padding: 7px 9px; background: #302b35; color: var(--muted); font-size: 11px; }
.auth-card .primary-button, .auth-card .text-button { width: 100%; margin-top: 10px; }

.calendar-panel { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.date-nav {
  min-height: 49px; padding: 6px 9px; display: flex; align-items: center; gap: 5px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.nav-button { width: 34px; height: 34px; padding: 0; background: #2a2630; color: var(--text); font-size: 24px; }
.today-button { padding: 9px 11px; background: #2a2630; color: var(--text); font-size: 12px; }
.view-switch { margin-left: auto; display: flex; gap: 2px; padding: 3px; border-radius: 11px; background: #121014; }
.view-switch button { border: 0; border-radius: 8px; padding: 7px 8px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; }
.view-switch button.active { background: var(--surface-2); color: var(--text); }
.status-line { min-height: 0; padding: 0 12px; color: var(--muted); font-size: 11px; transition: min-height .15s, padding .15s; }
.status-line:not(:empty) { min-height: 28px; padding-top: 7px; padding-bottom: 7px; border-bottom: 1px solid var(--border); }

.calendar-shell { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; background: #141217; }
.day-headers, .all-day-row { display: grid; grid-template-columns: var(--axis-width) repeat(var(--day-count), minmax(0, 1fr)); }
.day-headers { min-height: 52px; border-bottom: 1px solid var(--border); background: var(--surface); }
.day-header { padding: 7px 3px; display: grid; place-items: center; border-left: 1px solid var(--border); text-align: center; }
.day-header .weekday { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.day-header .day-number { width: 28px; height: 28px; margin-top: 2px; display: grid; place-items: center; border-radius: 50%; font-size: 15px; font-weight: 750; }
.day-header.today .day-number { background: var(--accent); color: #17131a; }
.header-axis { display: grid; place-items: center; color: var(--muted); font-size: 9px; }

.all-day-row { min-height: 0; max-height: 124px; border-bottom: 1px solid var(--border); background: #17151a; overflow-y: auto; }
.all-day-axis { padding: 8px 5px; color: var(--muted); text-align: right; font-size: 9px; }
.all-day-cell { min-height: 28px; padding: 3px; border-left: 1px solid var(--border); position: relative; }
.all-day-event { display: block; width: 100%; margin-bottom: 3px; padding: 4px 5px; border: 0; border-radius: 6px; color: #fff; font-size: 9px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.time-scroller { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.time-grid { min-height: calc(var(--hour-height) * 24); display: grid; grid-template-columns: var(--axis-width) 1fr; position: relative; }
.time-axis { position: relative; border-right: 1px solid var(--border); background: #151318; }
.hour-label { position: absolute; right: 7px; transform: translateY(-50%); color: #8f8897; font-size: 9px; }
.days-grid { display: grid; grid-template-columns: repeat(var(--day-count), minmax(0, 1fr)); position: relative; }
.day-column { position: relative; min-width: 0; border-left: 1px solid var(--border); background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-height) - 1px), rgba(255,255,255,.085) calc(var(--hour-height) - 1px), rgba(255,255,255,.085) var(--hour-height)); }
.day-column::after { content: ""; position: absolute; inset: 0; pointer-events: none; background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour-height) / 2 - 1px), rgba(255,255,255,.035) calc(var(--hour-height) / 2 - 1px), rgba(255,255,255,.035) calc(var(--hour-height) / 2)); }
.care-shade { position: absolute; left: 0; right: 0; border-radius: 0; pointer-events: none; z-index: 1; }
body.care-editing .care-shade { pointer-events: auto; z-index: 8; border: 2px solid var(--shade-solid); background: var(--shade-edit) !important; cursor: pointer; }
.care-shade-label { display: none; position: sticky; top: 4px; width: fit-content; margin: 5px; padding: 3px 6px; border-radius: 5px; background: rgba(17,16,20,.72); color: #fff; font-size: 9px; font-weight: 800; }
body.care-editing .care-shade-label { display: block; }
.calendar-event { position: absolute; min-height: 18px; padding: 4px 5px; border: 1px solid rgba(255,255,255,.2); border-radius: 7px; color: #fff; text-align: left; overflow: hidden; z-index: 4; box-shadow: 0 1px 5px rgba(0,0,0,.25); }
.calendar-event .event-name { display: block; font-size: 10px; font-weight: 800; line-height: 1.15; }
.calendar-event .event-time { display: block; margin-top: 2px; font-size: 8px; opacity: .88; }
.current-time-line { position: absolute; left: 0; right: 0; height: 1px; background: #ff6c7b; z-index: 9; pointer-events: none; }
.current-time-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 7px; height: 7px; border-radius: 50%; background: #ff6c7b; }

.bottom-actions { position: absolute; left: 0; right: 0; bottom: calc(10px + var(--safe-bottom)); display: flex; justify-content: center; align-items: center; gap: 10px; pointer-events: none; z-index: 15; }
.mode-button, .fab { pointer-events: auto; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.mode-button { background: rgba(32,29,37,.94); color: var(--text); border: 1px solid var(--border); }
.mode-button.active { background: rgba(53,201,179,.2); color: #8bf0e1; border-color: rgba(53,201,179,.5); }
.fab { background: var(--accent); color: #17131a; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.58); z-index: 50; }
.drawer { position: fixed; left: 0; right: 0; bottom: 0; max-height: 91dvh; padding: 6px 16px calc(18px + var(--safe-bottom)); border-radius: 22px 22px 0 0; background: #1a181e; border: 1px solid var(--border); overflow-y: auto; z-index: 60; transform: translateY(105%); transition: transform .22s ease; }
.drawer.open { transform: translateY(0); }
.drawer-handle { width: 44px; height: 4px; margin: 0 auto 8px; border-radius: 3px; background: #5d5763; }
.drawer-header, .modal-header, .section-heading-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.drawer-header h2, .modal-header h2 { margin: 0; font-size: 19px; }
.drawer-header p, .modal-header p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.settings-section { margin: 16px 0; padding-top: 14px; border-top: 1px solid var(--border); }
.settings-section h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #c9c3d0; }
.field-label, .range-label { display: block; margin: 10px 0 6px; color: #d1cad7; font-size: 11px; font-weight: 650; }
.field-help { margin: 7px 0; color: var(--muted); font-size: 10px; line-height: 1.4; }
select, input[type="date"], input[type="time"], input[type="text"] { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #45404b; border-radius: 10px; background: #121014; color: var(--text); }
.calendar-checklist { display: grid; gap: 6px; }
.calendar-choice { display: grid; grid-template-columns: 18px 12px 1fr auto; gap: 8px; align-items: center; padding: 8px; border-radius: 9px; background: #211e26; }
.calendar-choice input { width: 17px; height: 17px; }
.calendar-dot { width: 10px; height: 10px; border-radius: 50%; }
.calendar-choice .calendar-name { min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar-role { color: var(--muted); font-size: 9px; }
.color-row { display: grid; grid-template-columns: 42px 1fr; gap: 8px; align-items: center; margin: 8px 0; }
.color-row input { width: 40px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: #121014; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.drawer-actions { display: grid; gap: 8px; }
.compact-settings { display: grid; grid-template-columns: 1fr 130px; align-items: center; gap: 10px; }

.modal { width: min(94vw, 520px); max-height: 90dvh; padding: 18px; border: 1px solid var(--border); border-radius: 20px; background: #1a181e; color: var(--text); overflow-y: auto; box-shadow: 0 28px 90px rgba(0,0,0,.58); }
.modal::backdrop { background: rgba(0,0,0,.65); }
.caregiver-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.caregiver-choices label { cursor: pointer; }
.caregiver-choices input { position: absolute; opacity: 0; }
.caregiver-choices span { min-height: 42px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 10px; background: #121014; font-size: 12px; font-weight: 750; }
.caregiver-choices input:checked + span { border-color: var(--choice-color); background: color-mix(in srgb, var(--choice-color) 24%, #121014); }
.toggle-label { margin: 14px 0 6px; padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; border-radius: 10px; background: #211e26; font-size: 12px; }
.toggle-label input { width: 19px; height: 19px; accent-color: var(--accent); }
.date-time-grid { display: grid; grid-template-columns: 1fr 120px; gap: 4px 10px; }
.optional { color: var(--muted); font-weight: 400; }
.modal-actions { margin-top: 18px; display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; align-items: center; }
.event-detail { margin-top: 14px; padding: 11px; border-radius: 10px; background: #211e26; color: #d9d2dd; font-size: 12px; line-height: 1.4; }
.event-description { margin: 14px 2px; color: #d9d2dd; white-space: pre-wrap; font-size: 12px; line-height: 1.5; }
.link-button { display: block; margin-top: 16px; text-decoration: none; text-align: center; }
.install-modal ol { padding-left: 23px; color: #d9d2dd; line-height: 1.8; }

@media (min-width: 760px) {
  :root { --axis-width: 64px; }
  .topbar { padding-left: 22px; padding-right: 22px; }
  .date-nav { padding-left: 18px; padding-right: 18px; }
  .bottom-actions { justify-content: flex-end; padding-right: 24px; }
  .drawer { top: 0; bottom: 0; left: auto; width: 410px; max-height: 100dvh; border-radius: 0; transform: translateX(105%); }
  .drawer.open { transform: translateX(0); }
  .drawer-handle { display: none; }
}

@media (max-width: 420px) {
  .view-switch button { padding: 7px 6px; }
  .today-button { padding-left: 8px; padding-right: 8px; }
  .date-time-grid { grid-template-columns: 1fr 105px; }
  .modal-actions { grid-template-columns: auto 1fr auto; }
  .modal-actions span { display: none; }
}
