/* Phone-first. One column, big tap targets, no framework. */

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --text: #1d2420;
  --muted: #5f6b64;
  --line: #dcdad2;
  --accent: #1f6b4a;
  --accent-text: #ffffff;
  --danger: #a32a2a;
  --error-bg: #fbe9e7;
  --ok-bg: #e4f3ea;
  --tap: 3rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a18;
    --surface: #1f2522;
    --text: #e8ebe7;
    --muted: #9aa69f;
    --line: #333b36;
    --accent: #3fa577;
    --accent-text: #0e1612;
    --danger: #e07a73;
    --error-bg: #3a2220;
    --ok-bg: #1d3328;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1.0625rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; }

nav { display: flex; flex-wrap: wrap; align-items: center; }
nav form { margin: 0; }
nav a, button.link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 0.75rem;
  color: var(--text);
  text-decoration: none;
  background: none;
  border: 0;
  font: inherit;
  cursor: pointer;
}
nav a[aria-current="page"] { color: var(--accent); font-weight: 700; box-shadow: inset 0 -3px 0 var(--accent); }

main { max-width: 36rem; margin: 0 auto; padding: 1rem 1rem 3rem; }

h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem; }
a { color: var(--accent); }
.muted, .hint { color: var(--muted); }
.hint { font-weight: 400; font-size: 0.9rem; }

.stack { display: flex; flex-direction: column; gap: 1rem; }
label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; }

input, select {
  min-height: var(--tap);
  padding: 0 0.75rem;
  font: inherit;
  font-size: 1rem; /* 16px or more stops iPhones zooming in on focus */
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}
input:focus-visible, select:focus-visible, button:focus-visible, .button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 1.25rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  text-decoration: none;
  cursor: pointer;
}
button.primary { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }

.msg { padding: 0.75rem 1rem; border-radius: 0.5rem; margin: 0 0 1rem; }
.msg.error { background: var(--error-bg); }
.msg.ok { background: var(--ok-bg); }

.holdings { list-style: none; margin: 0 0 1rem; padding: 0; }
.holdings li {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "ticker edit" "detail detail";
  gap: 0.25rem 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}
.holdings .ticker { grid-area: ticker; font-size: 1.25rem; font-weight: 700; }
.holdings .detail { grid-area: detail; }
.holdings .button { grid-area: edit; }
.sheet-link { margin-left: 0.5rem; font-size: 0.9rem; font-weight: 400; }
.option-name { margin-left: 0.25rem; font-size: 1rem; font-weight: 600; color: var(--muted); }

/* The holding form shows the option fields only while an option is picked. */
form:has(select[name="kind"] option[value="stock"]:checked) .option-only { display: none; }
form:not(:has(select[name="kind"] option[value="stock"]:checked)) .stock-only { display: none; }

.sheet {
  margin: 0 0 1rem;
  padding: 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 0.9rem/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

.notes { color: var(--muted); font-size: 0.95rem; overflow-wrap: anywhere; }

/* --- Chat --------------------------------------------------------------- */

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.chat-head h1 { overflow-wrap: anywhere; }

.past { margin: 0 0 1rem; }
.past summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; color: var(--accent); font-weight: 600; }
.past ul { list-style: none; margin: 0; padding: 0; }
.past li a { display: block; padding: 0.6rem 0.25rem; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.past li a[aria-current="page"] { font-weight: 700; }

.log { display: flex; flex-direction: column; gap: 0.75rem; margin: 0 0 1.25rem; }
.bubble {
  max-width: 92%;
  padding: 0.75rem 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 1rem;
}
.bubble.user { align-self: flex-end; color: var(--accent-text); background: var(--accent); border-bottom-right-radius: 0.25rem; }
.bubble.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 0.25rem; }
.bubble.pending, .bubble.status { color: var(--muted); font-style: italic; }
.bubble.status { align-self: flex-start; padding: 0 1rem; }
.bubble.error { background: var(--error-bg); }

.step { margin: 0 0 0.5rem; font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.25rem; padding: 0; }
.chip {
  min-height: var(--tap);
  padding: 0 1.1rem;
  font-weight: 700;
  border-radius: 999px;
}
.chip[aria-pressed="true"] { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }

.questions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; margin: 0 0 1.25rem; }
.question { padding: 0 0.5rem; font-weight: 500; font-size: 0.95rem; text-align: center; }
.question.picked { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.ask { display: flex; flex-direction: column; gap: 0.5rem; }
.ask textarea {
  width: 100%;
  padding: 0.75rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  resize: vertical;
}
.ask textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.ask-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.web { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 500; min-height: var(--tap); }
.web input { min-height: auto; width: 1.25rem; height: 1.25rem; }
button:disabled { opacity: 0.6; cursor: wait; }

@media (min-width: 30rem) {
  .questions { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 40rem) {
  main { padding-top: 2rem; }
}
