/* ============================================================
   FERIA CATEMU — Main Stylesheet
   Municipalidad de Catemu
   ============================================================ */

/* CSS Variables */
:root {
    --primary:        #7B2D8B;
    --primary-dark:   #5A1F6B;
    --primary-darker: #3D1249;
    --primary-light:  #9B4DAB;
    --primary-pale:   #E8D5EF;
    --secondary:      #3A9A4A;
    --secondary-dark: #2B7A38;
    --secondary-light:#5BBD6A;
    --accent:         #E8642A;
    --accent-dark:    #C44F1E;
    --warning-color:  #F5A623;
    --light-bg:       #FAF5FF;
    --text-dark:      #2D1547;
    --text-muted:     #6B6B80;
    --border-color:   #E0D5EB;
    --sidebar-width:  260px;
    --sidebar-collapsed: 70px;
    --navbar-height:  60px;
    --card-radius:    12px;
    --transition:     0.25s ease;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--light-bg);
    color: var(--text-dark);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, var(--primary-darker) 0%, var(--primary-dark) 40%, var(--primary) 100%);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    transition: transform var(--transition);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--warning-color) 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(232,100,42,0.4);
}

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.logo-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    letter-spacing: 1px;
}

.logo-sub {
    font-size: 0.7rem;
    font-weight: 400;
    color: rgba(255,255,255,0.65);
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Sidebar Toggle (mobile) */
.sidebar-toggle {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition);
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.2); }

/* Sidebar User */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--secondary) 0%, var(--secondary-dark) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.2);
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.6);
    text-transform: capitalize;
}

/* Sidebar Nav */
.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
    position: relative;
}

.nav-item:hover {
    color: white;
    background: rgba(255,255,255,0.1);
    transform: translateX(2px);
}

.nav-item.active {
    color: white;
    background: rgba(255,255,255,0.15);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

.nav-item i:first-child {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.nav-logout {
    color: rgba(255,160,140,0.85) !important;
}

.nav-logout:hover {
    color: #ffb3a0 !important;
    background: rgba(220,53,69,0.15) !important;
}

/* ============================================================
   MAIN WRAPPER
   ============================================================ */
.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition);
}

/* ============================================================
   TOP NAVBAR
   ============================================================ */
.top-navbar {
    position: sticky;
    top: 0;
    height: var(--navbar-height);
    background: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 100;
    box-shadow: 0 1px 8px rgba(123,45,139,0.06);
}

.navbar-left, .navbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-toggle-btn {
    color: var(--text-dark) !important;
    padding: 0.25rem !important;
    text-decoration: none;
    border: none;
    background: none;
}

.sidebar-toggle-btn:hover { color: var(--primary) !important; }

.breadcrumb { font-size: 0.8rem; }
.breadcrumb-item a { color: var(--primary); text-decoration: none; }
.breadcrumb-item a:hover { text-decoration: underline; }

.user-menu-btn {
    display: flex;
    align-items: center;
    color: var(--text-dark) !important;
    text-decoration: none !important;
    border: none;
    background: none;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.user-avatar-sm {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    flex: 1;
    padding: 1.75rem;
}

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1049;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--card-radius);
    box-shadow: 0 2px 8px rgba(123,45,139,0.06);
    transition: box-shadow var(--transition), transform var(--transition);
}

.card:hover {
    box-shadow: 0 4px 16px rgba(123,45,139,0.12);
}

.card-header {
    background: white;
    border-bottom: 1px solid var(--border-color);
    border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* Stat Cards */
.stat-card {
    background: white;
    border-radius: var(--card-radius);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(123,45,139,0.06);
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(123,45,139,0.14);
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.stat-card.stat-green::after  { background: var(--secondary); }
.stat-card.stat-orange::after { background: var(--accent); }
.stat-card.stat-yellow::after { background: var(--warning-color); }
.stat-card.stat-red::after    { background: #dc3545; }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 1rem;
}

.stat-icon.purple  { background: var(--primary-pale); color: var(--primary); }
.stat-icon.green   { background: #d4edda; color: var(--secondary-dark); }
.stat-icon.orange  { background: #fde8db; color: var(--accent-dark); }
.stat-icon.yellow  { background: #fef3cd; color: #856404; }
.stat-icon.red     { background: #f8d7da; color: #721c24; }

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-change {
    font-size: 0.75rem;
    margin-top: 0.5rem;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-container {
    background: white;
    border-radius: var(--card-radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(123,45,139,0.06);
}

.table {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table thead th {
    background: var(--light-bg);
    color: var(--text-dark);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
    padding: 0.85rem 1rem;
    white-space: nowrap;
}

.table tbody tr {
    transition: background var(--transition);
}

.table tbody tr:hover {
    background: rgba(123,45,139,0.03);
}

.table tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-color: var(--border-color);
}

/* ============================================================
   BADGES
   ============================================================ */
.badge-presente {
    background: #d4edda;
    color: #155724;
    font-weight: 600;
}

.badge-ausente {
    background: #f8d7da;
    color: #721c24;
    font-weight: 600;
}

.badge-justificado {
    background: #fff3cd;
    color: #856404;
    font-weight: 600;
}

.badge-libre {
    background: #d1ecf1;
    color: #0c5460;
    font-weight: 600;
}

.badge {
    font-size: 0.72rem;
    padding: 0.35em 0.65em;
    border-radius: 6px;
    font-weight: 600;
}

/* Bootstrap primary badge override */
.badge.bg-primary { background-color: var(--primary) !important; }
.btn-primary { background-color: var(--primary) !important; border-color: var(--primary) !important; }
.btn-primary:hover { background-color: var(--primary-dark) !important; border-color: var(--primary-dark) !important; }
.btn-outline-primary { color: var(--primary) !important; border-color: var(--primary) !important; }
.btn-outline-primary:hover { background-color: var(--primary) !important; color: white !important; }

/* ============================================================
   FORMS
   ============================================================ */
.form-control:focus, .form-select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(123,45,139,0.15);
}

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-dark);
    margin-bottom: 0.35rem;
}

.form-text { font-size: 0.775rem; }

.required-mark::after {
    content: ' *';
    color: #dc3545;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0;
    line-height: 1.2;
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.25rem 0 0;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: stretch;
    background: var(--light-bg);
}

.login-left {
    flex: 1;
    background: linear-gradient(145deg, var(--primary-darker) 0%, var(--primary-dark) 35%, var(--primary) 65%, var(--primary-light) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    position: relative;
    overflow: hidden;
}

.login-left::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at center, rgba(255,255,255,0.05) 0%, transparent 60%);
}

.login-left .decorative-circle {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
}

.login-left .decorative-circle:nth-child(1) { width: 300px; height: 300px; top: -100px; right: -100px; }
.login-left .decorative-circle:nth-child(2) { width: 200px; height: 200px; bottom: -50px; left: -50px; }
.login-left .decorative-circle:nth-child(3) { width: 150px; height: 150px; top: 30%; left: -30px; }

.login-brand {
    position: relative;
    z-index: 1;
    text-align: center;
    color: white;
}

.login-brand-icon {
    width: 90px;
    height: 90px;
    background: rgba(255,255,255,0.15);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin: 0 auto 1.5rem;
    border: 2px solid rgba(255,255,255,0.2);
    backdrop-filter: blur(4px);
}

.login-brand h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 0.5rem;
}

.login-brand p {
    font-size: 1rem;
    opacity: 0.85;
    max-width: 300px;
    margin: 0 auto 0.5rem;
    line-height: 1.5;
}

.login-brand .muni-name {
    font-size: 0.85rem;
    opacity: 0.65;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.login-features {
    position: relative;
    z-index: 1;
    margin-top: 3rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    width: 100%;
    max-width: 300px;
}

.login-feature-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgba(255,255,255,0.85);
    font-size: 0.875rem;
}

.login-feature-item i {
    color: var(--secondary-light);
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.login-right {
    width: 480px;
    max-width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: white;
}

.login-card {
    width: 100%;
    max-width: 400px;
}

.login-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.25rem;
}

.login-card p.sub {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 2rem;
}

/* ============================================================
   FISCALIZACION TABLE
   ============================================================ */
.fisc-table .estado-cell {
    min-width: 140px;
}

.fisc-table .obs-cell {
    min-width: 180px;
}

/* ============================================================
   STATUS INDICATORS
   ============================================================ */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 5px;
}

.status-dot.green  { background: var(--secondary); }
.status-dot.red    { background: #dc3545; }
.status-dot.yellow { background: var(--warning-color); }
.status-dot.gray   { background: #6c757d; }
.status-dot.blue   { background: #0dcaf0; }

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-primary { color: var(--primary) !important; }
.bg-primary   { background-color: var(--primary) !important; }

.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.section-divider {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 1.5rem 0;
}

/* Action buttons in tables */
.btn-action {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: all var(--transition);
}

.btn-action:hover { transform: scale(1.1); }

/* Search box */
.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    padding-left: 2.25rem;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    color: var(--primary-pale);
    display: block;
    margin-bottom: 1rem;
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fade-in-up {
    animation: fadeInUp 0.4s ease forwards;
}

.stat-card { animation: fadeInUp 0.4s ease forwards; }
.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.10s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.20s; }
.stat-card:nth-child(5) { animation-delay: 0.25s; }
.stat-card:nth-child(6) { animation-delay: 0.30s; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-wrapper {
        margin-left: 0;
    }

    .login-left {
        display: none;
    }

    .login-right {
        width: 100%;
    }
}

@media (max-width: 767.98px) {
    .main-content { padding: 1rem; }
    .page-header { flex-direction: column; align-items: stretch; }
    .stat-value { font-size: 1.5rem; }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    .sidebar, .top-navbar, .sidebar-overlay, .btn, .no-print { display: none !important; }
    .main-wrapper { margin-left: 0 !important; }
    .main-content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    body { background: white !important; }
}
