:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #10223a;
  --muted: #6b7c93;
  --primary: #0ea46f;
  --primary-dark: #0a8055;
  --secondary: #1b5fa8;
  --secondary-dark: #154c86;
  --danger: #b42318;
  --danger-dark: #912018;
  --border: #dbe4ef;
  --chip-bg: #edf4ff;
  --chip-border: #c8ddf6;
  --chip-text: #194a7c;
  --whatsapp: #25d366;
  --whatsapp-dark: #1da851;
  --header-h: 56px;
  --nav-h: 64px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(16,34,58,.05);
}

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

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.3px;
}

.header-status {
  font-size: 12px;
  color: var(--muted);
}

/* ── Main area ───────────────────────────────────────────────────────────── */

.app-main {
  position: fixed;
  top: var(--header-h);
  bottom: var(--nav-h);
  left: 0; right: 0;
  overflow: hidden;
}

.tab-panel {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.tab-panel.hidden { display: none !important; }

.panel-scroll {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Bottom nav ──────────────────────────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  box-shadow: 0 -2px 16px rgba(16,34,58,.07);
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 4px 10px;
  transition: color .15s;
  letter-spacing: .2px;
}

.nav-item.active { color: var(--primary); }

.nav-icon {
  width: 22px;
  height: 22px;
  stroke-width: 2;
}

.nav-item.active .nav-icon { stroke-width: 2.5; }

/* ── Fields ──────────────────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.field-hint {
  font-size: 13px;
  color: var(--primary);
  font-weight: 700;
  min-height: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}

.field-prefix { width: 76px; }
.field-prefix input { text-align: center; font-weight: 700; }

input, textarea {
  font: inherit;
  font-size: 15px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--text);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,164,111,.12);
}

textarea { resize: none; }

.phone-big {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 14px 12px;
  text-align: center;
  border-radius: 12px;
}

/* ── Templates ───────────────────────────────────────────────────────────── */

.template-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-chip-add {
  background: var(--chip-bg);
  border: 1.5px solid var(--chip-border);
  color: var(--chip-text);
  border-radius: 20px;
  padding: 4px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}

.btn-chip-add:hover { background: #d9eaff; }

.template-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 172px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.template-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
}

.template-main {
  background: var(--chip-bg);
  border: 1.5px solid var(--chip-border);
  color: var(--chip-text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-main:hover, .template-main:active { background: #d5e8ff; border-color: #94bef0; }

.template-edit {
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}

.template-edit:hover { background: #f0f4f8; }

/* Template editor */

.template-editor {
  background: #f4f8ff;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.editor-title { font-weight: 800; font-size: 14px; }

.btn-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  line-height: 1;
  transition: background .12s;
}

.btn-close:hover { background: #e0e9f6; }

.editor-actions { display: flex; gap: 8px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-full { width: 100%; }

.btn-sm {
  padding: 9px 14px;
  font-size: 14px;
  border-radius: 8px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: var(--secondary-dark); }

.btn-ghost { background: #eef2f9; color: #23405f; }
.btn-ghost:hover { background: #e0e9f6; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }

.btn-whatsapp {
  background: var(--whatsapp);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  padding: 16px;
  border-radius: 14px;
  letter-spacing: .2px;
  box-shadow: 0 4px 14px rgba(37,211,102,.35);
}

.btn-whatsapp:hover { background: var(--whatsapp-dark); }
.btn-whatsapp:active { transform: scale(.98); }

/* ── Row actions ─────────────────────────────────────────────────────────── */

.row-actions { display: flex; gap: 8px; }
.row-actions .btn { flex: 1; }

/* ── Panel titles ────────────────────────────────────────────────────────── */

.panel-title { font-size: 20px; font-weight: 800; }
.panel-sub { font-size: 13px; color: var(--muted); margin-top: -4px; }

/* ── Metrics ─────────────────────────────────────────────────────────────── */

.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.metric {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.metric strong {
  display: block;
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}

.metric span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

/* ── Table ───────────────────────────────────────────────────────────────── */

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

table { width: 100%; border-collapse: collapse; font-size: 12px; }

th, td {
  border-bottom: 1px solid #edf2f9;
  text-align: left;
  padding: 9px 10px;
  white-space: nowrap;
}

th {
  background: #f7fafc;
  font-size: 10px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
}

tr:last-child td { border-bottom: none; }

/* ── Config tab ──────────────────────────────────────────────────────────── */

.config-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.config-section-title { font-size: 15px; font-weight: 800; }

.config-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: -4px;
}

.config-btn-group {
  display: flex;
  gap: 8px;
}

.config-btn-group .btn { flex: 1; }

.status-text {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  padding: 8px 10px;
  background: #f4f7fb;
  border-radius: 8px;
  border: 1px solid var(--border);
}
