/* ==========================
   LAYOUT BASE — Sistema Cobran2 dinámico
   ========================== */

:root {
    --color-primary:       #4F46E5;
    --color-primary-dark:  #3730a3;
    --color-success:       #10B981;
    --color-warning:       #F59E0B;
    --color-danger:        #EF4444;
    --color-info:          #3B82F6;

    --bg:       #f3f4f6;
    --surface:  #ffffff;
    --sidebar:  #1e1e2e;
    --sidebar-hover: #2a2b3d;
    --sidebar-active:#4F46E5;

    --text:     #1f2937;
    --text-light: #6b7280;
    --text-on-dark: #e5e7eb;
    --border:   #e5e7eb;
    --border-dark: #374151;
    --card:     #ffffff;
    --shadow:   0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
    --shadow-lg:0 10px 25px rgba(0,0,0,.08), 0 4px 10px rgba(0,0,0,.04);
    --radius:   10px;
    --radius-sm:6px;

    --sidebar-width: 240px;
    --sidebar-width-collapsed: 72px;
    --topbar-height: 68px;
}

body.theme-dark {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-light: #94a3b8;
    --border: #334155;
    --card: #1e293b;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Inter','Plus Jakarta Sans',-apple-system,BlinkMacSystemFont,sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; border: none; background: none; cursor: pointer; }
h1,h2,h3,h4 { margin: 0; font-weight: 700; color: var(--text); line-height: 1.25; }
p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }

/* Preloader */
.preloader {
    position: fixed; inset: 0; background: var(--bg); z-index: 99999;
    display: grid; place-items: center; transition: opacity .4s;
}
.preloader.hide { opacity: 0; pointer-events: none; }
.preloader-inner { text-align: center; }
.spinner {
    width: 52px; height: 52px; margin: 0 auto 1rem;
    border: 4px solid rgba(79,70,229,.2);
    border-top-color: var(--color-primary);
    border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Theme toggle */
.theme-toggle {
    position: fixed; bottom: 24px; right: 24px; z-index: 900;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--surface); box-shadow: var(--shadow-lg); color: var(--text);
    display: grid; place-items: center; font-size: 1.1rem;
}

/* ====== APP CONTAINER ====== */
.app-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}
.main-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.content-wrapper {
    padding: 1.5rem;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* ====== SIDEBAR ====== */
.sidebar {
    background: var(--sidebar);
    color: var(--text-on-dark);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: width .25s ease;
}
.sidebar.collapsed { width: var(--sidebar-width-collapsed); }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .sidebar-footer span { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 0.85rem; }

.sidebar-header {
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border-dark);
    margin-bottom: 0.5rem;
}
.logo {
    display: flex; align-items: center; gap: 0.6rem;
    font-size: 1.25rem; font-weight: 800; color: #fff;
}
.logo i {
    width: 34px; height: 34px; border-radius: 8px;
    background: linear-gradient(135deg, #4F46E5, #7c3aed);
    display: grid; place-items: center; font-size: 1rem;
}
.logo-text sub { font-size: 0.7rem; color: #a5b4fc; }

.sidebar-nav { flex: 1; padding: 0 0.5rem; }
.sidebar-nav li {
    margin: 0.15rem 0;
}
.nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 0.85rem; border-radius: var(--radius-sm);
    color: var(--text-on-dark); font-size: 0.88rem; font-weight: 500;
    transition: all .15s;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link i { width: 20px; text-align: center; font-size: 0.95rem; }
.sidebar-nav li.active .nav-link {
    background: linear-gradient(135deg, #4F46E5, #7c3aed);
    color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.4);
}
.sidebar-footer {
    padding: 1rem 1.25rem; border-top: 1px solid var(--border-dark);
    font-size: 0.8rem; color: var(--text-light);
}
.user-mini { display: flex; align-items: center; gap: 0.5rem; }
.user-mini .status-online { color: var(--color-success); font-size: 0.55rem; }

/* ====== TOPBAR ====== */
.topbar {
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 0 1.5rem; height: var(--topbar-height);
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; position: sticky; top: 0; z-index: 50;
    box-shadow: var(--shadow);
}
.topbar-left  { display: flex; align-items: center; gap: 1rem; }
.topbar-center{ flex: 1; max-width: 520px; }
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

.menu-toggle {
    display: grid; gap: 4px; padding: 0.5rem; border-radius: 8px;
    transition: background .15s;
}
.menu-toggle:hover { background: #f3f4f6; }
.menu-toggle span {
    display: block; width: 20px; height: 2px; background: var(--text); border-radius: 2px;
    transition: all .2s;
}

.page-info .page-title { font-size: 1.15rem; font-weight: 700; }
.breadcrumb {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.75rem; color: var(--text-light); margin-top: 0.15rem;
}
.breadcrumb i { font-size: 0.65rem; }

.search-box {
    position: relative; width: 100%;
}
.search-box input {
    width: 100%; padding: 0.55rem 1rem 0.55rem 2.3rem;
    border: 1px solid var(--border); border-radius: 8px;
    background: #f9fafb; font-size: 0.85rem;
    transition: all .15s;
}
.search-box input:focus {
    outline: none; background: #fff;
    border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.search-box > i {
    position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%);
    color: var(--text-light); font-size: 0.85rem;
}
.search-box kbd {
    position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%);
    font-size: 0.65rem; background: #fff; padding: 0.15rem 0.4rem;
    border: 1px solid var(--border); border-radius: 4px; color: var(--text-light);
}

.action-btn {
    position: relative; width: 40px; height: 40px;
    display: grid; place-items: center; border-radius: 8px;
    background: #f9fafb; color: var(--text); transition: all .15s;
}
.action-btn:hover { background: #e5e7eb; color: var(--color-primary); }
.notification-badge {
    position: absolute; top: -2px; right: -2px; background: var(--color-danger);
    color: #fff; font-size: 0.6rem; padding: 0.1rem 0.35rem; border-radius: 10px;
    font-weight: 700;
}

.user-profile {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.3rem 0.75rem 0.3rem 0.3rem; border-radius: 24px;
    background: #f9fafb; margin-left: 0.5rem;
}
.user-profile img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.user-info { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-size: 0.8rem; font-weight: 700; }
.user-role { font-size: 0.7rem; color: var(--text-light); }

/* ====== SECTION ====== */
.content-section { display: none; }
.content-section.active { display: block; }
.section-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.section-title h2 { font-size: 1.3rem; margin-bottom: 0.1rem; }
.section-title p { font-size: 0.85rem; color: var(--text-light); }
.section-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ====== WELCOME BANNER ====== */
.welcome-banner {
    position: relative; overflow: hidden;
    background: linear-gradient(135deg, #4F46E5, #7c3aed);
    color: #fff; padding: 1.5rem 1.75rem; border-radius: var(--radius);
    margin-bottom: 1.25rem;
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem; flex-wrap: wrap;
    box-shadow: 0 10px 30px rgba(79,70,229,.25);
}
.welcome-banner h2 { color: #fff; font-size: 1.4rem; margin-bottom: 0.3rem; }
.welcome-banner p  { opacity: 0.95; font-size: 0.92rem; }
.banner-actions    { display: flex; gap: 0.5rem; }

/* ====== BUTTONS ====== */
.btn {
    display: inline-flex; align-items: center; gap: 0.45rem;
    padding: 0.55rem 1.1rem; border-radius: 8px;
    font-size: 0.85rem; font-weight: 600; font-family: inherit;
    transition: all .15s; border: 1px solid transparent;
    white-space: nowrap;
}
.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-outline   { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f9fafb; border-color: var(--color-primary); color: var(--color-primary); }
.btn-white     { background: #fff; color: var(--color-primary); }
.btn-white:hover { background: #f3f4f6; }
.btn-text      { background: transparent; color: var(--color-primary); padding: 0.3rem 0.6rem; }
.btn-sm        { padding: 0.35rem 0.75rem; font-size: 0.78rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ====== KPI GRID ====== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.kpi-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem;
    box-shadow: var(--shadow); transition: all .2s;
    position: relative; overflow: hidden;
}
.kpi-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.kpi-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.kpi-card.primary::before { background: linear-gradient(90deg, #4F46E5, #7c3aed); }
.kpi-card.success::before { background: linear-gradient(90deg, #10B981, #059669); }
.kpi-card.warning::before { background: linear-gradient(90deg, #F59E0B, #d97706); }
.kpi-card.danger::before  { background: linear-gradient(90deg, #EF4444, #b91c1c); }

.kpi-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.85rem;
}
.kpi-icon {
    width: 44px; height: 44px; border-radius: 10px;
    display: grid; place-items: center; font-size: 1.1rem; color: #fff;
}
.kpi-card.primary .kpi-icon { background: linear-gradient(135deg, #4F46E5, #7c3aed); }
.kpi-card.success .kpi-icon { background: linear-gradient(135deg, #10B981, #059669); }
.kpi-card.warning .kpi-icon { background: linear-gradient(135deg, #F59E0B, #d97706); }
.kpi-card.danger  .kpi-icon { background: linear-gradient(135deg, #EF4444, #b91c1c); }

.kpi-body h3 {
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.8px;
    color: var(--text-light); font-weight: 700; margin-bottom: 0.4rem;
}
.kpi-value {
    font-size: 1.7rem; font-weight: 800; line-height: 1.1;
    display: flex; align-items: baseline; gap: 0.15rem;
}
.kpi-value .currency { font-size: 1rem; color: var(--text-light); }
.kpi-footer {
    display: flex; align-items: center; gap: 0.4rem;
    margin-top: 0.6rem; font-size: 0.75rem;
}
.kpi-trend { font-weight: 700; }
.kpi-period { color: var(--text-light); }

/* ====== CHARTS ====== */
.charts-section {
    display: grid; grid-template-columns: 1.5fr 1fr; gap: 1rem;
    margin-bottom: 1.5rem;
}
.chart-container {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}
.chart-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 1rem; gap: 0.75rem;
}
.chart-header h3 { font-size: 0.95rem; }
.chart-header p  { font-size: 0.75rem; color: var(--text-light); margin-top: 0.1rem; }
.chart-body { position: relative; }
.chart-grid { display: grid; gap: 1rem; }

@media (max-width: 1100px) {
    .charts-section { grid-template-columns: 1fr; }
}

/* ====== DATA CARD / TABLE ====== */
.data-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.data-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 0.75rem; flex-wrap: wrap;
}
.data-title h3 { font-size: 1rem; }
.data-title p  { font-size: 0.78rem; color: var(--text-light); }
.data-actions  { display: flex; gap: 0.5rem; align-items: center; }
.data-body { overflow-x: auto; padding: 0; }

.modern-table {
    width: 100%; border-collapse: collapse; font-size: 0.85rem;
}
.modern-table thead {
    background: #f9fafb;
}
.modern-table th {
    padding: 0.75rem 1rem; text-align: left; font-weight: 700;
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-light); white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
.modern-table td {
    padding: 0.85rem 1rem; border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.modern-table tbody tr:hover { background: #f9fafb; }
.modern-table tbody tr:last-child td { border-bottom: none; }

/* ====== RESPONSIVE ====== */
@media (max-width: 900px) {
    .app-container { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; top: 0; left: 0; z-index: 200;
        width: var(--sidebar-width); transform: translateX(-100%);
    }
    .sidebar.show { transform: translateX(0); }
    .topbar-center { display: none; }
    .user-profile .user-info { display: none; }
    .content-wrapper { padding: 1rem; }
    .kpi-value { font-size: 1.4rem; }
}

/* ====== NOTIFICATION CENTER ====== */
.notification-center {
    position: fixed; top: var(--topbar-height); right: -380px; width: 360px;
    height: calc(100vh - var(--topbar-height)); background: var(--surface);
    border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
    z-index: 100; transition: right .25s; display: flex; flex-direction: column;
}
.notification-center.show { right: 0; }
.notification-header {
    padding: 1rem; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.notification-list { flex: 1; overflow-y: auto; padding: 1rem; }

/* Dark theme adjustments */
.theme-dark .topbar { background: #1e293b; border-color: #334155; }
.theme-dark .search-box input { background: #0f172a; color: #f1f5f9; border-color: #334155; }
.theme-dark .kpi-card,
.theme-dark .chart-container,
.theme-dark .data-card,
.theme-dark .agenda-card,
.theme-dark .proy-prod-card { background: #1e293b; border-color: #334155; }
.theme-dark .modern-table thead { background: #0f172a; }
.theme-dark .modern-table th,
.theme-dark .modern-table td { border-color: #334155; }
.theme-dark .modern-table tbody tr:hover { background: #0f172a; }
