:root {
    /* Paleta de marca: negro, blanco y amarillo (fernandocarrero.com) */
    --bg: #f6f6f4;
    --surface: #ffffff;
    --border: #e8e8e6;
    --text: #0d0d0d;
    --text-muted: #6b6b68;
    --primary: #0d0d0d;         /* negro como color de acción principal */
    --primary-dark: #000000;
    --accent: #FFC629;          /* amarillo de marca — uso puntual, no decorativo */
    --accent-dark: #E6AF00;
    --success: #16a34a;
    --success-bg: #ecfdf3;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --sidebar-bg: #0d0d0d;
    --sidebar-bg-hover: #1e1e1e;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(13, 13, 13, 0.06), 0 8px 24px rgba(13, 13, 13, 0.05);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 4px; font-weight: 700; letter-spacing: -0.01em; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: #cfd2e6;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    gap: 10px; padding: 30px 20px 24px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-mark-img {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; border-radius: 10px; background: #fff; padding: 6px; flex-shrink: 0;
}
.brand-mark-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-mark-img-sidebar { width: 84px; height: 84px; border-radius: 18px; padding: 12px; }
.brand-mark-img-lg { width: 136px; height: 136px; border-radius: 26px; padding: 18px; }
.brand-text strong { display: block; color: #fff; font-size: 15px; }
.brand-text small { color: #9a9a97; font-size: 12px; }
.brand-text-stacked { display: flex; flex-direction: column; gap: 2px; }
.brand-text-stacked strong { font-size: 15px; }
.brand-text-stacked small { font-size: 12px; }

.sidebar-nav { display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: 10px; color: #c4c4c1;
    font-weight: 500; font-size: 14px; transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--sidebar-bg-hover); text-decoration: none; color: #fff; }
.nav-item.active { background: var(--sidebar-bg-hover); color: #fff; border-left-color: var(--accent); }
.nav-icon { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-footer { padding: 16px 20px; color: #66665f; font-size: 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-divider { height: 1px; background: rgba(255,255,255,0.08); margin: 8px 14px; }

.main-content { flex: 1; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.page-title { flex: 1; font-size: 20px; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }

.project-switcher { display: flex; align-items: center; gap: 8px; margin-right: 16px; }
.project-switcher-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.project-switcher select {
    padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: #f6f6f4;
    font-size: 13px; font-weight: 600; max-width: 220px;
}
.project-pill {
    padding: 6px 14px; border-radius: 999px; background: #f6f6f4; border: 1px solid var(--border);
    font-size: 13px; font-weight: 700; margin-right: 16px;
}

.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.role-badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.role-superadmin { background: #0d0d0d; color: var(--accent); }
.role-client { background: #f1f1ef; color: var(--text-muted); }

.content-area { padding: 24px 28px 48px; max-width: 1400px; }

/* ---------- Auth page ---------- */
.auth-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: #0d0d0d;
    background-image: radial-gradient(circle at 15% 15%, #1a1a1a 0%, #0d0d0d 55%);
    padding: 20px;
}
.auth-card {
    width: 100%; max-width: 380px; background: var(--surface);
    border-radius: 18px; padding: 36px 32px; box-shadow: 0 20px 60px rgba(0,0,0,0.45);
    border-top: 4px solid var(--accent);
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand h1 { font-size: 20px; margin-top: 12px; }
.auth-brand p { color: var(--text-muted); margin: 4px 0 0; font-size: 13px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }

/* ---------- Forms & inputs ---------- */
input[type="text"], input[type="password"], input[type="file"], select {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
    font-family: inherit; font-size: 14px; background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: 2px solid #ffe38a; border-color: var(--primary); }
.stacked-form { display: flex; flex-direction: column; gap: 14px; max-width: 360px; }
.stacked-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.inline-form { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }
.inline-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.mini-form { display: flex; gap: 8px; }
.inline-action-form { display: inline-block; margin-left: 6px; }
.inline-details { display: inline-block; margin-right: 6px; }
.inline-details[open] summary { margin-bottom: 6px; }
.inline-details .mini-form { margin-top: 6px; }
.mini-form-stack { flex-direction: column; align-items: stretch; min-width: 180px; }
.mini-form-stack input { margin-bottom: 6px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 18px; border-radius: 10px; border: none; cursor: pointer;
    font-family: inherit; font-weight: 600; font-size: 14px; transition: transform .1s, background .15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; border: 1px solid #0d0d0d; }
.btn-primary:hover { background: #000; text-decoration: none; }
.btn-secondary { background: #eeeeec; color: var(--text); }
.btn-secondary:hover { background: #e3e3e0; text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f4f4f2; text-decoration: none; }
.btn-danger { background: var(--error-bg); color: var(--error); }
.btn-danger:hover { background: #fde2e2; text-decoration: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- Alerts ---------- */
.alert { padding: 14px 16px; border-radius: 12px; margin-bottom: 20px; font-size: 14px; }
.alert-success { background: var(--success-bg); color: #166534; }
.alert-error { background: var(--error-bg); color: #991b1b; }
.alert-warning { background: var(--warning-bg); color: #92400e; }
.error-list { margin: 8px 0 0; padding-left: 18px; font-size: 12px; max-height: 140px; overflow-y: auto; }

/* ---------- Cards & panels ---------- */
.panel-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px; margin-bottom: 24px; box-shadow: var(--shadow);
}
.panel-card-narrow { max-width: 480px; }
.text-muted { color: var(--text-muted); font-size: 13px; }

.empty-state {
    text-align: center; padding: 80px 20px; color: var(--text-muted);
}
.empty-state h2 { color: var(--text); margin-bottom: 8px; }

/* ---------- Filters ---------- */
.filters-bar {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: end;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.filter-group { display: flex; flex-direction: column; gap: 6px; min-width: 160px; }
.filter-group label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.filter-grow { flex: 1; min-width: 220px; }

/* ---------- KPI grid ---------- */
.kpi-grid {
    display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 22px;
}
.kpi-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.kpi-icon {
    width: 40px; height: 40px; border-radius: 10px; background: #f6f6f4;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    border: 1px solid var(--border); color: #0d0d0d;
}
.kpi-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi-label { font-size: 11px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-size: 21px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Charts ---------- */
.charts-grid {
    display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-bottom: 24px;
    grid-template-areas: "wide wide" "a b";
}
.chart-card-wide { grid-area: wide; }
.charts-grid .chart-card:nth-of-type(2) { grid-area: a; }
.charts-grid .chart-card:nth-of-type(3) { grid-area: b; }
.chart-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow);
}
.chart-card h3 { font-size: 14px; margin-bottom: 14px; color: var(--text); }

/* ---------- Tables ---------- */
.table-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow);
}
.table-card-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.table-hint { font-size: 12px; color: var(--text-muted); }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
.data-table th {
    text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 700;
    text-transform: uppercase; font-size: 11px; letter-spacing: .03em; border-bottom: 2px solid var(--border);
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: #fafaf9; }
.cell-name { font-weight: 600; }
.table-loading { text-align: center; color: var(--text-muted); padding: 24px; }

.status-pill { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status-active { background: var(--success-bg); color: #166534; }
.status-inactive { background: #f1f2f8; color: var(--text-muted); }

/* ---------- Tabla de campañas expandible (detalle por anuncio) ---------- */
.campaign-row { cursor: pointer; transition: background .1s; }
.campaign-row:hover td { background: #fafaf9; }
.campaign-row.expanded td { background: #f6f6f4; }
.cell-toggle { width: 24px; }
.row-chevron { display: inline-flex; color: var(--text-muted); transition: transform .15s; }
.campaign-row.expanded .row-chevron { transform: rotate(90deg); color: #0d0d0d; }
.ads-row td { padding: 0; border-bottom: 1px solid var(--border); }
.ads-cell { background: #fbfbfa; }
.ads-detail { padding: 10px 16px 18px; overflow-x: auto; max-width: 100%; }
.ads-table { min-width: 2100px; font-size: 12.5px; }
.ads-table th { font-size: 10.5px; padding: 9px 11px; white-space: nowrap; }
.ads-table td { padding: 8px 11px; white-space: nowrap; }
.ads-table .cell-name { min-width: 170px; white-space: normal; }
.ads-table .cell-wrap { white-space: normal; max-width: 230px; }
.ads-hint { font-size: 11px; color: var(--text-muted); padding: 0 4px 8px; }

/* ---------- Upload ---------- */
.upload-form { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 16px; }
.file-drop {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    border: 2px dashed var(--border); border-radius: 12px; padding: 24px;
    flex: 1; min-width: 260px; cursor: pointer; color: var(--text-muted); font-weight: 600;
    transition: border-color .15s, background .15s;
}
.file-drop:hover { border-color: var(--primary); background: #faf6e8; }
.file-drop input { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .charts-grid { grid-template-columns: 1fr; grid-template-areas: "wide" "a" "b"; }
}

@media (max-width: 900px) {
    .menu-toggle { display: block; }
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 100; transform: translateX(-100%);
        transition: transform .2s ease; box-shadow: 20px 0 40px rgba(0,0,0,0.2);
    }
    .sidebar.open { transform: translateX(0); }
    .content-area { padding: 18px 16px 40px; }
    .topbar { padding: 14px 16px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .user-chip { display: none; }
}

@media (max-width: 520px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .kpi-value { font-size: 18px; }
    .auth-card { padding: 28px 22px; }
}

/* ---------- Análisis IA ---------- */
.ai-output {
    margin-top: 16px; padding: 18px 20px; background: #fafaf9; border: 1px solid var(--border);
    border-radius: 12px; font-size: 14px; line-height: 1.6;
}
.ai-output h3 { font-size: 16px; margin: 0 0 10px; border-left: 4px solid var(--accent); padding-left: 10px; }
.ai-output h4 { font-size: 14px; margin: 18px 0 8px; border-left: 4px solid var(--accent); padding-left: 10px; }
.ai-output h4:first-child { margin-top: 0; }
.ai-output p { margin: 0 0 10px; }
.ai-output ul { margin: 0 0 12px; padding-left: 20px; }
.ai-output li { margin-bottom: 6px; }

/* ---------- Formularios de tareas / textareas ---------- */
.stacked-form textarea, .inline-form textarea {
    font-family: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; resize: vertical;
}

/* ---------- Responsive extra: topbar con selector de proyecto ---------- */
@media (max-width: 900px) {
    .project-switcher-label { display: none; }
    .project-switcher select { max-width: 140px; }
}
