/* Look: "Calm & clear". Colours live here: change these to restyle the whole app. */
:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --accent: #0f766e;      /* buttons, links, names */
  --on-accent: #ffffff;
  --head: #0f766e;        /* top bar */
  --bg: #f4f6f6;          /* chat background */
  --panel: #ffffff;       /* message box, menus */
  --field: #f1f4f4;       /* text boxes */
  --theirs: #ffffff;      /* other people's bubbles */
  --mine: #d5f2ea;        /* your bubbles */
  --mine-text: #10302b;
  --ai: #ece9fb;          /* Holly's bubbles */
  --ai-name: #6d4fd8;
  --text: #17201f;
  --muted: #5e6b69;
  --border: #e3e8e7;
  --day: #e3e8e7;
  --wave: #9cc2bc;        /* voice-note bars */
  --danger: #dc2626;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #2fa597; --on-accent: #06201d; --head: #0d4f49; --bg: #0e1413; --panel: #161d1c; --field: #1c2524;
    --theirs: #1b2423; --mine: #17463f; --mine-text: #e3f4f0; --ai: #262243; --ai-name: #ad98ff;
    --text: #e6eceb; --muted: #93a19f; --border: #26302f; --day: #1f2928; --wave: #4d7d76;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 var(--font);
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.link { background: none; border: 0; color: var(--accent); padding: 4px; font-weight: 500; }
svg { width: 20px; height: 20px; display: block; }

.screen { height: 100dvh; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; background: var(--bg); }

/* Login */
#login { justify-content: center; padding: 24px; }
.login-box { background: var(--panel); border-radius: 20px; padding: 28px; border: 1px solid var(--border); display: flex; flex-direction: column; gap: 16px; }
.login-box h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
.login-box form { display: flex; flex-direction: column; gap: 10px; }
.login-box input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--field); }
.login-box button[type=submit] { padding: 12px; border: 0; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* Top bar */
header {
  display: flex; align-items: center; gap: 10px; position: relative;
  padding: calc(env(safe-area-inset-top) + 12px) 12px 12px 16px;
  background: var(--head); color: #fff;
}
.team-badge { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.18); display: grid; place-items: center; font-weight: 700; }
header h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; }
.icon { background: none; border: 0; padding: 6px 8px; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
header .icon { color: #fff; font-size: 22px; line-height: 1; }
.menu {
  position: absolute; right: 12px; top: 100%; z-index: 5;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 14px;
  display: flex; flex-direction: column; min-width: 230px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.menu button { background: none; border: 0; text-align: left; padding: 14px 16px; }
.menu button + button { border-top: 1px solid var(--border); }

/* Messages */
#messages { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.row { display: flex; align-items: flex-end; gap: 8px; max-width: 92%; align-self: flex-start; }
.row.first { margin-top: 8px; }
.row.mine { align-self: flex-end; }
.day { align-self: center; font-size: 12px; font-weight: 500; color: var(--muted); background: var(--day); padding: 3px 12px; border-radius: 99px; margin: 12px 0 4px; }

.avatar {
  flex: none; width: 64px; height: 64px; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; font-size: 24px; font-weight: 700; color: #fff; background: var(--accent);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.holly { background: var(--ai-name); }
.row:not(.first) .avatar { visibility: hidden; height: 0; }
.row.mine .avatar { display: none; }

.msg {
  min-width: 0; padding: 8px 12px 6px; border-radius: 18px; background: var(--theirs);
  border: 1px solid var(--border); overflow-wrap: anywhere; box-shadow: 0 1px 1px rgba(0,0,0,.03);
}
.row.first:not(.mine) .msg { border-bottom-left-radius: 6px; }
.row.mine .msg { background: var(--mine); color: var(--mine-text); border-color: transparent; }
.row.mine.first .msg { border-bottom-right-radius: 6px; }
.row.ai .msg { background: var(--ai); border-color: transparent; }
.msg .who { font-size: 13px; font-weight: 600; color: var(--accent); margin-bottom: 1px; }
.row.ai .who { color: var(--ai-name); }
.row:not(.first) .who { display: none; }
.msg .time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.row.mine .time { color: inherit; opacity: .6; }
.msg .text { white-space: pre-wrap; }
.msg .text a { color: var(--accent); }
.msg img.photo { display: block; max-width: 100%; max-height: 360px; border-radius: 12px; margin: 4px 0; cursor: zoom-in; }
.msg .chart { position: relative; height: 260px; width: min(560px, 70vw); max-width: 100%; margin: 8px 0 4px; background: var(--panel); border-radius: 12px; padding: 8px; }
.msg.pending .text, .row.pending .text { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* Voice notes */
.voice { display: flex; align-items: center; gap: 10px; min-width: min(250px, 60vw); padding: 2px 0; }
.voice .play {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
}
.voice .play svg { width: 16px; height: 16px; }
.wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; cursor: pointer; }
.wave i { flex: 1; max-width: 4px; border-radius: 2px; background: var(--wave); transition: background .1s; }
.wave i.on { background: var(--accent); }
.voice .dur { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 32px; text-align: right; }
.row.mine .voice .dur { color: inherit; opacity: .7; }
.msg .transcript { font-size: 14px; color: var(--muted); font-style: italic; margin-top: 4px; }
.row.mine .transcript { color: inherit; opacity: .75; }

/* Message box */
#composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 10px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--panel); border-top: 1px solid var(--border);
}
#composer label.icon { height: 46px; }
#text {
  flex: 1; resize: none; max-height: 140px; padding: 11px 16px; min-height: 46px;
  border-radius: 23px; border: 1px solid var(--border); background: var(--field); outline: none;
}
.round {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
  touch-action: none; user-select: none; -webkit-user-select: none; transition: transform .15s, background .15s;
}
.round svg { width: 21px; height: 21px; }
#mic-btn.active { background: var(--danger); color: #fff; transform: scale(1.15); }

#recording { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
#recording .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
#recording .link { margin-left: auto; }

/* Full-screen photo */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: flex; align-items: center; justify-content: center; z-index: 10; }
.viewer img { max-width: 100%; max-height: 100%; }

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

/* Team members screen */
#team { position: absolute; inset: 0; z-index: 8; background: var(--bg); overflow-y: auto; padding: calc(env(safe-area-inset-top) + 16px) 16px 24px; }
#chat { position: relative; }
.team-head { display: flex; align-items: center; justify-content: space-between; }
.team-head h2 { margin: 0; font-size: 20px; }
#add-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 4px; align-items: center; }
#add-form input:not([type=checkbox]) { flex: 1 1 160px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); }
#add-form button { padding: 10px 18px; border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.check { display: flex; align-items: center; gap: 6px; font-size: 15px; }
#team-msg { overflow-wrap: anywhere; }
#team-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 8px; }
#team-list li { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#team-list .person { flex: 1; min-width: 0; }
#team-list li.removed { opacity: .6; }
.tag { font-size: 11px; font-weight: 600; background: var(--accent); color: var(--on-accent); border-radius: 6px; padding: 1px 6px; vertical-align: 2px; }
.tag.off { background: var(--muted); }
.actions { display: flex; gap: 4px; }
.link.danger { color: var(--danger); }

/* Photo cropper */
.cropper { position: fixed; inset: 0; z-index: 20; background: #111; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 20px; }
.cropper[hidden] { display: none; }
.crop-title { margin: 0; font-weight: 500; text-align: center; }
.crop-box { position: relative; width: min(300px, 80vw); aspect-ratio: 1; overflow: hidden; border-radius: 12px; touch-action: none; cursor: grab; background: #222; }
.crop-box::after { content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 999px rgba(0,0,0,.55); border: 2px solid rgba(255,255,255,.9); pointer-events: none; }
.crop-box img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; max-width: none; }
.crop-zoom-row { display: flex; align-items: center; gap: 10px; width: min(340px, 90vw); }
#crop-zoom { flex: 1; accent-color: var(--accent); }
.crop-zoom-row button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(255,255,255,.4); background: none; color: #fff; font-size: 22px; line-height: 1; }
.crop-hint { margin: -8px 0 0; font-size: 13px; opacity: .7; }
.crop-box { background: #fff; }
.crop-actions { display: flex; gap: 12px; }
.crop-actions button { padding: 10px 22px; border-radius: 10px; border: 1px solid rgba(255,255,255,.4); background: none; color: #fff; font-weight: 600; }
.crop-actions .primary { background: var(--accent); border-color: var(--accent); }
