/* KNX Calendar. Layout: one-screen app. Header bar, weekday strip, 6-week month grid filling the rest; dialogs as bottom sheets on phones. Tokens follow the Delitech Kanban app. */
:root {
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --text: #202931; --bg: #fff; --surface: #fff; --subtle: #f6f7fa; --column: #f3f5f8;
  --muted: #66727f; --border: #dfe4ea; --soft: #edf0f3; --hover: #edf0f5;
  --accent: #4f46e5; --accent-fill: #4f46e5; --accent-hover: #4338ca; --accent-soft: #eef2ff; --on-accent: #fff;
  --danger: #be3450; --danger-bg: #fff4f5; --success: #277b62; --success-bg: #edf6f2; --warning: #96500d; --warning-bg: #fffbed;
  --row-min: 124px; --other-month: #f9fafc; --weekdays-bg: #dfe4ea; --today-ring: #4f46e5; --shadow: 0 12px 40px #1b213033;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --text: #eceef3; --bg: #202124; --surface: #2c2e33; --subtle: #303237; --column: #25272b;
  --muted: #b0b6c1; --border: #454850; --soft: #3b3e46; --hover: #3b3e46;
  --accent: #b1b5ff; --accent-fill: #6366f1; --accent-hover: #7779f5; --accent-soft: #373951; --on-accent: #fff;
  --danger: #ffabbc; --danger-bg: #432d35; --success: #8ddbbd; --success-bg: #283d35; --warning: #f5cd82; --warning-bg: #3c352a;
  --other-month: #1c1d20; --weekdays-bg: #3b3e46; --today-ring: #8b8ffa; --shadow: 0 12px 40px #00000080; color-scheme: dark; } }
:root[data-theme="dark"] {
  --text: #eceef3; --bg: #202124; --surface: #2c2e33; --subtle: #303237; --column: #25272b;
  --muted: #b0b6c1; --border: #454850; --soft: #3b3e46; --hover: #3b3e46;
  --accent: #b1b5ff; --accent-fill: #6366f1; --accent-hover: #7779f5; --accent-soft: #373951; --on-accent: #fff;
  --danger: #ffabbc; --danger-bg: #432d35; --success: #8ddbbd; --success-bg: #283d35; --warning: #f5cd82; --warning-bg: #3c352a;
  --other-month: #1c1d20; --weekdays-bg: #3b3e46; --today-ring: #8b8ffa; --shadow: 0 12px 40px #00000080; color-scheme: dark; }

html, body, #root { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px; overflow: hidden; }
* { box-sizing: border-box; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #818cf8; outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.eyebrow { color: var(--muted); font-size: 10px; letter-spacing: 1.4px; font-weight: 700; text-transform: uppercase; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 12px; font-weight: 600; font-size: 13px; min-height: 34px; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.icon-btn { width: 34px; padding: 0; }
svg.i { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Login */
.auth { height: 100%; display: grid; place-items: center; padding-inline: 16px; background: var(--column); overflow-y: auto; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 24px; display: grid; gap: 14px; margin-block: 24px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; letter-spacing: -.5px; }
.brand-symbol { width: 28px; height: 28px; border-radius: 7px; background: var(--accent-fill); color: #fff; display: inline-grid; place-items: center; }
.brand .slash { color: var(--muted); font-weight: 500; }
.auth h1 { font-size: 22px; letter-spacing: -.6px; text-wrap: balance; }
.field { display: grid; gap: 5px; font-weight: 600; font-size: 12px; }
.field input, .field select, .field textarea { border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; background: var(--surface); font-weight: 400; font-size: 14px; min-width: 0; width: 100%; }
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent-fill); outline: 2px solid #6366f133; }
.demo-users { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px 3px 3px; background: var(--surface); font-size: 12px; font-weight: 600; }
button.chip:hover { background: var(--hover); }
.avatar { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-size: 10px; font-weight: 700; flex-shrink: 0; }
.note { border-radius: 8px; padding: 9px 11px; font-size: 12px; line-height: 1.5; background: var(--accent-soft); }
.note.warn { background: var(--warning-bg); color: var(--warning); }
.error { color: var(--danger); font-size: 12px; font-weight: 600; }

/* App shell */
body:has(.app) { background: var(--column); }
.app { --frame-gap: 30px; height: calc(100% - 2 * var(--frame-gap)); margin: var(--frame-gap); display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--surface); box-shadow: 0 2px 12px #1b21300f; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; }
.month-title { font-size: 20px; font-weight: 800; letter-spacing: -.6px; min-width: 0; text-transform: capitalize; }
.month-title .year { color: var(--muted); font-weight: 500; }
.nav { display: flex; gap: 2px; }
.spacer { flex: 1; }
.top-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; background: var(--surface); font-size: 12px; max-width: 160px; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent-fill); color: #fff; font-size: 10px; font-weight: 700; display: inline-grid; place-items: center; }
.user-btn { padding: 3px 10px 3px 3px; border-radius: 999px; }

.weekdays { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--border); background: var(--weekdays-bg); }
.weekdays div { padding: 6px 4px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; text-align: center; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.weekdays .wd-short { display: none; }
@media (max-width: 900px) { .weekdays div { font-size: 10px; letter-spacing: 0; } }
.weekdays div.weekend { color: var(--danger); opacity: .8; }

.grid { flex: 1; display: grid; grid-template-rows: repeat(6, minmax(var(--row-min), 1fr)); min-height: 0; overflow-y: auto; touch-action: pan-y; }
.week { position: relative; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--soft); min-height: 0; overflow: hidden; }
.day { border-right: 1px solid var(--soft); padding: 6px 4px 0; text-align: center; cursor: pointer; background: var(--bg); min-width: 0; position: relative; }
.day:last-child { border-right: 0; }
.day:hover { background: var(--subtle); }
.day.other { background: var(--other-month); }
.day.other .num { color: var(--muted); opacity: .6; }
.num { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.day.today .num { background: var(--accent-fill); color: #fff; }
.day.weekend:not(.other) .num { color: var(--danger); }
.day.today.weekend .num { color: #fff; }
.more { position: absolute; left: 2px; right: 2px; bottom: 3px; height: 16px; font-size: 11px; font-weight: 700; color: var(--muted); border: 0; background: transparent; border-radius: 4px; padding: 1px 0; }
.more:hover { background: var(--hover); color: var(--text); }

.bars { position: absolute; inset: 0; pointer-events: none; }
.bar { position: absolute; height: 18px; border-radius: 4px; color: #fff; font-size: 11px; font-weight: 600; line-height: 18px; padding: 0 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; pointer-events: auto; border: 0; text-align: left; display: flex; gap: 4px; align-items: center; }
.bar:hover { filter: brightness(1.08); box-shadow: 0 1px 4px #0003; }
.bar.cont-left { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.cont-right { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.bar .bell { width: 11px; height: 11px; stroke-width: 2.5; }
.bar.dim { opacity: .25; }

.fab { position: fixed; right: calc(var(--frame-gap, 0px) + 20px); bottom: calc(var(--frame-gap, 0px) + 20px + env(safe-area-inset-bottom, 0px)); width: 56px; height: 56px; border-radius: 16px; border: 0; background: var(--accent-fill); color: #fff; box-shadow: var(--shadow); display: grid; place-items: center; }
.fab:hover { background: var(--accent-hover); }
.fab svg.i { width: 26px; height: 26px; }

/* Dialogs */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); box-shadow: var(--shadow); }
dialog::backdrop { background: #10131a80; }
.sheet { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; padding: 16px 18px 10px; }
.sheet-head h2 { font-size: 18px; letter-spacing: -.4px; flex: 1; min-width: 0; overflow-wrap: anywhere; text-wrap: balance; }
.sheet-body { padding: 4px 18px 16px; overflow-y: auto; display: grid; gap: 14px; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--soft); flex-wrap: wrap; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; font-size: 12px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent-fill); }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.person { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; cursor: pointer; min-width: 0; }
.person:has(input:checked) { border-color: var(--accent-fill); background: var(--accent-soft); }
.person input { accent-color: var(--accent-fill); }
.person span.n { font-weight: 600; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person small { display: block; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person > div { min-width: 0; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; outline: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.reminder-box { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: grid; gap: 10px; background: var(--subtle); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.mono { font-variant-numeric: tabular-nums; }

/* Event record */
.rec-stripe { width: 14px; height: 14px; border-radius: 4px; margin-top: 5px; flex-shrink: 0; }
.rec { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 12px 10px; align-items: start; }
.rec svg.i { color: var(--muted); margin-top: 1px; }
.rec .val { line-height: 1.5; overflow-wrap: anywhere; }
.rec .val strong { font-weight: 700; }
.desc { white-space: pre-wrap; }
.plist { display: flex; flex-wrap: wrap; gap: 6px; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700; }
.status-pill.on { background: var(--success-bg); color: var(--success); }
.status-pill.off { background: var(--subtle); color: var(--muted); }
.confirm { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--danger-bg); color: var(--danger); border-radius: 8px; padding: 8px 10px; font-weight: 600; }

/* Day list + outbox */
.list { display: grid; gap: 6px; }
.list-item { display: flex; gap: 10px; align-items: center; border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; background: var(--surface); text-align: left; width: 100%; min-width: 0; }
.list-item:hover { background: var(--hover); }
.list-item .dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.list-item .t { font-weight: 700; overflow-wrap: anywhere; }
.list-item > div { min-width: 0; flex: 1; }
.mail { border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; display: grid; gap: 6px; }
.mail-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.mail .to { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.status-pill.sent { background: var(--success-bg); color: var(--success); }
.status-pill.queued { background: var(--warning-bg); color: var(--warning); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 13px; box-shadow: var(--shadow); max-width: calc(100% - 32px); z-index: 10; }
.proto-tag { font-size: 10px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--warning); background: var(--warning-bg); border-radius: 6px; padding: 3px 7px; }

@media (max-width: 640px) {
  .topbar { padding: 6px 12px; gap: 6px; }
  .month-title { font-size: 17px; }
  .hide-sm { display: none !important; }
  :root { --row-min: 96px; }
  .app { --frame-gap: 8px; border-radius: 10px; }
  .day { padding: 4px 1px 0; }
  .num { width: 24px; height: 24px; font-size: 12px; }
  .more { font-size: 10px; }
  .bar { height: 15px; line-height: 15px; font-size: 9.5px; padding: 0 3px; border-radius: 3px; }
  .bar .bell { display: none; }
  .weekdays div { padding: 4px 0; font-size: 10px; letter-spacing: 0; }
  .weekdays .wd-full { display: none; }
  .weekdays .wd-short { display: inline; }
  dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 92%; }
  .sheet { max-height: 92vh; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .row2 { grid-template-columns: 1fr; }
  .filter { max-width: 120px; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar { transition: filter .12s; }
  dialog[open] { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(12px); opacity: .6; } }
}

/* Production additions */
.loading-screen { height: 100%; display: grid; place-items: center; color: var(--muted); font-weight: 600; }
.text-button { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 12px; padding: 4px 0; justify-self: start; }
.text-button:hover { text-decoration: underline; }
.banner { display: flex; gap: 10px; align-items: center; padding: 8px 16px; font-size: 12px; font-weight: 600; background: var(--warning-bg); color: var(--warning); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.banner.error { background: var(--danger-bg); color: var(--danger); }
.btn[disabled] { opacity: .55; cursor: default; }
