/* ==========================================================================
   Babymovil — Prototipo UI (backoffice / tenant)
   Custom CSS, self-contained. Design tokens lifted from the Chaja/Factu ERP.
   ========================================================================== */

:root {
  --body: #f8fafc;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #3b82f6;
  --card: #ffffff;
  --stroke: #e2e8f0;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #dbeafe;
  --secondary: #64748b;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --txt: #0f172a;
  --txt-muted: #64748b;
  --txt-light: #94a3b8;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--body);
  color: var(--txt);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.3; font-weight: 600; margin: 0; }
a { color: inherit; text-decoration: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ===== Layout ============================================================ */
.layout { display: flex; height: 100vh; overflow: hidden; }
.main-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.content { flex: 1; overflow-y: auto; padding: 1.5rem; }
@media (max-width: 640px) { .content { padding: 1rem; } }

/* ===== Sidebar =========================================================== */
.sidebar {
  width: 16rem; color: #cdd3ee;
  background: linear-gradient(185deg, #241f4d 0%, #1a1740 45%, #13112e 100%);
  display: flex; flex-direction: column; flex-shrink: 0;
  overflow-y: auto; overflow-x: hidden;
  transition: transform .2s ease;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: #322c63; border-radius: 4px; }

.sidebar-logo {
  display: flex; align-items: center; gap: .75rem;
  padding: 1.15rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo .logo-badge {
  width: 2.25rem; height: 2.25rem; border-radius: .6rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  box-shadow: 0 4px 10px rgba(59,130,246,.4);
}
.sidebar-logo .logo-badge svg { width: 1.25rem; height: 1.25rem; color: #fff; }
.sidebar-logo h1 { color: #fff; font-size: 1.125rem; font-weight: 700; }
.sidebar-logo p { color: var(--txt-light); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; margin: 0; }

.sidebar nav { flex: 1; padding: 1rem .75rem; display: flex; flex-direction: column; gap: .15rem; }
.sidebar-section {
  font-size: .625rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: #6f72a8; padding: 1.1rem .75rem .4rem;
}
.sidebar-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .75rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500; color: #a7abd4; cursor: pointer;
  transition: all .15s; position: relative;
}
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-link:hover { color: #fff; background: rgba(255,255,255,.07); }
.sidebar-link.active { color: #fff; background: linear-gradient(135deg, #6366f1, #4f46e5); box-shadow: 0 4px 14px rgba(99,102,241,.5); }
.sidebar-link .ext { margin-left: auto; width: 13px; height: 13px; opacity: .5; }

/* Collapsible groups */
.sidebar-group > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .75rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500; color: #a7abd4; transition: all .15s;
}
.sidebar-group > summary::-webkit-details-marker { display: none; }
.sidebar-group > summary svg.lead { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-group > summary:hover { color: #fff; background: rgba(255,255,255,.07); }
.sidebar-group[open] > summary { color: #fff; }
.sidebar-group .chevron { margin-left: auto; width: 16px; height: 16px; transition: transform .15s; }
.sidebar-group[open] > summary .chevron { transform: rotate(90deg); }
.sidebar-group-content { margin: .15rem 0 .15rem 1.5rem; display: flex; flex-direction: column; gap: .1rem; }
.sidebar-group-content .sidebar-link { padding: .4rem .75rem; font-size: .8125rem; }
.sidebar-group-content .sidebar-link svg { width: 16px; height: 16px; }

/* User footer */
.sidebar-user {
  border-top: 1px solid rgba(255,255,255,.08); padding: .75rem;
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-user .avatar {
  width: 2rem; height: 2rem; border-radius: 9999px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff;
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
}
.sidebar-user .info { flex: 1; min-width: 0; }
.sidebar-user .info p.name { color: #fff; font-size: .875rem; font-weight: 500; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .info p.role { color: var(--txt-light); font-size: .75rem; margin: 0; }
.sidebar-user .ico { color: var(--txt-light); display: flex; transition: color .15s; }
.sidebar-user .ico:hover { color: #fff; }
.sidebar-user .ico svg { width: 16px; height: 16px; }

/* Mobile sidebar */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
@media (max-width: 1023px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
}

/* ===== Header / topbar =================================================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .75rem 1.5rem; background: var(--card);
  border-bottom: 1px solid var(--stroke); flex-shrink: 0;
}
.topbar .left { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.topbar h2 { font-size: 1.125rem; font-weight: 600; }
.topbar .subtitle { font-size: .75rem; color: var(--txt-muted); }
.topbar .right { display: flex; align-items: center; gap: .75rem; }
.menu-btn { display: none; background: none; border: none; padding: .375rem; border-radius: var(--radius); color: var(--txt-muted); cursor: pointer; }
.menu-btn:hover { background: #f1f5f9; color: var(--txt); }
.menu-btn svg { width: 20px; height: 20px; }
@media (max-width: 1023px) { .menu-btn { display: inline-flex; } }

.topbar .pos-pill {
  display: flex; align-items: center; gap: .5rem; font-size: .8125rem;
  color: var(--txt-muted); background: #f8fafc; border: 1px solid var(--stroke);
  padding: .4rem .7rem; border-radius: var(--radius);
}
.topbar .pos-pill svg { width: 15px; height: 15px; }
@media (max-width: 640px) { .topbar .pos-pill { display: none; } }

/* ===== Buttons =========================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .5rem 1rem; border-radius: var(--radius); border: 1px solid transparent;
  font-size: .875rem; font-weight: 500; font-family: inherit; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #f1f5f9; color: #475569; border-color: var(--stroke); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: var(--danger-light); color: #dc2626; }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: var(--success-light); color: #059669; }
.btn-success:hover { background: #a7f3d0; }
.btn-warning { background: var(--warning-light); color: #d97706; }
.btn-warning:hover { background: #fde68a; }
.btn-sm { padding: .3rem .65rem; font-size: .8125rem; }
.btn-icon { padding: .4rem; }
.btn-icon svg { width: 15px; height: 15px; }

/* ===== Cards ============================================================= */
.card {
  background: var(--card); border: 1px solid var(--stroke);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 1.25rem; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--stroke);
}
.card-header h3 { font-size: .95rem; font-weight: 600; }
.card-header .sub { font-size: .75rem; color: var(--txt-muted); }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .stat-grid { grid-template-columns: 1fr; } }
.stat {
  background: var(--card); border: 1px solid var(--stroke); border-radius: var(--radius-lg);
  padding: 1.25rem; display: flex; align-items: flex-start; gap: 1rem; box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .15s;
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat .ico { width: 2.75rem; height: 2.75rem; border-radius: var(--radius); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.stat .ico svg { width: 1.25rem; height: 1.25rem; }
.stat .ico.blue { background: var(--primary-light); color: var(--primary-dark); }
.stat .ico.green { background: var(--success-light); color: #059669; }
.stat .ico.amber { background: var(--warning-light); color: #d97706; }
.stat .ico.violet { background: #ede9fe; color: #7c3aed; }
.stat .ico.red { background: var(--danger-light); color: #dc2626; }
.stat .label { font-size: .8125rem; color: var(--txt-muted); margin: 0; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin: .1rem 0 0; letter-spacing: -.02em; }
.stat .delta { font-size: .75rem; margin: .25rem 0 0; display: inline-flex; align-items: center; gap: .25rem; }
.stat .delta svg { width: 13px; height: 13px; }
.stat .delta.up { color: #059669; }
.stat .delta.down { color: #dc2626; }

/* ===== Tables ============================================================ */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  padding: .75rem 1rem; text-align: left; font-size: .7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--txt-muted);
  background: #f8fafc; border-bottom: 2px solid var(--stroke); white-space: nowrap;
}
table.data td {
  padding: .7rem 1rem; font-size: .875rem; color: #334155;
  border-bottom: 1px solid #f1f5f9; vertical-align: middle;
}
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover td { background: #f8fafc; }
table.data .r { text-align: right; }
table.data .c { text-align: center; }
.cell-main { font-weight: 500; color: var(--txt); }
.cell-sub { font-size: .75rem; color: var(--txt-muted); }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; }

/* ===== Badges ============================================================ */
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .6rem; border-radius: 9999px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.badge svg { width: 12px; height: 12px; }
.badge-success { background: var(--success-light); color: #059669; }
.badge-danger { background: var(--danger-light); color: #dc2626; }
.badge-warning { background: var(--warning-light); color: #d97706; }
.badge-info { background: var(--primary-light); color: #2563eb; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 9999px; background: currentColor; }

/* ===== Forms / filters =================================================== */
.input, select.input, textarea.input {
  width: 100%; height: 2.5rem; padding: .5rem .75rem;
  border: 1px solid var(--stroke); border-radius: var(--radius);
  background: #fff; color: var(--txt); font-size: .875rem; font-family: inherit;
  outline: none; transition: all .15s;
}
textarea.input { height: auto; min-height: 4rem; }
.input:focus, select.input:focus, textarea.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
select.input {
  appearance: none; -webkit-appearance: none; height: 2.5rem;
  padding-right: 2.5rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .85rem center; background-size: 1rem;
}
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .75rem; font-weight: 500; color: #475569; }
.search-input { position: relative; }
.search-input svg { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--txt-muted); pointer-events: none; }
.search-input input { padding-left: 2.25rem; }

.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem;
  background: var(--card); border: 1px solid var(--stroke);
  border-radius: var(--radius-lg); padding: 1rem; box-shadow: var(--shadow-sm);
}
.filter-bar .grow { flex: 1; min-width: 200px; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .65rem;
  background: var(--primary-light); color: var(--primary-dark);
  border-radius: 9999px; font-size: .78rem; font-weight: 500;
}
.chip button { background: none; border: none; cursor: pointer; color: inherit; display: flex; padding: 0; opacity: .7; }
.chip button:hover { opacity: 1; }
.chip svg { width: 13px; height: 13px; }

/* ===== Page headings & misc ============================================== */
.page-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; align-items: center; gap: .75rem; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.muted { color: var(--txt-muted); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.fw-600 { font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

/* Empty state */
.empty { text-align: center; padding: 3.5rem 1rem; color: var(--txt-muted); }
.empty svg { width: 3rem; height: 3rem; margin: 0 auto .75rem; opacity: .35; display: block; }
.empty p { margin: 0; }

/* Pagination */
.pager { display: flex; align-items: center; justify-content: space-between; padding: .85rem 1.25rem; border-top: 1px solid var(--stroke); font-size: .8125rem; color: var(--txt-muted); }
.pager .pages { display: flex; gap: .25rem; }
.pager .pages a, .pager .pages span {
  display: inline-flex; align-items: center; justify-content: center; min-width: 2rem; height: 2rem;
  padding: 0 .5rem; border-radius: var(--radius); border: 1px solid var(--stroke); background: #fff; color: #475569; font-weight: 500;
}
.pager .pages a:hover { background: #f1f5f9; }
.pager .pages .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Progress / mini bars */
.bar { height: 6px; border-radius: 9999px; background: #eef2f7; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 9999px; background: var(--primary); }
.bar > span.low { background: var(--danger); }
.bar > span.mid { background: var(--warning); }

/* Section title */
.section-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em; }

/* Mini chart (CSS bars) */
.chart { display: flex; align-items: flex-end; gap: .55rem; height: 160px; padding-top: .5rem; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .4rem; height: 100%; justify-content: flex-end; }
.chart .col .fill { width: 100%; max-width: 34px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, #60a5fa, #3b82f6); transition: height .3s; }
.chart .col .lbl { font-size: .68rem; color: var(--txt-muted); }

/* ===== Switch toggle ===================================================== */
.switch { position: relative; display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; user-select: none; font-size: .875rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 2.4rem; height: 1.35rem; border-radius: 9999px; background: #cbd5e1; transition: .2s; flex-shrink: 0; position: relative; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 1.05rem; height: 1.05rem; border-radius: 9999px; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(1.05rem); }
.switch input:disabled + .track { opacity: .5; }

/* ===== Callout / info box =============================================== */
.callout { display: flex; gap: .6rem; padding: .75rem .9rem; border-radius: var(--radius); font-size: .85rem; line-height: 1.5; }
.callout svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; }
.callout-info { background: var(--primary-light); color: #1e40af; }
.callout-warning { background: var(--warning-light); color: #92400e; }
.callout-success { background: var(--success-light); color: #065f46; }
.callout-muted { background: #f1f5f9; color: #475569; }

/* ===== Forms layout ===================================================== */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .full { grid-column: 1 / -1; }
.input-prefix { position: relative; }
.input-prefix > span { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--txt-muted); font-size: .875rem; }
.input-prefix > input { padding-left: 1.6rem; }
.divider { border: none; border-top: 1px solid var(--stroke); margin: 0; }

/* ===== Channel logos / cards =========================================== */
.chan-logo { width: 2.5rem; height: 2.5rem; border-radius: .6rem; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: .8rem; flex-shrink: 0; }
.chan-logo svg { width: 1.25rem; height: 1.25rem; }
.chan-ml { background: #ffe600; color: #2d3277; }
.chan-tn { background: #2b3a8c; color: #fff; }
.chan-web { background: #ede9fe; color: #6d28d9; }
.chan-pos { background: #0f172a; color: #fff; }
.chan-tag { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; font-size: .8125rem; }
.chan-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
@media (max-width: 900px) { .chan-grid { grid-template-columns: 1fr; } }
.conn-dot { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 600; }
.conn-dot::before { content: ""; width: 8px; height: 8px; border-radius: 9999px; background: currentColor; }
.conn-ok { color: #059669; }
.conn-off { color: #dc2626; }

/* Checkable channel row (for product auto-publish) */
.pub-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem .9rem; border: 1px solid var(--stroke); border-radius: var(--radius); cursor: pointer; }
.pub-row + .pub-row { margin-top: .6rem; }
.pub-row.on { border-color: var(--primary); background: #f5f9ff; }

/* Inputs: checkboxes & spinner */
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 1rem; height: 1rem; cursor: pointer; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* tiny channel chips used inside tables */
.chip-chan { display: inline-flex; align-items: center; justify-content: center; width: 1.4rem; height: 1.4rem; border-radius: .35rem; font-size: .6rem; font-weight: 800; }
.chip-chan svg { width: 12px; height: 12px; }
