/* TG Phone styles.
 *
 * Priorities, in order: a focus ring you cannot miss, text that survives a
 * 300% zoom, contrast well past WCAG AA, and nothing that moves on its own.
 * Colour is never the only signal for anything.
 */

:root {
  --bg: #ffffff;
  --fg: #16191d;
  --muted: #4a5058;
  --line: #b9bfc7;
  --card: #f3f5f8;
  --accent: #0b4fa8;
  --accent-fg: #ffffff;
  --danger: #a11616;
  --danger-fg: #ffffff;
  --focus: #b8460e;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --fg: #f1f3f5;
    --muted: #b6bec8;
    --line: #454d57;
    --card: #1b2129;
    --accent: #6fa8ff;
    --accent-fg: #0a1220;
    --danger: #ff8b8b;
    --danger-fg: #2a0808;
    --focus: #ffc266;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 1rem 4rem;
  background: var(--bg);
  color: var(--fg);
  font: 1.05rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 68rem;
  margin-inline: auto;
}

h1 { font-size: 1.6rem; margin: 0.6rem 0 0.2rem; }
h2 { font-size: 1.35rem; margin: 1.2rem 0 0.6rem; }
h3 { font-size: 1.15rem; margin: 1rem 0 0.4rem; }
h4 { font-size: 1.02rem; margin: 0.8rem 0 0.3rem; }
p { margin: 0.4rem 0; }

/* Focus. Deliberately loud — two rings, so it is visible on any background. */
:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: -9999px;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 0.7rem 1rem;
  z-index: 100;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* --- controls ----------------------------------------------------------- */

button, .thread-button, a.button {
  font: inherit;
  min-height: 2.9rem;
  padding: 0.5rem 0.95rem;
  margin: 0.2rem 0.35rem 0.2rem 0;
  background: var(--card);
  color: var(--fg);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
button:hover { border-color: var(--fg); }
button[disabled] { opacity: 0.6; cursor: default; }

button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger  { background: var(--bg); color: var(--danger); border-color: var(--danger); }

/* aria-pressed gets a text-independent marker so a toggle's state is visible
   as well as announced. */
button[aria-pressed="true"]::before { content: "\2713\00a0"; }

input, select, textarea {
  font: inherit;
  min-height: 2.9rem;
  padding: 0.45rem 0.6rem;
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  width: 100%;
  max-width: 34rem;
}
textarea { min-height: 4rem; }

label { display: block; font-weight: 600; margin-bottom: 0.15rem; }
label.inline {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 400; margin: 0.45rem 0; max-width: 46rem;
}
label.inline input { width: 1.3rem; height: 1.3rem; min-height: 0; flex: none; }

.field { margin: 0.7rem 0; }
.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.35rem; margin: 0.6rem 0; }
.hint, .line { color: var(--muted); font-size: 0.95rem; }
.error { color: var(--danger); font-weight: 600; }
.readback { font-weight: 600; min-height: 1.6rem; }

/* --- layout ------------------------------------------------------------- */

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  padding: 0.6rem 0; border-bottom: 2px solid var(--line);
}
.topbar h1 { margin-right: auto; }

.login { max-width: 26rem; margin: 4rem auto; }

[role="tablist"] {
  display: flex; flex-wrap: wrap; gap: 0.25rem;
  border-bottom: 2px solid var(--line); padding: 0.5rem 0;
}
[role="tab"][aria-selected="true"] {
  background: var(--accent); color: var(--accent-fg); border-color: var(--accent);
  font-weight: 700;
}
[role="tabpanel"] { padding-top: 0.5rem; }
[role="tabpanel"]:focus { outline: none; }

/* --- call bar ----------------------------------------------------------- */

.callbar {
  border: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin: 0.8rem 0;
  background: var(--card);
}
.callbar-text { font-size: 1.2rem; font-weight: 700; margin: 0 0 0.4rem; }
.callbar-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.callbar-buttons button { min-width: 8rem; font-size: 1.05rem; }

/* --- keypad ------------------------------------------------------------- */

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(5rem, 7rem));
  gap: 0.5rem;
  margin: 0.6rem 0 1.2rem;
}
.key { min-height: 4rem; display: flex; flex-direction: column; align-items: center;
       justify-content: center; margin: 0; }
.key-digit { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.key-letters { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.06em; }

/* --- lists and cards ---------------------------------------------------- */

ul.plain, ul.cards { list-style: none; padding: 0; margin: 0.5rem 0; }
ul.cards > li { margin-bottom: 0.8rem; }

.card article {
  border: 2px solid var(--line);
  border-left: 6px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  background: var(--card);
}
.card article:focus { outline: 4px solid var(--focus); outline-offset: 2px; }
.summary { font-weight: 600; }
.transcript { white-space: pre-wrap; }

audio { width: 100%; max-width: 34rem; margin: 0.5rem 0; }

details { margin: 0.5rem 0; }
summary { cursor: pointer; min-height: 2.4rem; padding: 0.3rem 0; font-weight: 600; }

.split { display: grid; grid-template-columns: minmax(16rem, 22rem) 1fr; gap: 1.5rem; }
@media (max-width: 52rem) { .split { grid-template-columns: 1fr; } }

.thread-button {
  display: flex; flex-direction: column; align-items: flex-start;
  width: 100%; text-align: left; gap: 0.15rem;
}
.thread-who { font-weight: 700; }
.thread-preview, .thread-when { color: var(--muted); font-size: 0.92rem; }

.msg { border-left: 4px solid var(--line); padding: 0.35rem 0.7rem; margin: 0.5rem 0; }
.msg-outbound { border-left-color: var(--accent); }
.msg > p:first-child { color: var(--muted); font-size: 0.9rem; margin: 0; }
.msg-body { margin: 0.1rem 0 0; white-space: pre-wrap; }

/* --- tables ------------------------------------------------------------- */

table { border-collapse: collapse; width: 100%; margin: 0.6rem 0; }
caption { text-align: left; color: var(--muted); padding-bottom: 0.4rem; }
th, td { border: 1px solid var(--line); padding: 0.45rem 0.55rem; text-align: left;
         vertical-align: top; }
thead th { background: var(--card); }
td button, td a { margin: 0.15rem 0.25rem 0.15rem 0; min-height: 2.5rem; }

dl dt { font-weight: 700; margin-top: 0.6rem; }
dl dd { margin: 0.2rem 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
code { font-family: ui-monospace, Consolas, monospace; word-break: break-all;
       background: var(--card); padding: 0.15rem 0.35rem; border-radius: 4px; }

/* --- dialog ------------------------------------------------------------- */

#help-dialog {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
}
#help-dialog[hidden] { display: none; }
.dialog-inner {
  background: var(--bg); color: var(--fg);
  border: 3px solid var(--accent); border-radius: var(--radius);
  padding: 1.2rem 1.4rem; max-width: 36rem; max-height: 88vh; overflow: auto;
}

/* --- respect the user's settings ---------------------------------------- */

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

@media (prefers-contrast: more) {
  :root { --line: currentColor; --muted: var(--fg); }
  button, input, select, textarea { border-width: 3px; }
}
