:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #66736c;
  --line: #dfe5dd;
  --accent: #1e6f5c;
  --accent-strong: #164f42;
  --notice: #ecf7f2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 700;
}

.panel,
.grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 20px;
}

form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.call-state {
  margin-top: 16px;
  color: var(--muted);
}

.notice {
  border: 1px solid #b9dfd0;
  border-radius: 8px;
  background: var(--notice);
  color: var(--accent-strong);
  padding: 12px;
}

.notice.error {
  border-color: #e0b8b1;
  background: #fff2ef;
  color: #7a2e22;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.history {
  margin-top: 16px;
}

.readiness {
  margin-top: 16px;
}

.readiness-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.readiness-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
}

.readiness-item strong {
  color: var(--ink);
}

.readiness-item .ready {
  color: var(--accent-strong);
}

.readiness-item .missing {
  color: #8b3528;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.grid p {
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 720px) {
  .topbar,
  form,
  .grid,
  .readiness-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }
}

/* Auth */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-panel {
  width: min(400px, 100%);
}

.auth-panel h1 {
  margin-bottom: 16px;
  font-size: 24px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logout-form {
  margin: 0;
  display: block;
}

.link-button {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.link-button:hover {
  color: var(--accent);
}

.notice.error {
  background: #fdecec;
  color: #8a1f1f;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 14px;
}

/* ---- P2 console: layout ---- */
.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

.user-name {
  font-weight: 600;
}

/* ---- Dialer ---- */
.dialer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}

.dial-display {
  width: 100%;
  font-size: 24px;
  letter-spacing: 1px;
  text-align: center;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdfb;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.key {
  padding: 16px 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.key:hover { background: #f0f5f1; border-color: var(--accent); }
.key:active { background: #e4efe9; }

.agent-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.agent-field input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
}

.call-button {
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.call-button:hover { background: var(--accent-strong); }

.call-state {
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  background: var(--notice);
  color: var(--muted);
  font-size: 14px;
}

/* ---- History ---- */
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 { margin: 0; }

.search {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  min-width: 200px;
}

table.history {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  font-size: 14px;
}
.history-panel { min-width: 0; }
#history { overflow-x: auto; }
table.history th {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
table.history td { padding: 10px; border-bottom: 1px solid #eef2ee; }
table.history .num { font-variant-numeric: tabular-nums; }
table.history .when, table.history .dur {
  color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.empty { padding: 16px 4px; }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.ok { background: #e4f4ec; color: #1e6f5c; }
.badge.neutral { background: #eef1ee; color: #66736c; }
.badge.pending { background: #fdf3e0; color: #9a6b13; }
.badge.fail { background: #fdecec; color: #8a1f1f; }
.badge.dir-out { background: #e9eefb; color: #2a4b9b; }
.badge.dir-in { background: #f0e9fb; color: #5a2a9b; }

/* ---- Availability toggle ---- */
.availability {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
}
.availability .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #c2ccc5;
}
.availability.on .dot { background: #2fae6f; box-shadow: 0 0 0 3px #d8f0e3; }
.availability.off .dot { background: #c2ccc5; }
.availability .link-button { text-decoration: none; font-weight: 600; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .search { min-width: 0; }
  .topbar { flex-direction: column; }
  .topbar-user { width: 100%; flex-wrap: wrap; }
}

/* ---- Live call state (WebSocket-pushed) ---- */
.call-state .call-id {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.call-state.ok { background: #e4f4ec; color: #1e6f5c; }
.call-state.fail { background: #fdecec; color: #8a1f1f; }
.call-state.pending { background: #fdf3e0; color: #9a6b13; }
.call-state.neutral { background: #eef1ee; color: #66736c; }
