@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

:root {
    /* Color Palette - Institutional */
    --primary: #70502a;
    --primary-hover: #5a4022;
    --secondary: #162c31;
    --accent: #b48c4e;
    --bg-gradient-start: #162c31;
    --bg-gradient-end: #0d1a1d;
    --surface: rgba(255, 255, 255, 0.95);
    --surface-border: rgba(180, 140, 78, 0.2);
    --text-main: #383737;
    --text-muted: #606060;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    
    /* Typography */
    --font-family: 'Montserrat', sans-serif;
    
    /* Effects */
    --shadow-soft: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --transition: all 0.3s ease;
    --header-height: 72px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

select, input, textarea {
    font-family: var(--font-family);
    max-width: 100%;
}

select {
    min-width: 0;
}

body {
    font-family: var(--font-family);
    color: var(--text-main);
    background-color: #f8fafc;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==================
   LOGIN PAGE
   ================== */
.login-body {
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    justify-content: center;
    align-items: center;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}

.glass-panel {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--surface-border);
    border-radius: 1.5rem;
    padding: 2.5rem;
    box-shadow: var(--shadow-xl);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-circle {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, #fdfcfb 0%, #f5f5f5 100%);
    color: var(--primary);
    border: 1px solid var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    box-shadow: var(--shadow-soft);
}

.login-header svg {
    width: 36px;
    height: 36px;
    position: relative;
    top: 2px; /* Fix for visual alignment */
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.error-message {
    background: var(--danger-bg);
    color: var(--danger);
    padding: 0.875rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
}

.input-wrapper input {
    width: 100%;
    padding: 0.875rem 1rem 0.875rem 2.75rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 0.75rem;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-main);
    transition: var(--transition);
    background: white;
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(112, 80, 42, 0.1);
}

.input-wrapper input::placeholder {
    color: #94a3b8;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(112, 80, 42, 0.2);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-add-square {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    background: var(--secondary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-soft);
}

.btn-add-square:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(22, 44, 49, 0.3);
}

.btn-secondary {
    background: #606060;
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 0.75rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-secondary:hover {
    background: #4a4a4a;
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
    color: white;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    margin-bottom: 2.5rem;
}

@media (max-width: 480px) {
    .form-actions {
        flex-direction: column-reverse;
        gap: 0.75rem;
    }
    
    .form-actions button, .form-actions a {
        width: 100%;
        text-align: center;
    }
}

.login-footer {
    text-align: center;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #f1f5f9;
}

.login-footer p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ==================
   DASHBOARD
   ================== */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--secondary);
    border-right: none;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    background: transparent;
    width: 100%;
}

.sidebar-logo {
    height: var(--header-height);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
}

.sidebar-logo img {
    max-width: 100%;
    max-height: 44px;
    height: auto;
    display: block;
    filter: brightness(0) invert(1); /* Logo en blanco para fondo oscuro */
}

.sidebar-title-group {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.sidebar-title {
    font-size: 0.65rem;
    font-weight: 400;
    color: white;
    line-height: 1.4;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-subtitle {
    font-size: 0.6rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.4;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.01em;
}

.sidebar-nav {
    flex: 1;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    border-radius: 0.5rem;
    font-weight: 400;
    transition: var(--transition);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.95); /* Casi blanco degradado del fondo */
    color: var(--secondary);
    font-weight: 500;
    box-shadow: inset 4px 0 0 var(--accent), 0 4px 12px rgba(0,0,0,0.15);
    border-left: none; /* Usamos inset shadow para un look más limpio */
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
}

.user-details h4 {
    font-size: 0.9rem;
    margin-bottom: 0.1rem;
    color: white;
}

.user-details span {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    text-transform: capitalize;
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.6rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    color: white;
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
}

.btn-logout:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.btn-logout:hover {
    background: var(--danger);
    color: white;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Previene expansión por contenido */
    max-width: 100%;
}

.content-header {
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
}

.content-header h2 {
    font-size: 1.25rem;
    font-weight: 500;
}

.content-body {
    padding: 2rem;
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    max-width: 100%;
}

.welcome-card {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: var(--shadow-soft);
    border: 1px solid #e2e8f0;
    margin-bottom: 2rem;
}

.welcome-card h3 {
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.welcome-card p {
    color: var(--text-muted);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    background: white;
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-soft);
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.blue { background: #fdf5e1; color: var(--primary); }
.stat-icon.green { background: #f0fdf4; color: #16a34a; }
.stat-icon.purple { background: #faf5ff; color: #9333ea; }

.stat-info h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-bottom: 0.25rem;
}

.stat-info p {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
}

/* ==================
   MOBILE RESPONSIVENESS
   ================== */
.menu-toggle {
    display: none;
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
        transition: var(--transition);
    }

    .sidebar.active {
        left: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        width: 100%;
    }

    .content-header {
        padding: 0 1rem;
    }

    .content-body {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .welcome-card {
        padding: 1.5rem;
    }

    .form-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    /* Tablas responsivas */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-top: 1rem;
        background: white;
        border-radius: 0.5rem;
        border: 1px solid var(--surface-border);
    }
}

/* ==================
   CUSTOM SELECT (Multilínea)
   ================== */
.custom-select-wrapper {
    position: relative;
    user-select: none;
    width: 100%;
    min-width: 0;
}

.custom-select {
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1.5px solid #e2e8f0;
    border-radius: 0.75rem;
    background: white;
    cursor: pointer;
    transition: var(--transition);
}

.custom-select:hover {
    border-color: var(--accent);
}

.custom-select.open {
    border-color: var(--primary);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    z-index: 1001;
}

.custom-select-trigger {
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    font-size: 0.95rem;
    color: var(--text-main);
    display: block;
    white-space: normal;
    word-wrap: break-word;
    min-height: 46px;
    line-height: 1.4;
}

.custom-select-trigger:after {
    content: "";
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--text-muted);
    transition: var(--transition);
}

.custom-select.open .custom-select-trigger:after {
    transform: translateY(-50%) rotate(180deg);
}

.custom-select-options {
    position: absolute;
    top: 100%;
    left: -1.5px;
    right: -1.5px;
    background: white;
    border: 1.5px solid var(--primary);
    border-top: none;
    border-bottom-left-radius: 0.75rem;
    border-bottom-right-radius: 0.75rem;
    box-shadow: var(--shadow-xl);
    display: none;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
}

.custom-select.open .custom-select-options {
    display: block;
}

.custom-option {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    color: var(--text-main);
    transition: background 0.2s;
    border-bottom: 1px solid #f1f5f9;
    white-space: normal;
    word-wrap: break-word;
    line-height: 1.4;
}

.custom-option:last-child {
    border-bottom: none;
}

.custom-option:hover {
    background: #fdf5e1;
    color: var(--primary);
}

.custom-option.selected {
    background: var(--primary);
    color: white;
}

/* Ocultar select original pero mantenerlo funcional para el form */
.hidden-select {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}
