:root {
  --bg: #0b1120;
  --panel: #111827;
  --panel-2: #1e293b;
  --border: #2b384e;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-2: #0ea5e9;
  --live: #dc2626;
  --green: #10b981;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at top right, #172554 0%, var(--bg) 52%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

.onepage-shell {
  max-width: 1120px;
  height: 100vh;
  margin: 0 auto;
  padding: 12px 16px;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pihu-avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.25;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn, .select-compact {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 0.84rem;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
  transition: transform 0.12s ease, background 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 600; }
.btn-secondary { background: #1e293b; border-color: #3b4b68; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: #475569; }

.btn-live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #1e293b;
  border-color: #3b82f6;
  font-weight: 600;
}

.btn-live .dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #64748b;
}

.btn-live.active {
  background: rgba(220, 38, 38, 0.2);
  border-color: #ef4444;
  color: #fecaca;
}

.btn-live.active .dot {
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.25);
}

.voice-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
}

.intake-strip {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}

.first-look-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: linear-gradient(120deg, rgba(37, 99, 235, 0.22), rgba(16, 185, 129, 0.16));
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 11px;
  padding: 8px 12px;
}

.first-look-copy {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.official-badge {
  background: rgba(16, 185, 129, 0.22);
  border: 1px solid rgba(52, 211, 153, 0.45);
  color: #6ee7b7;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.portal-badge {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  color: #93c5fd;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
}

.first-look-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.btn-call {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.filter-input {
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  color: var(--text);
  font-size: 0.8rem;
  min-width: 130px;
}

.intake-fields {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.intake-fields input {
  flex: 1 1 180px;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 0.84rem;
}

.quick-prompts {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chip {
  white-space: nowrap;
  background: #172554;
  color: #dbeafe;
  border: 1px solid #1d4ed8;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.78rem;
  cursor: pointer;
}

.chip:hover { background: #1e40af; }

.chat-stage {
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.msg {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 13px;
  line-height: 1.5;
  font-size: 0.92rem;
  white-space: pre-wrap;
}

.msg.assistant {
  align-self: flex-start;
  background: #172033;
  border: 1px solid #2b3b57;
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1d4ed8, #0284c7);
  color: #fff;
}

.msg-meta {
  font-size: 0.72rem;
  opacity: 0.78;
  margin-bottom: 4px;
}

.composer-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(17, 24, 39, 0.94);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
}

.mic-pill {
  border: 1px solid #3b82f6;
  background: #172554;
  color: #fff;
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.mic-pill.listening {
  background: #dc2626;
  border-color: #f87171;
}

.composer-bar input {
  flex: 1;
  min-width: 0;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.93rem;
}

.status-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.76rem;
  color: var(--muted);
  padding: 0 4px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal.hidden { display: none; }

.modal-card {
  width: min(960px, 100%);
  max-height: 90vh;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-head small { color: var(--muted); }

.modal-pin-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.first-pin-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.45);
}

.first-pin-box.hidden { display: none; }

.first-pin-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.82rem;
}

.first-pin-copy strong { color: #6ee7b7; }
.first-pin-copy span { color: #cbd5e1; }

.first-pin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.first-pin-actions input {
  background: #1e293b;
  border: 1px solid #34d399;
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 0.84rem;
}

.admin-unlocked {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.admin-unlocked.hidden { display: none; }
.pin-error { font-size: 0.82rem; color: #fca5a5; }
.save-ok { color: #6ee7b7 !important; font-weight: 600; }

.modal-pin-bar input {
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  color: var(--text);
  font-size: 0.82rem;
}

.tab-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.tab-btn {
  border: 1px solid var(--border);
  background: #1e293b;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.tab-btn.active {
  background: #2563eb;
  border-color: #3b82f6;
  color: #fff;
}

.tab-pane {
  display: none;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.tab-pane.active { display: block; }

.pane-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.records-table th, .records-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
}

.records-table th { background: #1e293b; color: #cbd5e1; }

.status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.74rem;
  font-weight: 600;
}

.status-agreed { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.status-follow_up { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.status-not_agreed { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.status-inquiry { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }

.transcript-box {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: #1e293b;
  border: 1px solid var(--border);
  font-size: 0.82rem;
  white-space: pre-wrap;
  max-height: 180px;
  overflow-y: auto;
}

.transcript-box.hidden { display: none; }

.help-text, .muted-note { font-size: 0.82rem; color: var(--muted); }
.code-label { display: block; font-size: 0.82rem; margin: 10px 0 4px; color: #cbd5e1; }
.code-box {
  width: 100%;
  background: #020617;
  color: #34d399;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-family: Consolas, monospace;
  font-size: 0.78rem;
}

.fees-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.fee-item {
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 0.8rem;
}

.fee-item input {
  width: 100%;
  margin-top: 4px;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--text);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 12px;
}

.settings-grid h3 { margin-top: 0; font-size: 0.94rem; color: #93c5fd; }
.settings-grid label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.settings-grid input {
  width: 100%;
  margin-top: 3px;
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  color: var(--text);
}

.wa-test-box {
  display: flex;
  gap: 6px;
  margin: 8px 0;
}

.wa-test-box input { margin-top: 0; flex: 1; }

@media (max-width: 720px) {
  .onepage-shell { padding: 8px; }
  .msg { max-width: 94%; }
  .brand p { display: none; }
}
