/* AI Caller — "operator's call slip"
   Warm paper ground, deep ink, one call-green action. Numbers, statuses and
   eyebrows are set in mono, like a switchboard ticket. */

:root {
  --paper: #F5F3EC;
  --card: #FDFCF8;
  --ink: #20262E;
  --ink-soft: #6B6F66;
  --line: #DCD8CB;
  --green: #17754B;
  --green-deep: #0F5C3A;
  --amber: #9A6A00;
  --amber-bg: #F4E8CC;
  --red: #A83A31;
  --red-bg: #F3DEDA;
  --chipbg: #ECE9DF;
  --shadow: 0 1px 2px rgba(32, 38, 46, .07), 0 6px 24px rgba(32, 38, 46, .06);
  --radius: 14px;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14181D;
    --card: #1C2229;
    --ink: #E9E7DE;
    --ink-soft: #98A0A8;
    --line: #313A44;
    --green: #3AA476;
    --green-deep: #2C8A61;
    --amber: #D6A94E;
    --amber-bg: #33290F;
    --red: #E07A6E;
    --red-bg: #3A1F1B;
    --chipbg: #262E37;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

/* view switching */
body[data-view="loading"] #appView,
body[data-view="loading"] #loginView { display: none; }
body[data-view="login"] #appView { display: none; }
body[data-view="app"] #loginView { display: none; }

.container { max-width: 620px; margin: 0 auto; padding: 0 16px 32px; }

/* type */
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 6px;
}
.brand { font-size: 30px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 4px; }
.brand.small { font-size: 18px; margin: 0; }
.muted { color: var(--ink-soft); }
.micro { font-size: 12.5px; }
.mono { font-family: var(--mono); }

/* header */
.topbar {
  max-width: 620px;
  margin: 0 auto;
  padding: 18px 16px 10px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}
.topbar .eyebrow { margin-bottom: 2px; }

/* cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.slip { margin-top: 8px; border-top: 2px dashed var(--line); }
.slip-eyebrow { margin-bottom: 14px; }

/* fields */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
}
.field input[type="tel"], .field input[type="number"], .field input[type="datetime-local"],
#totp { font-family: var(--mono); }
.field textarea { resize: vertical; }
.field input:focus-visible, .field textarea:focus-visible,
.btn:focus-visible, .linklike:focus-visible, .toggle input:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
.field .micro { margin: 5px 0 0; }
.row.two { display: grid; grid-template-columns: 1fr 130px; gap: 12px; }
.indent { margin-left: 30px; margin-top: 6px; }

/* toggles */
.toggles { margin: 4px 0 14px; display: grid; gap: 9px; }
.toggle { display: flex; gap: 10px; align-items: flex-start; font-size: 14.5px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--green); flex: none; }

/* buttons */
.btn {
  font: inherit;
  font-weight: 650;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 12px 16px;
  cursor: pointer;
}
.btn-primary {
  width: 100%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn-primary:hover { background: var(--green-deep); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-place .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #fff; opacity: .9;
}
.btn-place[data-busy="1"] .dot { animation: pulse 1.1s ease-in-out infinite; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--chipbg); }
.linklike {
  background: none; border: 0; padding: 4px 2px;
  color: var(--green); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.linklike:hover { text-decoration: underline; }

/* lists */
.listblock { margin-top: 26px; }
.listhead { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.calls { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.call-item {
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.call-item:hover { border-color: var(--ink-soft); }
.call-main { flex: 1; min-width: 0; }
.call-to { font-family: var(--mono); font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.empty { font-size: 14px; padding: 4px 2px; }

/* status chips */
.chip {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--chipbg);
  color: var(--ink-soft);
  flex: none;
}
.chip[data-s="completed"] { background: color-mix(in srgb, var(--green) 16%, var(--card)); color: var(--green); }
.chip[data-s="queued"], .chip[data-s="in-progress"], .chip[data-s="started"] { background: var(--amber-bg); color: var(--amber); }
.chip[data-s="failed"], .chip[data-s="error"], .chip[data-s="busy"], .chip[data-s="no-answer"] { background: var(--red-bg); color: var(--red); }
.cancel-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--red); background: none; border: 1px solid var(--line);
  border-radius: 9px; padding: 6px 10px; cursor: pointer; flex: none;
}
.cancel-btn:hover { background: var(--red-bg); }

/* login */
.login-wrap { min-height: 92vh; display: grid; place-items: center; padding: 20px 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .muted { margin: 0 0 16px; font-size: 14px; }
.login-card .btn { margin-top: 4px; }
.error { color: var(--red); font-size: 14px; margin: 2px 0 10px; }

/* details sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(15, 18, 22, .45); z-index: 30;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 620px; margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .18);
  max-height: 82vh;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 10px auto 4px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 18px 12px; border-bottom: 1px solid var(--line); }
.sheet-num { margin: 0; font-size: 16px; }
.sheet-head .micro { margin: 2px 0 0; }
.sheet-body { overflow-y: auto; padding: 14px 18px; }
.sheet-body .eyebrow { margin-top: 10px; }
.summary { margin: 4px 0 10px; }
.live-line { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 2px 0 12px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
.transcript { display: grid; gap: 8px; margin: 6px 0 12px; }
.bubble { border-radius: 12px; padding: 9px 12px; font-size: 14.5px; max-width: 92%; }
.bubble .who {
  display: block; font-family: var(--mono); font-size: 10px;
  letter-spacing: .12em; text-transform: uppercase; margin-bottom: 3px; opacity: .7;
}
.bubble.agent { background: color-mix(in srgb, var(--green) 12%, var(--card)); justify-self: end; }
.bubble.caller { background: var(--chipbg); justify-self: start; }
.bubble.transcript-raw { background: var(--chipbg); white-space: pre-wrap; max-width: 100%; }
.sheet-actions { display: flex; gap: 10px; padding: 10px 18px 16px; border-top: 1px solid var(--line); }
.sheet-actions .btn { flex: 1; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  z-index: 40; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}

.foot { text-align: center; margin-top: 34px; }

@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
[hidden] { display: none !important; }
