:root {
  --ink: #1c1b1a;
  --paper: #f6f4ef;
  --card: #ffffff;
  --muted: #6b6862;
  --line: #e3ded4;
  --accent: #0f766e;
  --accent-soft: #dbeee9;
  --danger: #b4432e;
  --good: #0f766e;
  --warn: #b8860b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13.5px; margin: 4px 0 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; font-size: 20px; margin: 0 0 2px; letter-spacing: -.2px; }
h3 { font-family: Georgia, serif; margin: 0 0 12px; }

/* Brand */
.brand { font-size: 18px; letter-spacing: -.3px; display: flex; align-items: center; gap: 8px; font-weight: 500; }
.brand b { font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(15,118,110,.15); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--card); padding: 34px 30px; border-radius: var(--radius);
  box-shadow: var(--shadow); width: 340px; display: flex; flex-direction: column; gap: 12px;
  border: 1px solid var(--line);
}
.login-card .brand { font-size: 22px; margin-bottom: 4px; }
.login-card input {
  padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; background: #fbfaf7;
}
.login-card button {
  margin-top: 4px; padding: 11px; border: none; border-radius: 10px; background: var(--ink); color: #fff;
  font-size: 15px; cursor: pointer;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 14px 26px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.tabs { display: flex; gap: 4px; margin-left: 10px; }
.tab {
  border: none; background: none; padding: 8px 16px; border-radius: 999px; cursor: pointer;
  font-size: 14.5px; color: var(--muted); font-weight: 500;
}
.tab.active { background: var(--ink); color: #fff; }
.topright { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #f0ede5; color: var(--muted); }
.pill.warn { background: #fbf0d8; color: #8a6d10; }
.pill.ok { background: #dbeee9; color: var(--accent); }
.ghost { border: 1px solid var(--line); background: none; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--ink); }

main { padding: 26px; max-width: 1200px; margin: 0 auto; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.panel.wide { max-width: 900px; margin: 0 auto; }

textarea, input[type=text], input:not([type]) {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14.5px; font-family: inherit; background: #fbfaf7; resize: vertical;
}
textarea:focus, input:focus { outline: none; border-color: var(--accent); background: #fff; }

button.primary, button.ghost, .btn-file, button:not(.tab):not(.ghost) { font-family: inherit; }
button.primary {
  margin-top: 12px; padding: 11px 20px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer; font-weight: 500;
}
button.primary:disabled { opacity: .55; cursor: default; }

.dropzone {
  display: block; margin-top: 12px; border: 1.5px dashed var(--line); border-radius: 12px;
  padding: 16px; text-align: center; color: var(--muted); cursor: pointer; background: #fbfaf7; font-size: 13.5px;
}
.dropzone.drag { border-color: var(--accent); background: #f2f9f7; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: #eef4f2; color: var(--accent); font-size: 12px; padding: 3px 9px; border-radius: 999px; }

.field { margin: 16px 0; }
.field > label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.btn-file {
  display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 9px;
  cursor: pointer; font-size: 13.5px; background: #fbfaf7; margin-top: 6px;
}
.btn-file.small { font-size: 12.5px; padding: 6px 12px; }
.filebox { font-size: 13px; color: var(--muted); padding: 8px 0; }
.filebox b { color: var(--ink); }
.saved { margin-left: 12px; color: var(--good); font-size: 13px; }

.empty { color: var(--muted); text-align: center; padding: 60px 20px; font-size: 14px; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 16px; }

/* Review */
.score-row { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.score { font-family: Georgia, serif; font-size: 34px; font-weight: 700; }
.verdict { text-transform: capitalize; font-weight: 600; padding: 4px 12px; border-radius: 999px; font-size: 13px; }
.v-strong, .v-good { background: #dbeee9; color: var(--accent); }
.v-moderate, .v-unclear { background: #fbf0d8; color: #8a6d10; }
.v-weak { background: #f6ddd6; color: var(--danger); }
.bar { height: 8px; background: #eee7db; border-radius: 999px; overflow: hidden; margin: 10px 0 16px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.kv { font-size: 13px; margin: 3px 0; }
.kv b { color: var(--muted); font-weight: 600; }
.lists { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.lists h4 { margin: 0 0 6px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.lists ul { margin: 0; padding-left: 18px; font-size: 13px; }
.flags { background: #fbf0d8; border-radius: 10px; padding: 10px 14px; margin: 12px 0; font-size: 13px; }
.flags b { color: #8a6d10; }
.draft-box { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-top: 10px; background: #fbfaf7; }
.draft-box label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin: 8px 0 3px; }
.sendrow { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* Chat */
.chat { border: 1px solid var(--line); border-radius: 12px; padding: 12px; height: 340px; overflow-y: auto; background: #fbfaf7; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 13.5px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fff; }
.msg.agent { align-self: flex-start; background: #eef4f2; color: var(--ink); }
.chat-input { display: flex; gap: 8px; margin-top: 10px; }
.chat-input input { flex: 1; }
.chat-input button { padding: 10px 16px; border: none; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer; }

/* History */
.history { display: flex; flex-direction: column; gap: 12px; }
.hcard { border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.hcard .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.hcard h3 { margin: 0; font-size: 16px; }
.hcard .co { color: var(--muted); font-size: 13px; }
.badge { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.badge.sent { background: #dbeee9; color: var(--accent); }
.badge.draft { background: #f0ede5; color: var(--muted); }
.hmeta { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.hactions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.hactions button { font-size: 13px; padding: 7px 13px; border-radius: 9px; border: 1px solid var(--line); background: #fbfaf7; cursor: pointer; }
.hactions button.go { background: var(--accent); color: #fff; border: none; }
.followups { margin-top: 10px; font-size: 12.5px; color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(20,18,16,.5); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--card); border-radius: var(--radius); padding: 24px; width: 560px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-card textarea { margin: 6px 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Phones ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  body { font-size: 15px; }

  /* Top bar wraps: brand + sign-out on row 1, full-width tabs on row 2 */
  .topbar { flex-wrap: wrap; gap: 10px 12px; padding: 11px 14px; }
  .brand { order: 1; font-size: 16px; }
  .topright { order: 2; margin-left: auto; gap: 8px; }
  .tabs { order: 3; width: 100%; margin-left: 0; gap: 6px; }
  .tab { flex: 1; text-align: center; padding: 9px 4px; font-size: 13.5px; }
  .pill { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ghost { padding: 7px 11px; }

  main { padding: 14px; }
  .grid { gap: 14px; }
  .panel { padding: 16px; }
  .panel.wide { max-width: 100%; }

  /* Prevent iOS auto-zoom on focus (needs >=16px) */
  textarea, input[type=text], input:not([type]), .login-card input,
  .chat-input input, .modal-card input, .modal-card textarea { font-size: 16px; }

  /* Review: stack strengths/gaps, roomier score */
  .lists { grid-template-columns: 1fr; }
  .score { font-size: 28px; }
  .score-row { gap: 10px; }
  .draft-box { padding: 12px; }
  .sendrow { gap: 8px; }
  .sendrow button { flex: 1 1 auto; }

  /* Chats a touch shorter so the input stays reachable */
  .chat { height: 46vh; max-height: 340px; }

  .modal { padding: 12px; }
  .modal-card { padding: 18px; }

  .login-card { width: 100%; max-width: 360px; padding: 28px 22px; }
}

/* Small tweak for very narrow devices */
@media (max-width: 380px) {
  .tab { font-size: 12.5px; padding: 8px 2px; }
  .brand { font-size: 15px; }
}
