/* Carolina Painting — design system.
 *
 * Mobile-first. Huriel uses this on a phone, outdoors, one-handed, sometimes in
 * direct sunlight with dusty hands; Amir uses it on a laptop. Where those two
 * conflict, the phone wins.
 *
 * Non-negotiables baked in here:
 *   - 44px minimum on every interactive target (--tap).
 *   - High contrast; no thin grey-on-grey text for anything that matters.
 *   - Safe-area insets so the tab bar clears the iPhone home indicator.
 *   - Light + dark, driven by CSS variables only.
 *
 * Palette carries the marketing site's deep green and warm neutrals so the tool
 * feels like the same business.
 */

:root {
  --green-900: #1f2a24;
  --green-700: #244a3f;
  --green-600: #2f5d4f;
  --green-400: #5c6a61;
  --green-200: #c9cfc9;

  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3efe6;
  --border: #e0dbd0;
  --text: #1f2a24;
  --text-muted: #5c6a61;
  --accent: #2f5d4f;
  --accent-text: #ffffff;
  --danger: #a3312a;
  --danger-bg: #fbeceb;
  --warning: #8a5a12;
  --warning-bg: #fdf3e2;
  --success: #2f5d4f;

  --tap: 44px; /* minimum touch target — do not shrink */
  --radius: 12px;
  --pad: 16px;
  --tabbar-h: 60px;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a17;
    --surface: #1c2420;
    --surface-2: #232d28;
    --border: #33403a;
    --text: #eef2ef;
    --text-muted: #9aa79f;
    --accent: #6fae97;
    --accent-text: #0f1512;
    --danger: #f08b83;
    --danger-bg: #3a1f1d;
    --warning: #e8b96a;
    --warning-bg: #392c17;
    --success: #6fae97;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 17px; /* larger base: read at arm's length in sunlight */
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100%; }

/* ── Shell layout ─────────────────────────────────────────────────────────
   Phone: content scrolls, tab bar pinned to the bottom (thumb reach).
   Wide screens: the same tabs become a left sidebar for laptop use. */

.content {
  padding: var(--pad);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 760px;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}

.tab {
  flex: 1 1 0;
  min-height: var(--tap);
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tab-icon { font-size: 20px; line-height: 1; }

.tab-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 2px;
}

.tab-active { color: var(--accent); }
.tab-active .tab-icon { transform: scale(1.05); }

@media (min-width: 900px) {
  #app:not(.login-mode) {
    display: grid;
    grid-template-columns: 232px 1fr;
    grid-template-areas: "nav offline" "nav content";
    grid-template-rows: auto 1fr;
    min-height: 100vh;
  }
  .tabbar {
    position: sticky;
    top: 0;
    grid-area: nav;
    flex-direction: column;
    height: 100vh;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 24px 12px;
    gap: 4px;
  }
  .tab {
    flex: 0 0 auto;
    height: auto;
    min-height: var(--tap);
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 14px;
    border-radius: var(--radius);
    font-size: 15px;
  }
  .tab-active { background: var(--surface-2); }
  .content {
    grid-area: content;
    padding: 32px;
    padding-bottom: 64px;
    margin: 0;
  }
  .offline-bar { grid-area: offline; }
}

/* ── Offline warning ──────────────────────────────────────────────────────
   Loud on purpose. The app opens fine with no signal and then every save
   fails; the worst outcome is twenty minutes of measurements typed into a
   form that will never save. */

.offline-bar {
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 10px var(--pad);
  font-size: 15px;
  position: sticky;
  top: 0;
  z-index: 15;
}
.offline-bar[hidden] { display: none; }

/* ── Typography ───────────────────────────────────────────────────────── */

.page-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  margin: 4px 0 20px;
  color: var(--text);
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 12px;
}

/* ── Cards ────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 16px;
}

.card.error {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.boot-error { margin: 48px auto; max-width: 420px; text-align: center; }

.empty-state { text-align: center; padding: 32px var(--pad); }
.empty-message { font-size: 18px; margin: 0 0 6px; color: var(--text); }
.empty-sub { font-size: 14px; margin: 0; color: var(--text-muted); }

.warn-note {
  background: var(--warning-bg);
  color: var(--warning);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  margin: 0 0 10px;
}

.account-name { font-size: 18px; font-weight: 600; margin: 0 0 2px; }
.account-email { color: var(--text-muted); font-size: 15px; margin: 0 0 16px; }
.about-card { color: var(--text-muted); font-size: 14px; text-align: center; }
.about-card p { margin: 2px 0; }

/* ── Controls ─────────────────────────────────────────────────────────── */

.btn {
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-block { display: block; width: 100%; }

.choice-row { display: flex; gap: 10px; }

.choice {
  flex: 1 1 0;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.choice-active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 17px; /* >=16px or iOS Safari zooms the page on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ── Login ────────────────────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pad);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
}

.login-brand {
  font-family: var(--font-display);
  font-size: 26px;
  text-align: center;
  color: var(--accent);
  margin-bottom: 24px;
}

.login-error {
  color: var(--danger);
  font-size: 15px;
  min-height: 22px;
  margin-bottom: 8px;
}

.login-lang { margin-top: 20px; }
.login-lang .choice { font-size: 15px; min-height: var(--tap); }

/* ── Toasts ───────────────────────────────────────────────────────────── */

#toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 40;
}

.toast {
  background: var(--green-900);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: none; }
.toast-success { background: var(--green-600); }
.toast-error { background: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
