/*
 * Page layout.
 *   Phones & tablets (< 1040px): one column, in this order:
 *     header · prompt · banners · filters · needs attention · applications · your data
 *   Desktop (1040–1279px): sidebar | (reminders on top of) main
 *   Wide desktop (≥ 1280px): sidebar | main | reminders rail
 * The sidebar/main/rail wrappers use display: contents on small screens,
 * so their children can be ordered as one column.
 */

body {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 72px;
}
/* Paints the phone's status-bar area so sticky content doesn't show through it. */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 16; background: var(--bg); }

.wrap { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 26px; }
.sidebar, .main, .rail { display: contents; }
.app-header { order: 1; }
.main > .bar-prompt { order: 2; }
.banners { order: 3; }
.tiles { order: 4; }
.rail .attention { order: 5; }
.main > .section:not(.data) { order: 6; }
.main > .data { order: 7; }
.section { display: flex; flex-direction: column; gap: 12px; }

.app-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.app-header .mark { color: var(--wordmark-dot); }
.logo { display: flex; align-items: center; gap: 12px; }
.logo-mark { width: 40px; height: 40px; flex: none; border-radius: 10px; }
.app-header .sub { color: var(--muted); margin-top: 6px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.log-btn { padding: 12px 20px; font-size: .98rem; border-radius: 12px; }
.lang { position: relative; display: inline-flex; align-items: center; color: var(--muted); }
.lang svg { position: absolute; inset-inline-start: 12px; pointer-events: none; }
.lang select { min-height: 44px; padding-block: 8px; padding-inline: 38px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: .9rem; cursor: pointer; }
.log-btn .plus { font-size: 1.2rem; line-height: 1; }

.banners { display: flex; flex-direction: column; gap: 10px; }
.banners:empty { display: none; }

/* Filters stay reachable while scrolling. */
.tiles {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 15;
  background: var(--bg); padding-block: 8px; margin-block: -8px;
}

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.list, .reminders { display: flex; flex-direction: column; gap: 12px; }

/* Floating + button within thumb reach on phones. */
.fab {
  display: none; position: fixed; z-index: 40;
  inset-inline-end: calc(18px + env(safe-area-inset-right, 0px)); bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 62px; height: 62px; border-radius: 20px; padding: 0;
  box-shadow: 0 8px 24px rgb(79 63 216 / .35);
}
.fab svg { width: 28px; height: 28px; }

@media (max-width: 660px) {
  .fab { display: inline-flex; }
  .log-btn { display: none; }
  .app-header { align-items: flex-start; }
  .brand { flex: 1; min-width: 0; }
  body { padding-bottom: 120px; }
  .tiles { gap: 6px; }
}

/* ---------- Desktop: sidebar navigation ---------- */
@media (min-width: 1040px) {
  body { padding: 0; }
  body::before { display: none; }
  .wrap {
    max-width: none; margin: 0; gap: 0; min-height: 100vh;
    display: grid; grid-template-columns: 264px minmax(0, 1fr);
    grid-template-areas: "side rail" "side main"; grid-template-rows: auto 1fr;
  }
  .sidebar, .main, .rail { display: flex; flex-direction: column; }

  .sidebar {
    grid-area: side; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    gap: 22px; padding: 26px 16px 20px;
    background: var(--surface); border-inline-end: 1px solid var(--line);
  }
  .sidebar .app-header { flex-direction: column; align-items: stretch; gap: 18px; padding-inline: 8px; }
  .sidebar h1 { font-size: 1.9rem; }
  .sidebar .logo-mark { width: 34px; height: 34px; }
  .sidebar .sub { font-size: .86rem; }
  .sidebar .header-actions { flex-direction: column; align-items: stretch; gap: 10px; }
  .sidebar .log-btn { order: -1; width: 100%; justify-content: center; }
  .sidebar .lang, .sidebar .lang select { width: 100%; }

  /* Filters become a vertical menu: icon · label · count */
  .tiles { display: flex; flex-direction: column; gap: 2px; position: static; margin: 0; padding: 0; background: none; }
  .tiles .tile { justify-content: flex-start; gap: 12px; padding: 8px 10px; border-color: transparent; background: transparent; border-radius: 10px; }
  .tiles .tile .ico { width: 32px; height: 32px; }
  .tiles .tile .tv { flex: 1; flex-direction: row-reverse; justify-content: space-between; align-items: center; }
  .tiles .tile small { font-size: .95rem; color: var(--ink); font-weight: 600; }
  .tiles .tile b { font-family: var(--body); font-size: .85rem; font-weight: 700; color: var(--muted); min-width: 28px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); text-align: center; }
  .tiles .tile:hover { background: var(--surface-2); }
  .tiles .tile[aria-pressed="true"] { background: var(--cs); border-color: transparent; }
  .tiles .tile[aria-pressed="true"] b { background: var(--c); color: var(--surface); }

  .main { grid-area: main; gap: 24px; padding: 28px 36px 72px; width: 100%; max-width: 1040px; }
  .rail { grid-area: rail; padding: 28px 36px 0; max-width: 1040px; }
  .rail .reminders { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-items: start; }
  .rail .reminders > .allclear, .rail .reminders > .more { grid-column: 1 / -1; }
}

/* ---------- Wide desktop: reminders get their own column on the right ---------- */
@media (min-width: 1280px) {
  .wrap { grid-template-columns: 264px minmax(0, 1fr) 360px; grid-template-areas: "side main rail"; grid-template-rows: 1fr; }
  .main { margin-inline: auto; }
  .rail {
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 28px 20px; background: var(--surface-2); border-inline-start: 1px solid var(--line);
  }
  .rail .reminders { display: flex; flex-direction: column; }
}
