:root {
  --bg: #F5F7FA;
  --bg2: #FFFFFF;
  --bg3: #EEF2F6;
  --border: #E3E9EF;
  --border2: #EDF1F5;
  --accent: #0B5CAB;
  --accent2: #094A8A;
  --ink: #0F2B46;
  --ink2: #0A1F33;
  --text: #16232F;
  --text2: #64748B;
  --danger: #DC2626;
  --success: #16A34A;
  --warn: #D97706;
  --radius: 10px;
  --sidebar-w: 232px;
  --shadow: 0 1px 2px rgba(15,43,70,.05), 0 1px 3px rgba(15,43,70,.04);
  --shadow-md: 0 4px 16px rgba(15,43,70,.10);
}

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

body {
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── LAYOUT ─── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-logo {
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .icon { display: flex; }
.sidebar-logo .icon svg { width: 30px; height: 30px; }
.sidebar-logo h1 { font-size: 13px; font-weight: 800; color: #fff; line-height: 1.2; letter-spacing: -.01em; }
.sidebar-logo small { color: rgba(255,255,255,.5); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; font-weight: 600; }

nav { flex: 1; padding: 10px 8px; overflow-y: auto; }

nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  color: rgba(255,255,255,.62);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  border-radius: 8px;
  margin-bottom: 2px;
  transition: color .12s, background .12s;
  cursor: pointer;
}
nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
nav a.active { color: #fff; background: var(--accent); font-weight: 600; }
nav a .nav-icon { display: inline-flex; width: 18px; justify-content: center; }
nav a .nav-icon svg { width: 16px; height: 16px; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px; color: rgba(255,255,255,.5);
}
.sidebar-footer .user { font-weight: 700; color: #fff; margin-bottom: 8px; font-size: 13px; }
.sidebar-footer .btn-secondary {
  background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.15); box-shadow: none;
}
.sidebar-footer .btn-secondary:hover { background: rgba(255,255,255,.14); }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 54px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: var(--bg2);
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar h2 { font-size: 15px; font-weight: 800; letter-spacing: -.01em; }
.topbar .topbar-actions { display: flex; gap: 8px; align-items: center; }

.content { padding: 24px; flex: 1; max-width: 1200px; }

/* ─── CARDS / STATS ─── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 11px; color: var(--text2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat-card .value { font-size: 28px; font-weight: 800; color: var(--text); letter-spacing: -.02em; }
.stat-card .sub { font-size: 11px; color: var(--text2); margin-top: 3px; }
.stat-card.accent { border-top: 3px solid var(--accent); }
.stat-card.accent .value { color: var(--accent); }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card-header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 13px; color: var(--text);
  background: #FAFBFC;
}

/* ─── TABLES ─── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th { padding: 9px 16px; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); border-bottom: 1px solid var(--border); white-space: nowrap; background: #FAFBFC; font-weight: 600; }
td { padding: 10px 16px; border-bottom: 1px solid var(--border2); vertical-align: middle; color: var(--text); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(11,92,171,0.02); }

/* ─── BADGES ─── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-green { background: #DCFCE7; color: #15803D; }
.badge-red { background: #FEE2E2; color: #B91C1C; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-teal { background: #DBEAFE; color: var(--accent2); }
.badge-gray { background: #F1F5F9; color: var(--text2); border: 1px solid var(--border); }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  border: none; cursor: pointer;
  transition: opacity .12s, transform .1s, box-shadow .12s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { opacity: .9; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 3px rgba(11,92,171,.35); }
.btn-primary:hover { background: var(--accent2); opacity: 1; }
.btn-secondary { background: var(--bg2); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); }
.btn-secondary:hover { background: var(--bg3); opacity: 1; }
.btn-danger { background: #FEF2F2; color: var(--danger); border: 1px solid #FECACA; }
.btn-danger:hover { background: #FEE2E2; opacity: 1; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ─── FORMS ─── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; font-weight: 700; color: var(--text2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .06em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 11px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-size: 13.5px; outline: none;
  transition: border-color .12s, box-shadow .12s;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11,92,171,.12);
}
.field input[type="color"] { padding: 4px 8px; height: 38px; cursor: pointer; }
.field select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748B' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; appearance: none; }
.field textarea { resize: vertical; min-height: 72px; }
.field .hint { font-size: 11px; color: var(--text2); margin-top: 4px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ─── LOGO PREVIEW ─── */
.logo-preview {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  background: #FAFBFC;
  margin-bottom: 14px;
  min-height: 80px;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.logo-preview .brand-name-preview {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1;
}
.logo-preview .preview-label {
  font-size: 10px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-top: 8px;
}

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,43,70,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(15,43,70,.25);
}
.modal-header {
  padding: 16px 20px 13px;
  border-bottom: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 15px; background: #FAFBFC;
  border-radius: 14px 14px 0 0;
}
.modal-body { padding: 18px 20px; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border2);
  display: flex; justify-content: flex-end; gap: 8px;
  background: #FAFBFC; border-radius: 0 0 14px 14px;
}
.btn-close { background: none; border: none; cursor: pointer; color: var(--text2); font-size: 20px; line-height: 1; }
.btn-close:hover { color: var(--text); }

/* ─── LOGIN ─── */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, var(--ink) 0%, var(--ink2) 60%, #071522 100%);
}
.login-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px;
  width: 100%; max-width: 350px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo .icon { display: flex; justify-content: center; margin-bottom: 10px; }
.login-logo .icon svg { width: 46px; height: 46px; }
.login-logo h1 { font-size: 17px; font-weight: 800; color: var(--text); letter-spacing: -.02em; }
.login-logo small { color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }

/* ─── MISC ─── */
.error-msg { background: #FEF2F2; border: 1px solid #FECACA; color: var(--danger); padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.success-msg { background: #F0FDF4; border: 1px solid #BBF7D0; color: var(--success); padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.hidden { display: none !important; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
.text-muted { color: var(--text2); }
.text-sm { font-size: 12px; }
.mono { font-family: 'SF Mono', 'Consolas', monospace; font-size: 12px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ─── BAR CHART ─── */
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 72px; }
.bar-chart .bar { flex: 1; background: #C7DDF2; border-radius: 4px 4px 0 0; min-height: 3px; position: relative; transition: background .15s; }
.bar-chart .bar:hover { background: var(--accent); }
.bar-chart .bar.conv { background: #BBE7C9; }
.bar-chart .bar.conv:hover { background: var(--success); }
.chart-legend { display: flex; gap: 14px; align-items: center; font-size: 11px; color: var(--text2); margin-top: 10px; }
.chart-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ─── TOAST ─── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--ink); border: 1px solid rgba(0,0,0,.1);
  color: #fff; padding: 11px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(15,43,70,.3);
  z-index: 1000;
}
#toast.hidden { display: none; }

/* ─── MOBILE ─── */
.menu-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--text); font-size: 22px; padding: 4px; }

.overlay-bg { display: none; position: fixed; inset: 0; background: rgba(15,43,70,.45); z-index: 99; }
.overlay-bg.visible { display: block; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .topbar { padding: 0 14px; }
  .content { padding: 14px; }
}

/* ─── PROVINCIAS ACORDEÓN ─── */
.prov-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.prov-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; cursor: pointer;
  transition: background .12s;
  user-select: none;
}
.prov-header:hover { background: #FAFBFC; }
.prov-header .prov-name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.prov-header .prov-meta { display: flex; align-items: center; gap: 10px; }
.prov-header .chevron { font-size: 12px; color: var(--text2); transition: transform .2s; }
.prov-card.open .chevron { transform: rotate(180deg); }

.prov-body {
  display: none;
  border-top: 1px solid var(--border2);
  background: #FAFBFC;
}
.prov-card.open .prov-body { display: block; }

.tel-list { padding: 6px 16px; }
.tel-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border2);
  gap: 10px;
}
.tel-row:last-child { border-bottom: none; }
.tel-num { font-family: 'SF Mono','Consolas',monospace; font-size: 13px; font-weight: 600; }
.tel-label { font-size: 12px; color: var(--text2); }
.tel-actions { display: flex; gap: 6px; flex-shrink: 0; }

.tel-add-row {
  padding: 10px 16px;
  border-top: 1px solid var(--border2);
  background: var(--bg2);
}

/* ─── FONT PICKER GRID ─── */
.font-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-top: 6px;
}
.font-option {
  border: 2px solid var(--border); border-radius: 8px;
  padding: 10px 8px; text-align: center; cursor: pointer;
  background: var(--bg2); transition: border-color .12s, background .12s;
}
.font-option:hover { background: var(--bg3); }
.font-option.selected { border-color: var(--accent); background: #EFF6FF; }
.font-option .sample { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.2; }
.font-option .name { font-size: 10px; color: var(--text2); margin-top: 4px; }

@media (max-width: 900px) {
  .dash-tops { grid-template-columns: 1fr !important; }
}
