/*
 * School calendar - browser styles.
 *
 * No web fonts, no imports and no remote URLs: the Lambda is the only origin
 * this app is allowed to talk to, and the pages are served under a
 * default-src 'self' Content-Security-Policy.
 *
 * ACCESSIBILITY NOTE, and it is a requirement rather than a preference: no
 * state in this app is signalled by colour alone. Overdue rows carry a visible
 * "Overdue" label, the current day carries a visible "Today" marker, and the
 * empty states say in words that they are a good outcome. The colours below
 * are reinforcement only, so the interface survives greyscale printing and
 * colour-blind readers.
 */

:root {
  --ink: #1c2430;
  --ink-soft: #56636f;
  --line: #d8dee6;
  --surface: #ffffff;
  --page: #f4f6f9;
  --accent: #1f5f9c;
  --accent-soft: #e6eff8;
  --good: #1c6b45;
  --good-soft: #e6f4ec;
  --warn: #8a4b0c;
  --warn-soft: #fbeee0;
  --alarm: #93231f;
  --alarm-soft: #fbe7e6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-title {
  margin: 0;
  font-size: 1.35rem;
}

.app-subtitle {
  margin: 0;
  color: var(--ink-soft);
}

.app-nav {
  margin-left: auto;
}

.nav-link,
.link {
  color: var(--accent);
}

/* A bare text link is a ~22px tap target; give the header nav a real one. */
.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.5rem;
}

.app-main {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr);
  gap: 1.25rem;
  padding: 1.25rem 1.5rem 3rem;
  align-items: start;
}

.app-main--narrow {
  grid-template-columns: minmax(0, 640px);
}

.connection-state {
  grid-column: 1 / -1;
  display: grid;
  gap: 0.75rem;
}

.app-body {
  display: contents;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

/* --- Connection / prompt cards --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left-width: 6px;
  border-radius: 8px;
  padding: 1rem;
}

.card-title {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.card-body {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
}

.card--connect {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

.card--reauth {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.card--school {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

.card--identity {
  border-left-color: var(--line);
}

/* --- Buttons and links-as-buttons ---
 *
 * TOUCH TARGETS ARE NOT A PHONE-ONLY CONCERN, so the 44px minimum below is
 * deliberately OUTSIDE any media query. A trackpad, a shaky hand and a stylus
 * all benefit at desktop widths too, and a control that changes size at a
 * breakpoint is a control whose hit area you cannot reason about. The one
 * documented exception is .chip - see the note on it.
 */

.btn {
  font: inherit;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* .btn is also used on <a> elements (e.g. the event detail panel's "Open
     email" link) styled as a button - an anchor's default underline must not
     survive that reuse. */
  text-decoration: none;
}

.btn:hover {
  border-color: var(--accent);
}

.btn[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  font: inherit;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  text-decoration: none;
}

/* Smaller type and tighter padding, but NOT a smaller hit area. */
.btn-small {
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* --- Calendar --- */

.calendar-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.month-heading {
  margin: 0;
  font-size: 1.15rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}

/* --- The processing-job filter ---
 *
 * Same flex/wrap/gap idiom as .calendar-toolbar above, and for the same reason:
 * at 360px the <select> wraps onto its own line UNDER the label rather than
 * pushing the panel past the viewport. Nothing here is given overflow-x - see
 * the phone block at the foot of this file.
 *
 * `display: flex` here does NOT defeat the `hidden` attribute the row ships
 * with: `[hidden] { display: none !important }` below carries !important
 * precisely so a layout rule cannot resurrect a hidden element. Do not weaken
 * or reorder that rule, and do not swap `hidden` for visibility/height:0 - the
 * <select> would stay focusable and tabbable while invisible.
 */
.calendar-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.calendar-filter__label {
  font-weight: 600;
}

/* min-height is OUTSIDE any media query, exactly like .btn: a touch target is
 * not a phone-only concern, and a control whose hit area changes at a
 * breakpoint is one you cannot reason about.
 *
 * `font: inherit` keeps this at the 16px body size. iOS Safari zooms the whole
 * viewport in when a form control smaller than 16px takes focus, and the user is
 * left scrolled and zoomed - the same reason .field-input inherits its font.
 *
 * `max-width: 100%` so a long job name sizes the control to the panel rather
 * than the panel to the name. */
.calendar-filter__select {
  font: inherit;
  min-height: 44px;
  max-width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.calendar-weekdays,
.calendar-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

/* Weeks really are rows: the grid stacks them, each one a seven-column grid. */
.calendar-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
}

.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem;
}

.chip-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.attention-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
}

.detail-value {
  overflow-wrap: anywhere;
}

.settings-summary-name {
  overflow-wrap: anywhere;
}

.weekday {
  padding: 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
}

.day-cell {
  min-height: 96px;
  padding: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.day-cell--outside {
  background: var(--page);
  color: var(--ink-soft);
}

.day-cell--today {
  border-color: var(--accent);
  border-width: 2px;
  background: var(--accent-soft);
}

.day-number {
  font-size: 0.8rem;
  font-weight: 600;
}

/* Paired with the visible "Today" text marker - never colour alone. */
.day-today-marker {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.all-day-band {
  display: grid;
  gap: 2px;
}

/*
 * DELIBERATE EXCEPTION to the 44px touch-target minimum above: a chip gets
 * 28px. A day cell shows up to three of them, and at 44px each the cell would
 * be over 150px tall - a month would not fit on a phone screen at all, which
 * costs more usability than it buys. 28px stays comfortably tappable, and every
 * chip has a full-size alternative route: tapping it opens the detail panel,
 * and the same event is reachable from the attention list's 44px buttons.
 */
.chip {
  font: inherit;
  font-size: 0.78rem;
  min-height: 28px;
  text-align: left;
  padding: 0.15rem 0.3rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.chip--all-day {
  border-left-color: var(--good);
  background: var(--good-soft);
}

.chip--attention {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.chip-time {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  margin-right: 0.3rem;
}

/*
 * Still reads as an underlined link - no border, no background - but it is a
 * real button, so it gets a real hit area rather than the 18px a bare inline
 * control would give it.
 */
.more-toggle {
  font: inherit;
  font-size: 0.75rem;
  border: none;
  background: none;
  color: var(--accent);
  text-align: left;
  padding: 0.1rem 0.6rem;
  min-height: 44px;
  cursor: pointer;
  text-decoration: underline;
}

/* --- Attention panel --- */

.attention-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.attention-item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 0.5rem;
  display: grid;
  gap: 0.25rem;
}

.attention-item--overdue {
  border-left-color: var(--alarm);
  background: var(--alarm-soft);
}

.attention-title {
  font-weight: 600;
}

.attention-meta {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.attention-actions {
  display: flex;
  gap: 0.4rem;
}

/* Panel-level expander: spans the panel so the whole strip under the list is
 * the tap target, rather than a few characters of underlined text. */
.attention-more {
  width: 100%;
  margin-top: 0.25rem;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  border: 1px solid currentColor;
}

.badge--overdue {
  color: var(--alarm);
}

.badge--due {
  color: var(--ink-soft);
}

/* --- Detail panel --- */

.detail-panel {
  grid-column: 1 / -1;
}

.detail-title {
  margin: 0 0 0.5rem;
}

.detail-row {
  margin: 0 0 0.35rem;
}

.detail-label {
  font-weight: 600;
  margin-right: 0.35rem;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* --- Messages --- */

.empty-state {
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  border-radius: 6px;
  color: var(--good);
  background: var(--good-soft);
  border: 1px solid var(--good);
}

.notice {
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--page);
}

.notice--info {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.notice--problem {
  border-color: var(--alarm);
  background: var(--alarm-soft);
}

.scan-message {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--page);
}

/* --- Settings form --- */

.settings-body {
  display: grid;
  gap: 1rem;
}

.settings-summary {
  margin: 0;
  color: var(--ink-soft);
}

.settings-panel {
  display: grid;
  gap: 0.9rem;
}

.field {
  display: grid;
  gap: 0.25rem;
}

.field--inline {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.field-label {
  font-weight: 600;
}

.field-input {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

.field-checkbox {
  width: auto;
}

/*
 * 24px, not 44px: a natively-rendered radio or checkbox blown up to 44px looks
 * broken on every platform. The associated <label> is the large hit area - it
 * is clickable by virtue of its `for`, and every one of these controls has one.
 */
input[type="radio"],
input[type="checkbox"] {
  min-width: 24px;
  min-height: 24px;
}

.field-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.field-error {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--alarm);
}

/* --- Settings: processing jobs (TASK-057, TASK-060) ---
 *
 * A job is one school, its sender domains and its search terms - one .field each,
 * the last two comma-separated - and there can be twenty of them on this page.
 * Two constraints shape everything below.
 *
 * ONE COLUMN, ALWAYS. Every one of these is `display: grid` with a single
 * implicit column, so a row stacks label-over-field at any width and there is
 * nothing to scroll sideways. NOTHING here sets `overflow-x`: a horizontally
 * scrolling region inside a vertically scrolling page is the trap the phone
 * block at the foot of this file explicitly refused for the month grid, and a
 * form is no better a place for it.
 *
 * NO NEW TOUCH-TARGET RULE. Every control the job editor adds carries .btn or
 * .btn-small and every input carries .field-input, so the 44px minimum and the
 * 16px `font: inherit` are inherited from the blocks above - outside any media
 * query, and not restated here where they could drift.
 */

.jobs {
  display: grid;
  gap: 0.75rem;
}

/* Same card language as .settings__section: a job reads as one distinct thing
 * rather than as loose fields that happen to sit near each other. */
.job {
  display: grid;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

.job__head {
  margin: 0;
  font-size: 1rem;
  /* A user-supplied name can be one very long word; wrap it rather than let it
   * push the card wider than the page. */
  overflow-wrap: break-word;
}

/* Wrap rather than shrink: two 44px buttons do not fit beside each other at
 * 360px, and a button that gets smaller at a breakpoint is a hit area you
 * cannot reason about. */
.job__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* The armed state of the in-row remove. Bordered AND worded ("Remove <name>?"),
 * never colour alone - see the docblock at the top of this file. */
.job__confirm {
  display: grid;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--alarm);
  border-radius: 6px;
}

.job__confirm p {
  margin: 0;
}

/* --- Settings: disconnect section ---
 *
 * Same visual language as .panel, which is what the settings form next to it
 * uses: this section was previously unstyled and read as loose text hanging off
 * the bottom of a card.
 */

.settings__section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

.disconnect__choice {
  margin: 0.75rem 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
}

/* Radio in the first column, its label in the second: the label text wraps
 * under itself rather than under the control. */
.disconnect__option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: start;
  margin: 0 0 0.75rem;
}

.disconnect__confirm {
  display: grid;
  gap: 0.25rem;
  margin: 0 0 0.75rem;
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .app-main {
    grid-template-columns: minmax(0, 1fr);
  }
}

/*
 * Phone width. The 860px rule above has already put the panels in one column;
 * this block buys back horizontal room inside them.
 *
 * THE MONTH GRID STAYS A MONTH GRID: seven columns, compressed in place. It is
 * NOT given overflow-x, and it is NOT swapped for an agenda list. A calendar
 * whose weeks you have to scroll sideways stops being something you can read at
 * a glance, which is the only reason to show a month rather than a list.
 *
 * WHAT IS NOT REDUCED HERE, ON PURPOSE: body font-size stays 16px and
 * .field-input keeps `font: inherit`. iOS Safari zooms the page in when a text
 * field smaller than 16px takes focus, and the user is then left scrolled and
 * zoomed on a form they were part-way through. Shrinking type is not worth
 * that; the padding reductions below reclaim the same space.
 */
@media (max-width: 600px) {
  .app-header {
    padding: 0.75rem;
  }

  .app-main {
    padding: 0.75rem 0.75rem 2rem;
    gap: 0.75rem;
  }

  .panel {
    padding: 0.6rem;
  }

  /* Full width and no auto-margin, so the buttons wrap into a block of their
   * own under the month heading instead of being crushed beside it. */
  .toolbar-actions {
    margin-left: 0;
    width: 100%;
  }

  /* Same treatment as .toolbar-actions: a full-width row of its own under its
   * label, rather than a narrow control squeezed beside it. Only the WIDTH
   * changes here - the 44px height and the 16px type stay put. */
  .calendar-filter__select {
    width: 100%;
  }

  .day-cell {
    min-height: 64px;
    padding: 0.15rem;
  }

  .chip {
    font-size: 0.7rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .weekday {
    padding: 0.15rem 0;
    font-size: 0.7rem;
  }

  /* Acknowledge / Dismiss / Details are 44px tall each: at 360px they wrap
   * rather than shrink. */
  .attention-actions {
    flex-wrap: wrap;
  }

  /* Padding only. The job card is already one column at every width, and its
   * buttons and inputs keep their 44px and 16px exactly as everything else here
   * does - this block buys back horizontal room, it does not shrink controls. */
  .job {
    padding: 0.6rem;
  }

  .job__confirm {
    padding: 0.5rem;
  }
}

.mailbox__table {
  width: 100%;
  border-collapse: collapse;
}

.mailbox__table th,
.mailbox__table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #ddd;
  overflow-wrap: anywhere;
}

.mailbox__count {
  white-space: nowrap;
}

/* Privacy and terms pages (static prose). */
.legal { max-width: 46rem; line-height: 1.6; }
.legal h2 { margin: 1.75rem 0 0.5rem; font-size: 1.15rem; }
.legal ul { padding-left: 1.25rem; }
.legal li { margin: 0.35rem 0; }
.legal-updated { opacity: 0.7; font-size: 0.9rem; }

.app-footer { padding: 1rem; text-align: center; font-size: 0.9rem; }
.app-footer a { margin: 0 0.5rem; }
