/* Picky PWA — mobile-first chat. Colours as tokens; dark mode follows the system. */
:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --text: #1d1a27;
  --muted: #6f6a80;
  --line: #e6e3ef;
  --accent: #6d28d9;
  --accent-2: #c026d3;
  --me: #6d28d9;
  --me-text: #ffffff;
  --picky: #ffffff;
  --picky-text: #1d1a27;
  --error: #c62828;
  --shadow: 0 1px 2px rgba(20, 10, 40, .06), 0 2px 8px rgba(20, 10, 40, .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121019;
    --surface: #1c1926;
    --text: #ece9f5;
    --muted: #9d97b0;
    --line: #2c2838;
    --accent: #a78bfa;
    --me: #6d28d9;
    --picky: #231f30;
    --picky-text: #ece9f5;
    --error: #ef9a9a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }

/* Login */
.login {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom)); text-align: center;
}
.login-logo { border-radius: 22px; box-shadow: var(--shadow); }
.login h1 { margin: 16px 0 4px; font-size: 28px; }
.login form { width: 100%; max-width: 340px; margin-top: 20px; display: grid; gap: 12px; }
.login input {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 16px;
}
.primary {
  padding: 14px; border: 0; border-radius: 14px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, #6d28d9, #c026d3); cursor: pointer;
}

/* Chat layout: header / scrolling messages / composer */
.app { height: 100dvh; display: flex; flex-direction: column; }
.bar {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.who { display: flex; align-items: center; gap: 10px; }
.who img { border-radius: 10px; }
.name { font-weight: 700; }
.status { font-size: 12px; color: var(--muted); }
.status.busy { color: var(--accent); }
.icon-btn {
  display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer; fill: currentColor; flex: none;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.menu {
  position: absolute; right: 12px; top: calc(100% - 4px); z-index: 10; min-width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.18);
}
.menu button { display: block; width: 100%; text-align: left; padding: 11px 12px; border: 0; border-radius: 10px; background: none; cursor: pointer; }
.menu button:active { background: var(--line); }

.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 8px;
}
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.msg {
  max-width: 84%; padding: 10px 14px; border-radius: 18px; box-shadow: var(--shadow);
  overflow-wrap: anywhere; white-space: normal;
}
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-text); border-bottom-right-radius: 6px; }
.msg.picky { align-self: flex-start; background: var(--picky); color: var(--picky-text); border-bottom-left-radius: 6px; }
.msg.failed { opacity: .6; }
.msg p { margin: 0 0 .5em; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: .2em 0 .5em; padding-left: 1.2em; }
.msg a { color: inherit; text-decoration: underline; }
.msg.picky a { color: var(--accent); }
.msg code { font: 14px ui-monospace, Menlo, monospace; background: rgba(127,127,127,.15); padding: 1px 4px; border-radius: 5px; }
.msg .meta { display: block; margin-top: 4px; font-size: 11px; opacity: .6; text-align: right; }
.retry { align-self: flex-end; font-size: 13px; color: var(--error); background: none; border: 0; cursor: pointer; padding: 0 4px; }

.typing { align-self: flex-start; display: flex; gap: 5px; padding: 14px 16px; background: var(--picky); border-radius: 18px; box-shadow: var(--shadow); }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; opacity: .6; } }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; min-height: 42px; max-height: 140px; resize: none; padding: 10px 14px; border-radius: 21px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 16px; line-height: 1.35;
}
.composer textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; }
.send:not(:disabled) { background: linear-gradient(135deg, #6d28d9, #c026d3); fill: #fff; }

/* Voice: recording state, voice bubbles, replay button */
.mic.recording { background: #e53935; fill: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(229, 57, 53, .5); } 50% { box-shadow: 0 0 0 8px rgba(229, 57, 53, 0); } }
@media (prefers-reduced-motion: reduce) { .mic.recording { animation: none; } }
.rec { flex: 1; display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 12px; color: var(--muted); font-size: 15px; }
.rec .dot { width: 10px; height: 10px; border-radius: 50%; background: #e53935; }
.link { margin-left: auto; border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; }
.msg .voice-tag { opacity: .7; margin-right: 4px; }
.play { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; padding: 4px 10px; border: 1px solid var(--line);
  border-radius: 14px; background: none; font-size: 13px; cursor: pointer; }
