/*
 * telegraph-webaccess frontend styles.
 *
 * Palette mirrors the Telegraph Go Android app
 * (telegraph_brand_guidelines.md + Color.kt):
 *   - Background: NavyVeryDark → NavyDark vertical gradient
 *   - Brand:      Yellow #FFCC33 (logo / CTAs)
 *   - Body text:  white
 *   - Secondary:  Blue200 #BFDBFE / Blue300 #93C5FD
 *   - Errors:     Red400 #F87171
 *   - Success:    AppGreen #10B981
 *
 * No framework. No build step. ~6 KB total. Vanilla CSS variables for
 * easy palette tweaking.
 */

:root {
  --bg-top: #00274D;            /* NavyVeryDark */
  --bg-bottom: #002147;         /* NavyDark */
  --card-bg: rgba(0, 33, 71, 0.7);
  --card-border: rgba(191, 219, 254, 0.18);
  --field-bg: rgba(0, 39, 77, 0.6);
  --field-border: rgba(191, 219, 254, 0.30);
  --field-border-focus: #FFCC33;

  --brand-yellow: #FFCC33;
  --text-primary: #ffffff;
  --text-secondary: #BFDBFE;    /* Blue200 */
  --text-muted: #93C5FD;        /* Blue300 */
  --text-link: #FFD54F;         /* YellowLight */

  --error: #F87171;             /* Red400 */
  --success: #10B981;           /* AppGreen */

  --radius: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-primary);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

/* -- Layout shell ------------------------------------------------------ */

.shell {
  max-width: 480px;
  margin: 2rem auto 0;
  padding: 1.5rem 1rem 1rem;
}

.brand {
  text-align: center;
  margin-bottom: 1.75rem;
}

.brand-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--brand-yellow);
  letter-spacing: 0.01em;
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* -- Card (used by every state screen) -------------------------------- */

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.screen-title {
  margin: 0 0 1.25rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* -- Form fields (mirrors TelegraphTextField look from Android) ------- */

.field {
  display: block;
  margin-bottom: 1rem;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.field input,
.field select {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s ease;
}

.field input::placeholder { color: rgba(191, 219, 254, 0.4); }

.field input:focus,
.field select:focus {
  border-color: var(--field-border-focus);
}

/* select arrow color (inherit from text) */
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23BFDBFE' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.25rem;
}

.field-with-toggle {
  position: relative;
}
.field-with-toggle input { padding-right: 3rem; }
.icon-btn {
  position: absolute;
  right: 0.5rem; top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: var(--brand-yellow);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
}

/* -- Links ------------------------------------------------------------- */

a, .link-right {
  color: var(--text-link);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

.link-right {
  display: block;
  text-align: right;
  font-size: 0.85rem;
  margin: -0.5rem 0 1rem;
}

/* -- CTAs (the big colored action buttons) ---------------------------- */

.cta {
  display: block;
  width: 100%;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--bg-bottom);
  background: var(--brand-yellow);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  margin-top: 0.5rem;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.cta:hover { filter: brightness(1.05); }
.cta:active { transform: translateY(1px); }
.cta:disabled { opacity: 0.5; cursor: not-allowed; }

.ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--field-border);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.ghost:hover { color: var(--text-primary); border-color: var(--brand-yellow); }

/* -- Footer + utility text -------------------------------------------- */

.muted { color: var(--text-secondary); }
.small { font-size: 0.85rem; }
.footnote {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.error {
  color: var(--error);
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
  text-align: center;
}
.page-footer {
  max-width: 480px;
  margin: 1.5rem auto 2rem;
  padding: 0 1rem;
  text-align: center;
}

/* -- State-driven screen visibility ----------------------------------- */

[data-screen] { display: none; }
body[data-state="login"]      [data-screen="login"]      { display: block; }
body[data-state="pair"]       [data-screen="pair"]       { display: block; }
body[data-state="connecting"] [data-screen="connecting"] { display: block; }
/* The ready screen is a flex column (URL bar + iframe filling rest).
   "display: block" here would beat .ready-shell's "display: flex" on
   specificity, killing the flex container — iframe then collapses to
   its default 150px tall, leaving the navy parent bg showing below.
   Caught live 2026-05-10 on ipchicken via gate.*. */
body[data-state="ready"]      [data-screen="ready"]      { display: flex; }
body[data-state="rejected"]   [data-screen="rejected"]   { display: block; }
body[data-state="expired"]    [data-screen="expired"]    { display: block; }

/* -- Pair screen specific ---------------------------------------------- */

.pair-box {
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.25rem 0 1rem;
  text-align: center;
}
.pair-qr-placeholder {
  width: 200px; height: 200px;
  margin: 0 auto 1rem;
  background: white; color: black;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.big-code {
  display: inline-block;
  font-size: 1.5rem;
  letter-spacing: 0.3em;
  color: var(--brand-yellow);
  font-weight: 700;
}

/* -- Ready (URL bar + iframe) ----------------------------------------- */

.ready-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-bottom);
  /* Mobile browsers (Safari iOS, Chrome Android) shrink/grow the
     URL bar with scroll; 100vh includes that hidden chrome which
     makes the layout taller than the visible viewport, cutting the
     iframe in half. 100dvh is the *dynamic* viewport height and
     reflects what's actually visible. inset:0 above is the legacy
     fallback for browsers that don't support dvh. */
  height: 100dvh;
}
.url-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-top);
  border-bottom: 1px solid var(--card-border);
  align-items: center;
}
.url-bar input {
  flex: 1;
  padding: 0.55rem 0.85rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius);
  outline: none;
}
.url-bar input:focus { border-color: var(--brand-yellow); }
.url-bar button[type="submit"] {
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--brand-yellow);
  color: var(--bg-bottom);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

/* Browser-style nav buttons (back / forward / reload) */
.nav-btn {
  width: 2.1rem; height: 2.1rem;
  padding: 0;
  font-size: 1.15rem;
  font-family: inherit;
  line-height: 1;
  color: var(--text-secondary);
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-btn:hover:not(:disabled) {
  color: var(--brand-yellow);
  border-color: var(--brand-yellow);
}
.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#content {
  flex: 1;
  width: 100%;
  border: 0;
  background: white;
}

/* -- Mobile tweaks ---------------------------------------------------- */

@media (max-width: 640px) {
  .shell {
    margin-top: 1rem;
    padding: 1rem 0.75rem;
  }
  .brand-title { font-size: 1.4rem; }
  .tagline { font-size: 0.85rem; }
  .card { padding: 1.15rem; }

  /* Bigger touch targets on mobile (Apple HIG: 44px min). */
  .field input,
  .field select {
    padding: 0.85rem 0.85rem;
    font-size: 1rem;
  }
  .cta {
    padding: 0.95rem 1rem;
    font-size: 1.05rem;
  }
  .icon-btn {
    padding: 0.75rem 0.85rem;
    font-size: 1.25rem;
  }
  .field-with-toggle input { padding-right: 3.25rem; }

  /* URL bar in "ready" state: stack into 2 rows so back/fwd/reload
     get full touch targets and the URL input has the whole width. */
  .url-bar {
    flex-wrap: wrap;
    padding: 0.55rem;
    gap: 0.4rem;
  }
  .url-bar input {
    order: -1;          /* URL input on top */
    flex-basis: 100%;
    min-width: 0;
    padding: 0.7rem 0.85rem;
    font-size: 1rem;
  }
  .nav-btn {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.3rem;
  }
  .url-bar button[type="submit"] {
    flex: 1;             /* "Go" stretches to fill remaining */
    padding: 0.7rem 0.85rem;
    font-size: 1rem;
  }
  .ghost {
    padding: 0.7rem 0.85rem;
    font-size: 0.9rem;
  }

  /* Pair-screen QR shouldn't overflow narrow screens. */
  .pair-qr-placeholder {
    width: min(200px, 60vw);
    height: min(200px, 60vw);
  }
  .big-code {
    font-size: 1.2rem;
    letter-spacing: 0.2em;
  }

  .page-footer { margin: 1rem auto; }
  .footnote { font-size: 0.85rem; }
}

/* On very narrow screens (older / smaller phones, foldables in
   "split" mode), tighten further. */
@media (max-width: 380px) {
  .shell { padding: 0.75rem 0.5rem; }
  .card { padding: 1rem; }
  .brand-title { font-size: 1.25rem; }
}
