/* App shell */
html { background: #f3ede1; }
body { margin: 0; min-height: 100vh; background: #17332b; }
.ui.app { height: 100vh; min-height: 100vh; overflow: hidden; }
.ui.app[data-theme="day"] { background: var(--bg); }
.app-inner { height: 100%; min-height: 0; }
.app-masthead { flex: 0 0 auto; }
.app-masthead .ui-brand { min-width: 0; }

/* App controls */
.app-actions {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 1.2cqw; margin: .35cqw 0 .75cqw;
}
.view-switch, .app-tools { display: flex; align-items: center; gap: .4cqw; }
.view-switch {
  padding: .25cqw; border: 1px solid var(--line); border-radius: 99px; background: var(--panel);
}
.view-switch button, .tool-btn {
  border: 0; border-radius: 99px; background: transparent; color: var(--muted);
  padding: .48cqw .95cqw; font: inherit; font-size: .72cqw; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: .3cqw;
  cursor: pointer; white-space: nowrap;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.view-switch button.is-active { background: var(--nav-active-bg); color: var(--nav-active-text); font-weight: 600; }
.view-switch button:hover, .tool-btn:hover { color: var(--text); }
.tool-btn { border: 1px solid var(--line); background: var(--panel); }
.tool-btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.tool-btn--primary:hover { color: #fff; filter: brightness(1.04); }
.tool-btn .icon { width: .75cqw; height: .75cqw; }
.tool-btn.danger { color: var(--accent); border-color: var(--accent-line); }

/* Views */
.month-view { flex: 1; min-height: 0; display: flex; }
.month-view .tv-dashboard { width: 100%; }
.cal-grid { grid-template-rows: none; grid-auto-rows: 1fr; }
.day { cursor: pointer; }
.day:hover { box-shadow: inset 0 0 0 1px var(--line); }
.day.outside { cursor: pointer; }
.day .pills { pointer-events: none; }

.week-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.week-view .week-title { margin-top: .2cqw; }
.week-view .week-grid { min-height: 0; }
.week-view .week-col { cursor: pointer; }
.week-view .week-col:hover { border-color: var(--accent-line); }
.week-view .week-sync { font-size: 1cqw; }

.day-view { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 1.2cqw 0; }
.day-card {
  width: min(100%, 430px); container-type: inline-size;
  padding: 6cqw 6.4cqw 3.4cqw;
  background: var(--panel); border: 1px solid var(--line); border-radius: 5cqw;
  box-shadow: var(--shadow);
}
.day-card .phone-section { margin-top: 4.6cqw; }
.day-card .phone-next { margin-top: 3.8cqw; }
.day-card .phone-tomorrow { margin-top: 3.6cqw; }
.day-card .phone-greeting { font-size: 8.8cqw; }
.day-record-status { margin-left: auto; font-size: 2.5cqw; color: var(--muted); white-space: nowrap; }
.pt-event.is-now { color: var(--accent); }
.pt-event.is-now .pt-check { background: var(--accent-soft); color: var(--accent); }
.pt-event.is-past { opacity: .62; }

.app-footer {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 2cqw; margin-top: .8cqw; font-family: var(--mono); font-size: .52cqw;
  letter-spacing: .04em; color: var(--muted);
}
.app-footer #data-status { text-align: right; }

/* Empty states */
.agenda-empty, .week-empty, .dialog-empty {
  display: grid; place-items: center; min-height: 7cqw; padding: 2cqw 1cqw;
  color: var(--muted); font-size: .75cqw; text-align: center; line-height: 1.7;
}
.week-empty { font-family: var(--serif); font-size: 1.2cqw; opacity: .7; }

/* Dialogs */
.app-dialog {
  width: min(560px, calc(100% - 32px)); padding: 26px; border: 1px solid rgba(26, 38, 33, .14);
  border-radius: 18px; background: #fbf6ec; color: #1a2621;
  box-shadow: 0 30px 80px rgba(12, 27, 23, .3); font-family: var(--sans);
}
.app-dialog::backdrop { background: rgba(8, 18, 15, .55); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-head .ui-kicker { color: #963a22; }
.dialog-head h2 { margin: 6px 0 0; font-family: var(--serif); font-size: 26px; letter-spacing: -.04em; }
.dialog-close {
  width: 32px; height: 32px; border: 1px solid rgba(26, 38, 33, .12); border-radius: 50%;
  background: transparent; color: #5e6962; font-size: 20px; line-height: 1; cursor: pointer;
}
.dialog-close:hover { background: rgba(26, 38, 33, .05); }
.dialog-meta { margin: 10px 0 16px; color: #78837c; font-size: 12px; line-height: 1.6; }
.dialog-list { max-height: 46vh; overflow: auto; }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-actions .tool-btn {
  border: 1px solid rgba(26, 38, 33, .14); background: #fff; color: #3c4b44;
  border-radius: 10px; padding: 9px 14px; font-size: 12px; font-weight: 600;
}
.dialog-actions .tool-btn:hover { background: #f4efe5; }
.dialog-actions .tool-btn--primary { background: #c25536; border-color: #c25536; color: #fff; }
.dialog-actions .tool-btn.danger { margin-right: auto; color: #b3432a; }
.dialog-day-event {
  display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 12px 0; border-top: 1px solid rgba(26, 38, 33, .09);
}
.dialog-day-event:first-child { border-top: 0; }
.dialog-day-event time { font-size: 12px; font-weight: 600; color: #1a2621; font-variant-numeric: tabular-nums; }
.dialog-day-event strong { display: block; font-size: 13px; font-weight: 600; }
.dialog-day-event span { display: block; margin-top: 2px; font-size: 11px; color: #78837c; }
.dialog-event-actions { display: flex; gap: 4px; }
.dialog-event-actions button {
  border: 0; background: transparent; color: #78837c; font: inherit; font-size: 11px;
  cursor: pointer; padding: 4px 6px; border-radius: 6px;
}
.dialog-event-actions button:hover { background: rgba(26, 38, 33, .06); color: #1a2621; }
.dialog-event-actions button.delete:hover { color: #b3432a; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field--wide { grid-column: 1 / -1; }
.field span { font-size: 11px; color: #78837c; }
.field input, .field select {
  width: 100%; box-sizing: border-box; border: 1px solid rgba(26, 38, 33, .16);
  border-radius: 9px; background: #fff; color: #1a2621; font: inherit; font-size: 13px;
  padding: 10px 11px; outline: none;
}
.field input:focus, .field select:focus { border-color: #c25536; box-shadow: 0 0 0 3px rgba(194, 85, 54, .1); }
.form-error { margin: 12px 0 0; color: #b3432a; font-size: 12px; }

.app-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 50; padding: 10px 16px; border-radius: 99px;
  background: #17332b; color: #f7f1e4; font-size: 12px; font-weight: 500;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .2);
}

/* Responsive */
@media (max-width: 1000px) {
  body { overflow: auto; }
  .ui.app { height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  .app-inner { height: auto; min-height: 0; padding: 4vw 4vw 3vw; }
  .app-actions { margin: .8vw 0 1.6vw; }
  .view-switch button, .tool-btn { font-size: 12px; padding: 8px 13px; }
  .tool-btn .icon { width: 13px; height: 13px; }
  .month-view { display: block; }
  .tv-dashboard { display: flex; flex-direction: column; gap: 16px; margin-top: 0; }
  .calendar { min-height: 62vh; }
  .tv-side { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
  .today-agenda, .weather-card--rail { min-height: 0; }
  .tv-side { flex: none; }
  .app-footer { font-size: 9px; margin-top: 18px; }
  .day-view { padding: 10px 0; }
  .week-view { min-height: 58vh; }
}
@media (max-width: 640px) {
  .app-masthead { grid-template-columns: 1fr auto; }
  .app-masthead .cal-month-group { grid-column: 1 / -1; justify-self: stretch; justify-content: space-between; margin-top: 8px; }
  .app-masthead .ui-clock { grid-column: 2; grid-row: 1; }
  .app-actions { align-items: flex-start; flex-wrap: wrap; }
  .view-switch { width: 100%; justify-content: space-between; }
  .view-switch button { flex: 1; }
  .tv-side { grid-template-columns: 1fr; }
  .calendar { min-height: 68vh; }
  .cal-grid { gap: 2px; }
  .day { padding: 3px; }
  .day-note { font-size: 6px; }
  .pill { font-size: 7px; }
  .week-view .week-grid { overflow-x: auto; grid-template-columns: repeat(7, minmax(112px, 1fr)); }
  .week-view .week-col { min-height: 300px; }
  .day-card { width: 100%; border-radius: 24px; padding: 8vw 7vw 6vw; }
  .day-card .phone-greeting { font-size: 34px; }
  .app-footer { flex-direction: column; align-items: flex-start; gap: 4px; }
  .form-grid { grid-template-columns: 1fr; }
  .field--wide { grid-column: auto; }
}


/* Hidden views must win over the flex display declarations. */
.month-view[hidden], .week-view[hidden], .day-view[hidden] { display: none !important; }

/* App air-quality grades */
.air-item strong.grade-good { color: #a8e3c0; }
.air-item strong.grade-moderate { color: #e2b054; }
.air-item strong.grade-bad,
.air-item strong.grade-very-bad { color: #f0b397; }

/* Day-view event states */
.pt-check.is-upcoming { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.pt-check.is-now { background: var(--accent-soft); color: var(--accent); }
.pt-event.is-now { color: var(--accent); }
.pt-event.is-now .pt-check { background: var(--accent-soft); color: var(--accent); }

/* Week view scale and note colours */
.week-view .week-title h2 { font-size: clamp(28px, 3.4cqw, 46px); }
.week-view .week-title .ui-kicker { font-size: clamp(8px, .78cqw, 10px); }
.week-view .week-title p { font-size: clamp(11px, .95cqw, 14px); }
.w-note-line { display: flex; align-items: baseline; min-width: 0; white-space: nowrap; overflow: hidden; }
.w-anno.term { color: #8a6a1f; font-weight: 600; }
.w-anno.holiday { color: var(--accent); font-weight: 600; }
.week-col.today .w-anno.term { color: #f0cc84; }
.week-col.today .w-anno.holiday { color: #f0b397; }
.w-note-line .sep { color: var(--muted); font-size: .85cqw; }

/* Phone-style day view */
.day-card { display: flex; flex-direction: column; height: 100%; max-height: 660px; min-height: 600px; }
.day-card .phone-nav { margin-top: auto; }
.day-nav button { cursor: pointer; }
.day-nav button.active { color: var(--text); }
@media (max-width: 640px) {
  .day-card { height: auto; max-height: none; min-height: 0; }
  .day-card .phone-nav { margin-top: 24px; }
}

/* Mobile app chrome readability */
@media (max-width: 640px) {
  .cal-masthead .ui-brand { gap: 8px; }
  .cal-masthead .ui-mark { width: 28px; height: 28px; font-size: 15px; }
  .cal-masthead .ui-brand strong { font-size: 16px; }
  .cal-masthead .ui-brand div span { font-size: 10px; margin-top: 2px; }
  .cal-masthead .ui-clock strong { font-size: 18px; }
  .cal-masthead .ui-clock span { font-size: 10px; margin-top: 3px; }
  .cal-month { gap: 1px; }
  .cal-month .ui-kicker { font-size: 9px; letter-spacing: .08em; }
  .cal-month h2 { font-size: 21px; }
  .cal-nav { font-size: 11px; gap: 6px; }
  .cal-nav button { width: 24px; height: 24px; }
  .cal-nav button .icon { width: 12px; height: 12px; }
  .cal-sync { font-size: 9px; gap: 4px; }
  .cal-sync i { width: 5px; height: 5px; }
  .app-actions { flex-wrap: nowrap; gap: 8px; align-items: center; }
  .view-switch { width: auto; flex: 1; min-width: 0; padding: 3px; }
  .view-switch button { flex: 1; padding: 7px 4px; font-size: 11px; }
  .app-tools { flex: 0 0 auto; gap: 4px; }
  .tool-btn { padding: 7px 9px; font-size: 11px; }
  .tool-btn .icon { width: 12px; height: 12px; }
  .app-masthead .cal-month-group { margin-top: 10px; }
}

/* Mobile month overview: compact calendar, details live in day view */
@media (max-width: 640px) {
  .month-view { display: flex; flex-direction: column; min-height: calc(100vh - 122px); min-height: calc(100dvh - 122px); }
  .month-view .tv-side { display: none; }
  .month-view .tv-dashboard { display: flex; flex: 1; min-height: 0; }
  .month-view .calendar { flex: 1; min-height: 0; padding: 10px; }
  .month-view .cal-grid { gap: 2px; }
  .month-view .weekdays { font-size: 8px; padding: 3px 0; }
  .month-view .day { padding: 4px 3px; border-radius: 4px; }
  .month-view .day .num { font-size: 11px; }
  .month-view .day-lunar { font-size: 7px; }
  .month-view .day-notes { margin-top: 1px; }
  .month-view .day-note { font-size: 6.5px; line-height: 1.2; }
  .month-view .day-note:nth-child(n+2) { display: none; }
  .month-view .pills { gap: 1px; margin-top: 2px; }
  .month-view .pill { font-size: 7px; line-height: 1.25; padding: 1px 2px; border-radius: 2px; }
  .month-view .day.today .pill { font-size: 7px; line-height: 1.25; padding: 1px 2px; }
  .month-view .pill-more { font-size: 6px; padding: 0 2px; right: 2px; }
}

/* Empty-state call to action */
.empty-add {
  display: inline-flex; align-items: center; justify-content: center;
  margin-top: .55cqw; padding: .35cqw .8cqw; border-radius: 99px;
  border: 1px solid var(--accent-line); background: var(--accent-soft);
  color: var(--accent); font: inherit; font-size: .7cqw; font-weight: 600;
  cursor: pointer;
}
.empty-add:hover { filter: brightness(.98); }
.app-dialog .empty-add { margin-top: 10px; padding: 8px 13px; font-size: 12px; }

/* Full-screen app shell */
body { background: #f3ede1; }
.app-shell {
  width: 100%; height: 100vh; height: 100dvh; min-height: 0;
  display: flex; flex-direction: column; align-items: stretch;
  gap: 0; padding: 0; background: #f3ede1;
}
.app-toolbar {
  flex: 0 0 auto; width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1.2cqw; padding: 1.1cqw 1.6cqw .55cqw; color: var(--text);
}
.app-toolbar-label {
  font-family: var(--mono); font-size: clamp(8px, .52cqw, 11px); letter-spacing: .2em;
  color: var(--muted); white-space: nowrap;
}
.app-toolbar .app-actions { margin: 0; flex: 0 1 auto; display: flex; align-items: center; gap: .55cqw; }
.app-toolbar .view-switch {
  background: var(--panel); border-color: var(--line); padding: .22cqw;
}
.app-toolbar .view-switch button {
  font-size: clamp(12px, .84cqw, 16px); padding: .48cqw 1.15cqw; color: var(--muted);
}
.app-toolbar .view-switch button.is-active { background: var(--nav-active-bg); color: var(--nav-active-text); }
.app-toolbar .tool-btn {
  background: var(--panel); border-color: var(--line);
  color: var(--text-2); font-size: clamp(12px, .8cqw, 15px); padding: .48cqw 1cqw;
}
.app-toolbar .tool-btn:hover { color: var(--text); background: var(--panel-2); }
.app-toolbar .tool-btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.app-toolbar .tool-btn--primary:hover { background: var(--accent); color: #fff; filter: brightness(1.04); }
.app-toolbar .tool-btn .icon { width: clamp(13px, .9cqw, 17px); height: clamp(13px, .9cqw, 17px); }

.ui.app {
  width: 100%; height: 100vh; height: 100dvh; max-height: none;
  aspect-ratio: auto; border-radius: 0; border: 0; box-shadow: none;
  display: flex; flex-direction: column;
}
.app-inner { flex: 1 1 auto; height: auto; min-height: 0; padding: 0 1.6cqw; }
.app-footer {
  flex: 0 0 auto; width: 100%; margin: 0; padding: .5cqw 1.6cqw .75cqw;
  color: var(--muted); font-size: clamp(8px, .52cqw, 11px);
}
.app-footer #data-status { color: var(--muted); opacity: .8; }
.week-view { width: 100%; max-width: none; margin: 0; }

/* The day view is the proposal's night phone: keep its palette even in day mode. */
.day-card {
  --bg: #0c1b17; --panel: #152722; --panel-2: #11211c; --text: #f4eee2;
  --text-2: #c4cfc8; --muted: #93a29a; --line: rgba(255, 255, 255, .12);
  --line-soft: rgba(255, 255, 255, .07); --accent: #e29370; --accent-deep: #f0b397;
  --accent-soft: rgba(226, 147, 112, .15); --accent-line: rgba(226, 147, 112, .36);
  --forest: #1d3a31; --gold: #ecc477; --green: #8fd0ad; --sky: #9ab6c8;
  width: min(100%, 340px); height: auto; min-height: 0; max-height: none;
  padding: 5.2cqw 5.4cqw 2.8cqw; background: var(--panel); color: var(--text);
  border-color: var(--line); border-radius: 5.5cqw;
  box-shadow: 0 24px 60px rgba(5, 15, 12, .32);
}
.day-card .phone-greeting { font-size: 8.4cqw; }
.day-card .phone-section { margin-top: 4cqw; }
.day-card .phone-next { margin-top: 3.2cqw; }
.day-card .phone-tomorrow { margin-top: 3cqw; }
.day-card .phone-nav { padding-bottom: 1.2cqw; }
.day-view { align-items: flex-start; padding: 1cqw 0; }

@media (max-width: 1000px) {
  .app-shell { height: auto; min-height: 100vh; min-height: 100dvh; padding: 0; gap: 0; }
  .app-toolbar { width: 100%; padding: 12px 16px 8px; }
  .app-toolbar-label { display: none; }
  .app-toolbar .app-actions { width: 100%; gap: 8px; }
  .app-toolbar .view-switch { padding: 3px; }
  .app-toolbar .view-switch button { font-size: 12px; padding: 8px 13px; }
  .app-toolbar .tool-btn { font-size: 12px; padding: 8px 13px; }
  .app-toolbar .tool-btn .icon { width: 14px; height: 14px; }
  .ui.app {
    width: 100%; aspect-ratio: auto; height: auto; max-height: none;
    min-height: 100vh; min-height: 100dvh;
    border-radius: 0; border: 0; box-shadow: none;
  }
  .app-inner { flex: 1 0 auto; height: auto; min-height: 0; padding: 0 16px; }
  .app-footer { width: 100%; padding: 10px 16px 14px; font-size: 9px; }
}

/* Day-card empty state */
.day-card .dialog-empty {
  min-height: 10cqw; padding: 2.6cqw 2cqw;
  font-size: 2.7cqw; line-height: 1.6;
}
.day-card .dialog-empty .empty-add {
  margin-top: 1.4cqw; padding: 1cqw 1.8cqw;
  font-size: 2.5cqw; border-radius: 99px;
}

/* Fill the day stage like the proposal's phone screen */
.ta-list > .agenda-empty { flex: 1; }
.day-view { align-items: center; padding: .8cqw 0; }
.day-view .day-card {
  width: min(100%, 430px); height: 100%; max-height: 820px;
  padding: 26px 30px 18px;
}
@media (max-width: 640px) {
  .day-view { align-items: flex-start; padding: 10px 0; }
  .day-view .day-card { width: 100%; height: auto; max-height: none; padding: 8vw 7vw 6vw; }
}

/* Tablet / small-laptop adaptations */
@media (max-width: 1000px) {
  .tv-side .today-agenda { min-height: 280px; }
  .tv-side .weather-card--rail { min-height: 230px; }
  .day-view { min-height: 620px; }
  .day-view .day-card { width: min(100%, 430px); height: auto; max-height: none; }
}

/* Keyboard focus for interactive calendar surfaces */
.day:focus-visible,
.week-col:focus-visible,
.ta-event:focus-visible,
.pt-event:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#stage-head:empty { display: none; }
#stage-head { flex: 0 0 auto; }

.agenda-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .65cqw; padding: 3cqw 1cqw; text-align: center;
}
.agenda-empty p { margin: 0; font-size: .78cqw; color: var(--muted); line-height: 1.6; }
.agenda-empty .empty-icon { width: 2.4cqw; height: 2.4cqw; color: var(--muted); opacity: .5; stroke-width: 1.3; }
.agenda-empty .empty-add { margin-top: .2cqw; }
@media (max-width: 1000px) {
  .agenda-empty p { font-size: 12px; }
  .agenda-empty .empty-icon { width: 32px; height: 32px; }
  .agenda-empty { gap: 8px; padding: 24px 12px; }
}

/* Google Calendar connection */
.app-footer-right {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 1cqw; flex-wrap: wrap;
}
.google-status {
  border: 1px solid var(--line); border-radius: 99px; background: var(--panel);
  color: var(--text-2); font: inherit; font-size: clamp(8px, .54cqw, 11px);
  padding: .28cqw .72cqw; cursor: pointer; white-space: nowrap;
}
.google-status:hover { color: var(--text); background: var(--panel-2); }
.google-status[data-state="connected"] { color: var(--green); border-color: var(--line); }
.google-status[data-state="loading"],
.google-status[data-state="connecting"] { color: var(--muted); }
.google-status[data-state="error"],
.google-status[data-state="expired"] { color: var(--accent); border-color: var(--accent-line); }
.google-status[hidden] { display: none; }

.g-mark {
  display: inline-grid; place-items: center; width: 1.35em; height: 1.35em;
  border-radius: 50%; background: #4285f4; color: #fff;
  font-family: var(--sans); font-size: .68em; font-weight: 700; line-height: 1;
  vertical-align: .08em;
}
.google-badge {
  display: inline-flex; align-items: center; gap: .25em;
  color: #4285f4; font-size: .9em; font-weight: 600; white-space: nowrap;
}
.google-link {
  color: #4285f4; font-size: 11px; font-weight: 600; text-decoration: none;
  padding: 4px 6px; border-radius: 6px;
}
.google-link:hover { background: rgba(66, 133, 244, .08); }

@media (max-width: 1000px) {
  .app-footer-right { gap: 8px; }
  .google-status { font-size: 9px; padding: 4px 8px; }
}

.pill.google { box-shadow: inset .22cqw 0 0 #4285f4; }

/* Keep Google badges inline inside event rows that style generic spans as blocks. */
.ui .g-mark { display: inline-grid; margin-top: 0; vertical-align: middle; }
.ui .dialog-day-event .person { display: inline-flex; margin-top: 0; }
.ui .dialog-day-event .google-badge { display: inline-flex; margin-top: 0; }

/* The day dialog lives outside .ui, so override its generic span rule directly. */
.dialog-day-event .g-mark { display: inline-grid; margin-top: 0; vertical-align: middle; }
.dialog-day-event .person { display: inline-flex; margin-top: 0; }
.dialog-day-event .google-badge { display: inline-flex; margin-top: 0; }

.google-status:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
