/* Applecado Calendar — clean & modern, light-touch Applecado branding.
   Use the tokens below; don't hard-code colours elsewhere. Lora is for headings/brand only. */

:root {
  --green: #2EB872;
  --green-ink: #1f8f56;
  --leaf: #ADE58F;
  --leaf-soft: #e9f7df;
  --cream: #F8F5EB;
  --coral: #FF5D6E;
  --ink: #1E1E1E;
  --ink-2: #5b5b57;
  --ink-3: #8c8b85;
  --surface: #ffffff;
  --surface-2: #fbfaf6;
  --line: #ebe8df;
  --line-strong: #dcd8cc;
  --shadow: 0 1px 2px rgba(30, 30, 30, .06), 0 8px 24px rgba(30, 30, 30, .08);
  --radius: 12px;
  --radius-sm: 8px;
  --hours: 14;            /* visible hours in the week grid (07–21); must match DAY_START/DAY_END in week.js */
  --hour-min: 34px;       /* grid scrolls rather than squashing hours below this */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Lora, Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --green: #3ccb83;
    --green-ink: #6ee0a5;
    --leaf: #4f7a3a;
    --leaf-soft: #1f2a1c;
    --cream: #121412;
    --coral: #ff7584;
    --ink: #ecebe6;
    --ink-2: #b4b2aa;
    --ink-3: #7f7d76;
    --surface: #1a1c1a;
    --surface-2: #1e211e;
    --line: #2a2d2a;
    --line-strong: #383c38;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 var(--font);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--green-ink); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: 600 14px var(--font); text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-ink); border-color: var(--green-ink); }
@media (prefers-color-scheme: dark) { .btn-primary, .btn-primary:hover { color: #0c1a12; } }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--leaf-soft); border-color: transparent; }
.btn-icon { width: 36px; padding: 0; font-size: 20px; line-height: 1; }
.btn-block { width: 100%; height: 44px; }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--coral); }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--coral) 10%, transparent); border-color: transparent; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }

input[type=text], input[type=email], input[type=password], input[type=date], input[type=time],
input[type=number], input[type=color], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 8px 10px; min-height: 38px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent);
}
textarea { resize: vertical; }
label { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); }
label > input, label > select, label > textarea, label > .dt { margin-top: 6px; }
label.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; color: var(--ink); cursor: pointer; }
label.check input { width: 16px; height: 16px; accent-color: var(--green); margin: 0; }
.stack > * + * { margin-top: 14px; }
.alert {
  background: color-mix(in srgb, var(--coral) 12%, var(--surface)); color: var(--ink);
  border-left: 4px solid var(--coral); padding: 10px 14px; border-radius: var(--radius-sm); margin: 0 0 16px;
}
.field-error { display: block; color: var(--coral); font-weight: 500; margin-top: 4px; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--surface); padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow); font-weight: 500;
  animation: toast-out .4s ease 3.5s forwards;
}
.toast.is-gone { opacity: 0; pointer-events: none; }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); visibility: hidden; } }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  height: 64px; padding: 0 20px;
  background: color-mix(in srgb, var(--cream) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; flex-shrink: 0; }
.brand .avo { color: var(--ink); }
.brand-name { font-family: var(--serif); font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.brand-sub {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--green-ink); background: var(--leaf-soft); padding: 3px 7px; border-radius: 999px;
}
.topbar-centre { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.weeknav { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 1; }
.week-title { font-size: 22px; margin-left: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-new span { font-size: 18px; line-height: 1; }

.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700;
  background: var(--leaf); color: #1E1E1E;
}
.menu-panel {
  position: absolute; right: 0; top: 46px; width: 240px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu-panel a, .menu-panel .linkish {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px;
  color: var(--ink); text-decoration: none; font-size: 14px;
}
.menu-panel a:hover, .menu-panel .linkish:hover { background: var(--leaf-soft); }
.menu-who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-who span { display: block; font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; }

/* ---------- week view ---------- */
.week-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.week-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 12px 20px 20px; gap: 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font: 500 13px var(--font); color: var(--ink); cursor: pointer;
  transition: opacity .15s, background .15s;
}
.filter-chip[aria-pressed=false] { opacity: .45; background: transparent; }
.filter-chip[aria-pressed=false] .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); display: inline-block; flex-shrink: 0; }

.week.is-grid {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(30, 30, 30, .04); overflow: hidden;
}
.wk-head, .wk-allday, .wk-body { display: grid; grid-template-columns: 56px repeat(7, minmax(0, 1fr)); }
.wk-head { border-bottom: 1px solid var(--line); }
.wk-dayhead { padding: 10px 10px 8px; display: flex; align-items: baseline; gap: 6px; border-left: 1px solid var(--line); }
.wk-dayhead .dow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.wk-dayhead .dom { font-family: var(--serif); font-size: 22px; font-weight: 600; line-height: 1; }
.wk-dayhead.is-today .dow { color: var(--green-ink); }
.wk-dayhead.is-today .dom {
  background: var(--green); color: #fff; border-radius: 999px;
  min-width: 32px; height: 32px; display: inline-grid; place-items: center; padding: 0 6px; font-size: 18px;
}
.is-weekend { background-color: var(--surface-2); }

.wk-allday { border-bottom: 1px solid var(--line-strong); min-height: 34px; }
.wk-allday .gutter { display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; }
.wk-allday .gutter span { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.allday-cell { border-left: 1px solid var(--line); padding: 4px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; min-width: 0; }
.allday-cell:hover { background: var(--leaf-soft); }

.wk-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; scrollbar-width: thin; }
.wk-body { position: relative; height: 100%; min-height: calc(var(--hour-min) * var(--hours)); }
.hours { position: relative; }
.hours span {
  position: absolute; right: 8px; transform: translateY(-50%);
  font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.day-col {
  position: relative; border-left: 1px solid var(--line); cursor: copy;
  --half: color-mix(in srgb, var(--line) 50%, transparent);
  /* one tile per hour: solid line on the hour, faint line on the half hour */
  background-image: linear-gradient(to bottom,
    var(--line) 1px, transparent 1px,
    transparent 50%, var(--half) 50%, var(--half) calc(50% + 1px), transparent calc(50% + 1px));
  background-size: 100% calc(100% / var(--hours));
}.day-col.is-today { background-color: color-mix(in srgb, var(--leaf-soft) 55%, transparent); }

.slot-hint {
  display: none; position: absolute; height: calc(100% / var(--hours) / 2); pointer-events: none;
  border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; color: var(--green-ink);
  background: color-mix(in srgb, var(--green) 12%, transparent);
  border: 1px dashed color-mix(in srgb, var(--green) 60%, transparent);
}

.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--coral); z-index: 3; pointer-events: none; }
.now-line i { position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--coral); }

/* item blocks */
.ev {
  --c: var(--green);
  position: absolute; z-index: 2; overflow: hidden;
  display: flex; flex-direction: column; gap: 1px;
  padding: 4px 6px 4px 8px; border-radius: 6px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface));
  border-left: 3px solid var(--c);
  color: var(--ink); text-decoration: none; font-size: 12.5px; line-height: 1.25;
  transition: box-shadow .15s, transform .15s;
  cursor: pointer;
}
.ev:hover { box-shadow: var(--shadow); z-index: 4; background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.ev-top { display: flex; align-items: flex-start; gap: 5px; min-width: 0; }
.ev-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-word; }
.ev-meta { color: var(--ink-2); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ev-icon { font-size: 10.5px; color: var(--ink-3); margin-left: 3px; }
.ev.is-short { flex-direction: row; align-items: center; gap: 6px; padding-top: 2px; padding-bottom: 2px; }
.ev.is-short .ev-title { -webkit-line-clamp: 1; white-space: nowrap; display: block; }
.ev.is-short .ev-top { flex: 1; align-items: center; min-width: 0; }
.ev.is-done { opacity: .55; }
.ev.is-done .ev-title { text-decoration: line-through; }
.ev.is-overdue { border-left-color: var(--coral); }
/* before 07:00 / after 21:00: pinned to the edge, dashed to show it's out of range */
.ev.is-outside { border-left-style: dashed; background: color-mix(in srgb, var(--c) 8%, var(--surface)); }
.ev.is-overdue .ev-meta { color: var(--coral); font-weight: 600; }

.ev-chip { position: relative; flex-direction: row; align-items: center; gap: 5px; padding: 3px 6px 3px 7px; min-height: 24px; }
.ev-chip .ev-title { -webkit-line-clamp: 1; display: block; white-space: nowrap; flex: 1; min-width: 0; }

.tick {
  flex-shrink: 0; width: 15px; height: 15px; margin-top: 1px; padding: 0;
  border-radius: 4px; border: 1.5px solid var(--c); background: var(--surface);
  display: grid; place-items: center; cursor: pointer;
}
.tick svg { width: 11px; height: 11px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.tick:hover { background: color-mix(in srgb, var(--c) 25%, var(--surface)); }
.tick.is-done { background: var(--c); }
.tick.is-done svg { opacity: 1; }

/* mobile list */
.week.is-list { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; padding-bottom: 40px; }
.list-day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.list-day h2 { font-size: 17px; display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.list-day h2 .dow { font-family: var(--font); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.list-day.is-today { border-color: var(--green); box-shadow: 0 0 0 1px var(--green); }
.list-day.is-today h2 .dow { color: var(--green-ink); }
.list-add { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; text-decoration: none; background: var(--leaf-soft); color: var(--green-ink); font: 600 18px var(--font); }
.list-ev { position: relative; flex-direction: row; align-items: center; gap: 8px; padding: 8px 10px; margin-top: 4px; font-size: 14px; }
.list-ev .ev-title { -webkit-line-clamp: 2; flex: 1; }
.list-time { font-size: 12px; color: var(--ink-2); min-width: 44px; font-variant-numeric: tabular-nums; }
.list-empty { margin: 2px 0 4px; color: var(--ink-3); font-size: 13px; }

/* ---------- forms / panels ---------- */
.form-page main, .panel { max-width: 640px; margin: 28px auto 60px; padding: 0 16px; }
.panel-wide { max-width: 860px; }
.panel-head { margin-bottom: 18px; }
.panel-head h1 { font-size: 30px; margin-top: 6px; }
.panel-head p { margin: 6px 0 0; }
.back { font-size: 14px; text-decoration: none; font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 19px; margin-bottom: 12px; }

.item-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 22px; }
.field { border: 0; margin: 0; padding: 0; min-width: 0; }
.field legend, .field .label { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; padding: 0; }
.field-title input {
  font-family: var(--serif); font-size: 24px; font-weight: 600; border: 0; border-bottom: 2px solid var(--line);
  border-radius: 0; padding: 4px 0 8px; background: transparent; box-shadow: none !important;
}
.field-title input:focus { border-bottom-color: var(--green); }

.type-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.type-chip input, .day-chip input { position: absolute; opacity: 0; pointer-events: none; }
.type-chip span {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px;
  border-radius: 999px; border: 1px solid var(--line-strong); font-weight: 500; font-size: 14px; color: var(--ink);
  cursor: pointer; transition: background .15s, border-color .15s;
}
.type-chip input:checked + span { background: color-mix(in srgb, var(--c) 16%, var(--surface)); border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.type-chip input:focus-visible + span, .day-chip input:focus-visible + span { outline: 2px solid var(--green); outline-offset: 2px; }

.when-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
.dt { display: flex; gap: 6px; }
.dt input[type=time] { max-width: 120px; }
.is-all-day .time-only { display: none; }

.repeat-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.repeat-row select { width: auto; min-width: 180px; }
.interval { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); }
.interval input { width: 72px; }
.recur-only, .weekly-only { display: none !important; }
.is-recurring .recur-only { display: inline-flex !important; }
.is-recurring .ends { display: flex !important; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 12px; }
.is-recurring.is-weekly .weekly-only { display: flex !important; }
.ends input[type=date] { width: auto; margin-left: 4px; }
.weekdays { gap: 6px; margin-top: 12px; }
.day-chip span {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line-strong); font-weight: 600; color: var(--ink-2);
}
.day-chip input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; font-size: 14px; color: var(--ink); }
.switch input { position: absolute; opacity: 0; }
.switch-track { width: 40px; height: 23px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .2s; flex-shrink: 0; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--green); outline-offset: 2px; }

.form-actions { display: flex; gap: 8px; padding-top: 4px; }
.danger-zone { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 16px; }
.danger-zone .muted { margin-left: auto; }

/* tables (users, types) */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 0 10px 8px; }
.table td { padding: 10px; border-top: 1px solid var(--line); vertical-align: middle; }
.table td.actions { text-align: right; white-space: nowrap; }
.table input[type=text], .table input[type=email] { min-height: 34px; padding: 6px 8px; }
.table input[type=color] { width: 44px; padding: 2px; min-height: 34px; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--leaf-soft); color: var(--green-ink); }
.inline-form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }

/* ---------- login ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.blob { position: fixed; border-radius: 50%; z-index: 0; pointer-events: none; }
.blob-a { width: 70vmax; height: 70vmax; left: -25vmax; top: -30vmax; background: var(--leaf); opacity: .55; border-radius: 42% 58% 60% 40% / 45% 45% 55% 55%; }
.blob-b { width: 50vmax; height: 50vmax; right: -20vmax; bottom: -25vmax; background: var(--leaf-soft); border-radius: 58% 42% 40% 60% / 55% 50% 50% 45%; }
@media (prefers-color-scheme: dark) { .blob-a { opacity: .25; } }
.auth-card {
  position: relative; z-index: 1; width: 100%; max-width: 380px;
  background: var(--surface); border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-weight: 700; font-size: 26px; margin-bottom: 22px; }
.auth-card h1 { font-size: 26px; }
.auth-card .muted { margin: 4px 0 20px; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .brand-sub { display: none; }
  .week-title { font-size: 18px; margin-left: 6px; }
}
@media (max-width: 760px) {
  .topbar { padding: 0 12px; gap: 8px; height: 58px; }
  .brand-name { display: none; }
  .week-title { font-size: 16px; }
  .btn-new { width: 36px; padding: 0; font-size: 0; }
  .btn-new span { font-size: 22px; }
  .week-wrap { padding: 10px 12px 12px; }
  .when-grid { grid-template-columns: 1fr; }
  .item-form { padding: 18px; }
}
