:root {
  --bg:             #0D1B2A;
  --surface:        #1A2B3C;
  --surface-hover:  #243447;
  --accent:         #00B4D8;
  --accent-dark:    #0077A8;
  --text-primary:   #F0F4F8;
  --text-secondary: #8BA3BC;
  --danger:         #E63946;
  --pager-amber:    #FFB703;
  --border:         #2A3F54;

  --top-bar-h:   56px;
  --tab-bar-h:   64px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ── Screens ─────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
}

/* Setup */
.setup-inner {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.setup-logo img {
  border-radius: 20px;
  background: var(--surface);
}
.setup-inner h1 {
  font-size: 24px;
  font-weight: 600;
  text-align: center;
}
.setup-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
}
.input-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Loading */
.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
}
.loading-inner p { font-size: 15px; }

/* Error */
.error-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  max-width: 300px;
  color: var(--text-secondary);
}
.error-inner svg { color: var(--danger); }
.error-inner h2 { font-size: 20px; color: var(--text-primary); }
.error-inner p { font-size: 15px; line-height: 1.5; }

/* ── Inputs ──────────────────────────────── */
input[type="tel"],
input[type="search"],
input[type="text"] {
  width: 100%;
  min-height: 52px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 17px;
  padding: 0 16px;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}
input[type="tel"]:focus,
input[type="search"]:focus {
  border-color: var(--accent);
}
input::placeholder { color: var(--text-secondary); }
input[type="search"]::-webkit-search-cancel-button { display: none; }

.field-error {
  font-size: 13px;
  color: var(--danger);
}

/* ── Buttons ─────────────────────────────── */
.btn-primary {
  width: 100%;
  min-height: 52px;
  background: var(--accent);
  color: #000;
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary {
  width: 100%;
  min-height: 52px;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 500;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-secondary:active { background: var(--surface-hover); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--surface-hover); }

/* ── Top bar ─────────────────────────────── */
#top-bar {
  position: fixed;
  top: 0;
  left: 0; right: 0;
  height: calc(var(--top-bar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
  padding-right: 12px;
  z-index: 50;
}
.app-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Banners ─────────────────────────────── */
#offline-banner,
#update-banner {
  position: fixed;
  top: calc(var(--top-bar-h) + var(--safe-top));
  left: 0; right: 0;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  z-index: 49;
}
#offline-banner {
  background: var(--pager-amber);
  color: #000;
}
#update-banner {
  background: var(--accent-dark);
  color: var(--text-primary);
}
#update-banner button {
  background: none;
  border: none;
  color: var(--text-primary);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

/* ── Main layout ─────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#tab-content {
  position: fixed;
  top: calc(var(--top-bar-h) + var(--safe-top));
  bottom: calc(var(--tab-bar-h) + var(--safe-bottom));
  left: 0; right: 0;
  overflow: hidden;
}

/* ── Tab panels ──────────────────────────── */
.tab-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  pointer-events: none;
  transition: none;
}
.tab-panel.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── Tab bar ─────────────────────────────── */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: calc(var(--tab-bar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s;
  min-height: 52px;
}
.tab-btn.active {
  color: var(--accent);
}
.tab-btn svg { flex-shrink: 0; }

/* ── Enter Number tab ────────────────────── */
.enter-number-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 32px 20px;
  max-width: 400px;
  margin: 0 auto;
}
.enter-label {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}
#enter-number-input {
  font-family: 'DM Mono', monospace;
  font-size: 28px;
  text-align: center;
  letter-spacing: 2px;
  min-height: 64px;
}

/* ── Contact list ────────────────────────── */
.contact-list {
  list-style: none;
  padding: 8px 0;
}
.contact-list li {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s;
  user-select: none;
}
.contact-list li:active {
  background: var(--surface-hover);
}
.contact-list li:last-child { border-bottom: none; }

.contact-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}
.contact-info {
  flex: 1;
  min-width: 0;
}
.contact-label {
  font-size: 17px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-number {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.contact-chevron {
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* Skeleton shimmer */
.skeleton-item {
  pointer-events: none;
}
.skeleton-line {
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
.skeleton-icon { width: 36px; height: 36px; border-radius: 8px; }
.skeleton-label { width: 55%; height: 16px; }
.skeleton-num   { width: 30%; height: 12px; margin-top: 4px; }
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Directory tab ───────────────────────── */
.dir-view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  background: var(--bg);
}
.dir-view.active-dir {
  transform: translateX(0);
}
.dir-view.slide-out {
  transform: translateX(-30%);
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--accent);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 500;
  padding: 16px 20px 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
  border-bottom: 1px solid var(--border);
  width: 100%;
}
.category-title {
  font-size: 20px;
  font-weight: 600;
  padding: 16px 20px 8px;
}

/* ── Search tab ──────────────────────────── */
.search-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.search-input-wrap {
  position: relative;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-icon {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}
#search-input {
  padding-left: 44px;
}
#search-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.search-hint {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 15px;
}

/* ── Overlays ────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay.modal-center {
  align-items: center;
  padding: 20px;
}

.bottom-sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  padding: 12px 20px calc(20px + var(--safe-bottom));
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px 20px;
  width: 100%;
  max-width: 360px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Confirmation sheet ──────────────────── */
.confirm-contact {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}
.confirm-desc {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.confirm-dial {
  font-size: 14px;
  color: var(--text-secondary);
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 20px;
  word-break: break-all;
}
.confirm-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Settings sheet ──────────────────────── */
.settings-sheet { padding-bottom: calc(32px + var(--safe-bottom)); }
.settings-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
}
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.settings-row {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.settings-label {
  font-size: 15px;
  color: var(--text-secondary);
  flex-shrink: 0;
  min-width: 130px;
}
.settings-value {
  flex: 1;
  font-size: 15px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings-action {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.settings-full-btn {
  width: 100%;
  min-height: 52px;
  background: var(--surface-hover);
  border: none;
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.settings-full-btn:active { background: var(--border); }
.settings-version {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  padding-top: 20px;
}

.desktop-dial {
  font-size: 18px;
  word-break: break-all;
  text-align: center;
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
  margin: 16px 0;
}

/* ── Mono ────────────────────────────────── */
.mono { font-family: 'DM Mono', monospace; }

/* ── Spinners ────────────────────────────── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-sm {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
