.admin-app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.admin-app .topbar {
  margin: 0 -20px 8px;
}

@media (max-width: 480px) {
  .admin-app {
    padding: 0 14px 32px;
  }
  .admin-app .topbar {
    margin: 0 -14px 8px;
    padding: 10px 14px;
  }
  .admin-app .topbar h1 {
    font-size: 0.95rem;
  }
  .search-box-wrap {
    max-width: none;
  }
}

.table-toolbar {
  margin: 20px 0 14px;
}

.search-box-wrap {
  position: relative;
  max-width: 320px;
}

.search-box-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--fg-muted);
  pointer-events: none;
}

.search-box {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  font-size: 0.88rem;
  transition: border-color var(--transition-fast);
}
.search-box:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.search-box:focus {
  border-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.citizen-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.citizen-table th,
.citizen-table td {
  padding: 11px 10px;
  text-align: left;
  white-space: nowrap;
}
.citizen-table th:first-child,
.citizen-table td:first-child {
  padding-left: 14px;
}
.citizen-table th:last-child,
.citizen-table td:last-child {
  padding-right: 14px;
}

.citizen-table thead th {
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-muted);
  position: sticky;
  top: 0;
}

.citizen-table tbody tr {
  transition: background var(--transition-fast);
}
.citizen-table tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--assistant-bubble) 55%, transparent);
}
.citizen-table tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.citizen-table tbody tr:not(:last-child) td {
  border-bottom: 1px solid var(--border);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px 3px 7px;
  border-radius: var(--radius-full);
  background: var(--assistant-bubble);
  color: var(--fg);
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.status-resolved { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge.status-pending { background: color-mix(in srgb, var(--warning) 16%, transparent); color: var(--warning); }

.call-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}
.call-btn svg { width: 12px; height: 12px; flex-shrink: 0; }
.call-btn:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}
.call-btn:active { transform: scale(0.96); }

.empty-state {
  padding: 24px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 0.9rem;
}

/* Below this width, the table's columns (name/phone/ward/language/query
   type/status/date/action) can't fit without either tiny type or
   horizontal scrolling that hides fields off-screen with no visible hint
   they're there (in practice: Language, Query Type, Status, Last Contact
   and the Demo Call button all scrolled out of view on a phone). Each row
   becomes a labeled card instead -- every field stays visible, no scroll
   needed. admin.js sets a data-label attribute per <td> that ::before
   reads to print the field name. */
@media (max-width: 720px) {
  .table-wrap {
    overflow-x: visible;
    border: none;
    box-shadow: none;
    border-radius: 0;
  }

  .citizen-table,
  .citizen-table tbody {
    display: block;
    width: 100%;
  }

  .citizen-table thead {
    display: none;
  }

  .citizen-table tbody tr {
    display: block;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 6px 14px;
    margin-bottom: 12px;
  }
  .citizen-table tbody tr:nth-child(even) {
    background: var(--panel);
  }
  .citizen-table tbody tr:not(:last-child) td {
    border-bottom: 1px solid var(--border);
  }

  .citizen-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 9px 0 !important;
    white-space: normal;
    text-align: right;
  }
  .citizen-table td::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--fg-muted);
    text-align: left;
  }
  .citizen-table td:first-child {
    font-weight: 600;
  }
  .citizen-table td:last-child {
    justify-content: center;
  }
  .citizen-table td:last-child::before {
    content: none;
  }
  .citizen-table .call-btn {
    width: 100%;
    justify-content: center;
    padding: 10px;
  }
}

/* Call modal */

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.call-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-in var(--transition) both;
}
.call-modal-overlay.hidden { display: none; }

.call-modal {
  width: 400px;
  max-width: 92vw;
  max-height: 88vh;
  background: var(--panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  /* Safety net, not the primary fix: header + transcript + keypad are sized
     to fit comfortably (see .keypad-btn's capped size below), but if they
     ever don't -- a very short window, a long transcript -- the whole modal
     scrolls instead of silently clipping content with no way to reach it
     (which is what used to happen with overflow:hidden here; the keypad's
     bottom row, including "0", could get cut off with no way to scroll to
     it). overflow-x stays hidden so rounded corners still clip correctly. */
  overflow-y: auto;
  overflow-x: hidden;
  animation: modal-in 240ms var(--ease) both;
}

.call-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.call-header-info { min-width: 0; }

.call-citizen-name {
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.call-citizen-meta {
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--fg-muted);
}

.call-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s infinite;
  flex-shrink: 0;
}

.hangup-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.hangup-btn svg { width: 15px; height: 15px; }
.hangup-btn:hover { box-shadow: var(--shadow-sm); }
.hangup-btn:active { transform: scale(0.92); }

.call-transcript {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 140px;
  max-height: 260px;
  background: color-mix(in srgb, var(--bg) 40%, transparent);
}

.call-turn {
  font-size: 0.85rem;
  line-height: 1.45;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  background: var(--assistant-bubble);
  color: var(--assistant-fg);
  box-shadow: var(--shadow-sm);
  animation: bubble-in var(--transition) both;
}
.call-turn.ivr {
  align-self: stretch;
}
.call-turn.citizen {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-fg);
  border-bottom-right-radius: 4px;
  max-width: 85%;
}
.call-turn.assistant {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  max-width: 85%;
}

.call-turn-translation {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(128, 128, 128, 0.25);
  font-size: 0.78rem;
  opacity: 0.85;
}

.call-keypad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  justify-content: center;
  gap: 12px;
  padding: 16px 18px;
}
.call-keypad.hidden { display: none; }

.keypad-btn {
  /* Fixed size rather than 1fr+aspect-ratio: a fluid square that scales
     with modal width made the keypad up to ~520px tall on its own (4 rows
     of ~110px squares) -- comfortably taller than most phone viewports,
     which is what was pushing "0" (and the rest of the bottom row) below
     the visible area. A fixed 64px keeps total keypad height ~320px
     regardless of modal width. */
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--assistant-bubble);
  color: var(--fg);
  font-size: 1.15rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}
.keypad-btn:hover {
  background: var(--accent);
  color: #fff;
}
.keypad-btn:active {
  transform: scale(0.93);
}
.keypad-btn-inert {
  opacity: 0.35;
  cursor: default;
  box-shadow: none;
}
.keypad-btn-inert:hover {
  background: var(--assistant-bubble);
  color: var(--fg);
}
.keypad-btn-inert:active {
  transform: none;
}

.call-assistant-controls {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--border);
}
.call-assistant-controls.hidden { display: none; }

.call-assistant-controls .input-row {
  display: flex;
  gap: 8px;
}

.call-assistant-controls .text-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
}

#call-text-input {
  flex: 1;
  padding: 10px 40px 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 0.88rem;
  transition: border-color var(--transition-fast);
}
#call-text-input:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
#call-text-input:focus {
  border-color: var(--accent);
  background: var(--panel);
}
#call-text-input:disabled {
  opacity: 0.55;
}

#call-text-send {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
#call-text-send:hover { background: var(--accent-hover); }
#call-text-send:active { transform: scale(0.97); }

/* Small viewports: the call modal goes full-screen, like a real phone call
   UI, instead of a centered card with margins it barely fits in. */
@media (max-width: 480px) {
  .call-modal-overlay {
    padding: 0;
  }
  .call-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .call-transcript {
    min-height: 80px;
  }
}
