/* ==========================================================================
   AayZee Phone — light theme PWA styles
   Light theme only. No dark mode.
   ========================================================================== */

:root {
  --teal: #0d7d6c;
  --teal-dark: #0a6356;
  --teal-soft: #e3f2ee;
  --green: #22b45e;
  --green-dark: #189a4d;
  --red: #e5484d;
  --red-dark: #c93438;
  --amber: #b7791f;
  --amber-soft: #fdf3e0;
  --ink: #1c2422;
  --ink-soft: #5b6663;
  --muted: #8a9491;
  --bg: #f4f6f5;
  --card: #ffffff;
  --line: #e5eae8;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(20, 40, 36, 0.08);
  --shadow-sm: 0 2px 10px rgba(20, 40, 36, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

input { user-select: text; -webkit-user-select: text; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

.hidden { display: none !important; }

/* ---------------- Views ---------------- */
.view { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }

/* ---------------- Login ---------------- */
.view-login {
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--sat)) 24px calc(24px + var(--sab));
  background: linear-gradient(160deg, #eef7f4 0%, var(--bg) 55%, #eef4f1 100%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 36px 28px 28px;
  text-align: center;
  border: 1px solid var(--line);
}

.login-logo {
  width: 88px; height: 88px;
  border-radius: 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}

.login-title { font-size: 26px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.3px; }
.login-sub { font-size: 14px; color: var(--ink-soft); margin: 0 0 24px; }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input {
  width: 100%;
  font-size: 17px;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fbfcfc;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13, 125, 108, 0.15); }

.form-error {
  font-size: 14px; color: var(--red-dark);
  background: #fdeeee; border: 1px solid #f6d3d3;
  border-radius: 10px; padding: 10px 12px; margin-bottom: 14px;
}

.login-hint { font-size: 12.5px; color: var(--muted); margin: 18px 0 0; line-height: 1.5; }

/* ---------------- Buttons ---------------- */
.btn {
  font-family: var(--font);
  font-size: 16px; font-weight: 600;
  border: none; border-radius: 14px;
  padding: 14px 20px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, box-shadow 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-small { font-size: 14px; padding: 9px 16px; border-radius: 10px; }

.btn-primary { background: var(--teal); color: #fff; box-shadow: 0 6px 16px rgba(13, 125, 108, 0.3); }
.btn-primary:active { background: var(--teal-dark); }
.btn-primary:disabled { background: #b9c9c5; box-shadow: none; cursor: default; }

.btn-ghost { background: var(--teal-soft); color: var(--teal-dark); }
.btn-danger { background: #fdeeee; color: var(--red-dark); border: 1px solid #f3c9c9; margin-top: 8px; }

.icon-btn {
  background: transparent; border: none; color: var(--ink-soft);
  width: 48px; height: 48px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:active { background: var(--line); }

/* ---------------- App bar ---------------- */
#view-main { padding-bottom: 0; }

.appbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--sat)) calc(16px + var(--sar)) 10px calc(16px + var(--sal));
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.appbar-brand { display: flex; align-items: center; gap: 9px; }
.appbar-logo { border-radius: 7px; }
.appbar-name { font-size: 17px; font-weight: 700; letter-spacing: -0.2px; }

/* Status pill */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.pill-ok       { background: #e5f6ec; color: #157a3e; border-color: #c8ecd6; }
.pill-warn     { background: var(--amber-soft); color: var(--amber); border-color: #f3e2b8; }
.pill-warn .pill-dot { animation: pulse 1.2s infinite; }
.pill-bad      { background: #fdeeee; color: var(--red-dark); border-color: #f3c9c9; }
.pill-busy     { background: var(--teal-soft); color: var(--teal-dark); border-color: #cbe7df; }
.pill-busy .pill-dot { animation: pulse 1.2s infinite; }
.pill-unknown  { background: #eef1f0; color: var(--muted); border-color: var(--line); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------------- Tab views ---------------- */
.tabview {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 18px 20px calc(18px + var(--sab));
  max-width: 480px; width: 100%; margin: 0 auto;
  overflow-y: auto;
}

/* ---------------- Dialer ---------------- */
.number-row { display: flex; align-items: center; gap: 4px; margin: 6px 0 2px; }
.number-display {
  flex: 1;
  font-size: 30px; font-weight: 600; letter-spacing: 1px;
  text-align: center;
  border: none; background: transparent; color: var(--ink);
  padding: 10px 4px; outline: none; min-width: 0;
}
.number-display::placeholder { color: #c3ccc9; font-weight: 400; letter-spacing: 0; font-size: 22px; }

.dial-callstate {
  min-height: 22px;
  text-align: center; font-size: 14px; font-weight: 600; color: var(--teal-dark);
  margin-bottom: 6px;
}

.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin: 4px 0 14px;
}
.key {
  font-family: var(--font);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 68px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.07s, background 0.12s;
}
.key:active { transform: scale(0.94); background: var(--teal-soft); border-color: #cbe7df; }
.key-digit { font-size: 26px; font-weight: 600; color: var(--ink); line-height: 1.1; }
.key-sub { font-size: 10px; font-weight: 600; letter-spacing: 1.5px; color: var(--muted); margin-top: 1px; }

.call-row { display: flex; justify-content: center; margin: 2px 0 8px; }
.btn-call {
  width: 74px; height: 74px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px rgba(34, 180, 94, 0.4);
  transition: transform 0.08s, background 0.15s;
}
.btn-call:active { transform: scale(0.93); background: var(--green-dark); }
.btn-call:disabled { background: #c6d2ce; box-shadow: none; cursor: default; }

.reg-note { text-align: center; font-size: 13px; color: var(--amber); margin: 0; }

/* ---------------- Tab bar ---------------- */
.tabbar {
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 8px calc(12px + var(--sar)) calc(10px + var(--sab)) calc(12px + var(--sal));
  position: sticky; bottom: 0; z-index: 20;
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-family: var(--font); font-size: 11px; font-weight: 600;
  padding: 6px 0 2px;
}
.tab.active { color: var(--teal); }

/* ---------------- History ---------------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.section-head h2, .section-title { font-size: 22px; font-weight: 700; margin: 4px 0 14px; letter-spacing: -0.3px; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-sm);
}
.hist-icon {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
}
.hist-icon.in { background: var(--teal-soft); color: var(--teal-dark); }
.hist-icon.out { background: #e8f3ff; color: #1f6fd6; }
.hist-icon.missed { background: #fdeeee; color: var(--red-dark); }
.hist-main { flex: 1; min-width: 0; }
.hist-number { font-size: 16px; font-weight: 600; }
.hist-meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.hist-result { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; }
.hist-result.completed { color: #157a3e; }
.hist-result.missed, .hist-result.declined, .hist-result.failed, .hist-result.busy, .hist-result.cancelled { color: var(--red-dark); }
.empty-note { text-align: center; color: var(--muted); font-size: 14px; margin-top: 30px; }

/* ---------------- Settings cards ---------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 10px; }
.card-text { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 12px; line-height: 1.5; }
.card-text.small { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); font-size: 14px; }
.kv { margin: 0; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid #f0f4f3; font-size: 14px; }
.kv-row:last-child { border-bottom: none; }
.kv-row dt { color: var(--ink-soft); font-weight: 500; }
.kv-row dd { margin: 0; font-weight: 600; text-align: right; word-break: break-all; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.check-row { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; cursor: pointer; }
.check-row input { width: 20px; height: 20px; accent-color: var(--teal); }
.version-note { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0 0; }

/* ---------------- Overlays (incoming / active call) ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(165deg, #e9f5f1 0%, #f4f6f5 45%, #e6f0ec 100%);
  padding: calc(20px + var(--sat)) 24px calc(28px + var(--sab));
}
.overlay::before {
  content: ""; position: absolute; inset: 0;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}
.overlay-inner { position: relative; text-align: center; width: 100%; max-width: 360px; }

.caller-avatar {
  width: 104px; height: 104px; border-radius: 50%;
  background: var(--teal-soft); color: var(--teal-dark);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  border: 3px solid #fff;
  box-shadow: var(--shadow);
}
#incoming-call:not(.hidden) .caller-avatar { animation: ringpulse 1.6s infinite; }
@keyframes ringpulse {
  0% { box-shadow: 0 0 0 0 rgba(13, 125, 108, 0.35); }
  70% { box-shadow: 0 0 0 22px rgba(13, 125, 108, 0); }
  100% { box-shadow: 0 0 0 0 rgba(13, 125, 108, 0); }
}

.overlay-label { font-size: 15px; font-weight: 600; color: var(--ink-soft); margin: 0 0 6px; }
.overlay-number { font-size: 32px; font-weight: 700; letter-spacing: 0.5px; margin: 0 0 26px; word-break: break-all; }
.overlay-duration { font-size: 20px; font-weight: 600; color: var(--ink-soft); margin: 8px 0 26px; font-variant-numeric: tabular-nums; }
.overlay-hint { font-size: 12.5px; color: var(--muted); margin: 22px 0 0; line-height: 1.5; }

.overlay-actions { display: flex; justify-content: center; gap: 34px; }
.btn-circle {
  width: 74px; height: 74px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.08s, background 0.15s, opacity 0.15s;
}
.btn-circle:active { transform: scale(0.92); }
.btn-answer { background: var(--green); color: #fff; box-shadow: 0 10px 24px rgba(34, 180, 94, 0.45); }
.btn-answer:active { background: var(--green-dark); }
.btn-decline { background: var(--red); color: #fff; box-shadow: 0 10px 24px rgba(229, 72, 77, 0.4); }
.btn-decline:active { background: var(--red-dark); }
.btn-neutral { background: #fff; color: var(--ink-soft); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.btn-neutral[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-neutral:disabled { opacity: 0.45; cursor: default; }

/* ---------------- Toasts ---------------- */
.toasts {
  position: fixed; left: 16px; right: 16px;
  bottom: calc(90px + var(--sab)); z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: #2b3331; color: #fff;
  font-size: 14px; font-weight: 500;
  padding: 12px 18px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  max-width: 420px; text-align: center;
  animation: toastin 0.22s ease-out;
}
.toast-error { background: #7c2326; }
.toast-ok { background: var(--teal-dark); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Small landscape / desktop guardrails */
@media (min-width: 520px) {
  .key { min-height: 76px; }
}
