:root {
    --primary-color: #2563eb;
    --primary-dark: #003366; /* required active Inicio color */
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background-color: #f8fafc;
    --card-background: #ffffff;
    --text-color: #1e293b;
    --border-color: #e2e8f0;
    --purple-badge: #7c3aed;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

.page {
    display: none;
}

.page:not(.hidden) {
    display: block;
}

.hidden {
    display: none !important;
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: var(--card-background);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.login-header {
    display: flex;
    align-items: center;
    justify-content: center; /* keep centered inside card */
    gap: 12px;
    margin-bottom: 8px;
}

/* New: ensure login header stacks vertically and the logo is constrained */
.login-header {
    /* stack logo (and optional title) above subtitle */
    flex-direction: column;
    gap: 8px;
}

.login-logo {
    width: 200px; /* reasonable default size */
    max-width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    border-radius: 8px; /* subtle rounding if image has background */
}

@media (max-width: 400px) {
    .login-logo {
        width: 72px;
    }
}

.login-header h1 {
    text-align: left; /* align text next to logo */
    margin: 0;
    font-size: 20px;
    color: var(--primary-color);
}

.login-card h1 {
    text-align: center;
    margin-bottom: 10px;
    color: var(--primary-color);
}

.subtitle {
    text-align: center;
    color: var(--secondary-color);
    margin-bottom: 30px;
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
}

/* Utility helpers used by the generation/signing UI */
.flex-row { display: flex; gap: 8px; flex-wrap: wrap; }
.flex-1 { flex: 1; }
.min-w-120 { min-width: 120px; }
.min-w-140 { min-width: 140px; }
.min-w-160 { min-width: 160px; }
.min-w-200 { min-width: 200px; }
.min-w-220 { min-width: 220px; }
.min-w-240 { min-width: 240px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

.scroll-box { overflow: auto; max-height: 180px; border: 1px solid #e6e6e6; border-radius: 6px; padding: 6px; margin-bottom: 8px; }
.icon-small { width: 16px; height: 16px; vertical-align: middle; margin-right: 8px; }
.icon-white { color: white; }
.table-full { width: 100%; border-collapse: collapse; }
.small-th { text-align: left; padding: 6px; }
.th-action { width: 120px; }

/* Ensure .note has consistent top spacing */
.note { margin-top: 8px; }

.input-with-button {
    display: flex;
    gap: 8px;
}

.input-with-button .form-control { flex: 1; }

.input-with-button .btn-small { padding: 8px 10px; }

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: #1d4ed8;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #475569;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.error-message {
    color: var(--danger-color);
    margin-top: 15px;
    text-align: center;
    font-size: 14px;
}

/* Navbar */
.navbar {
    background-color: var(--primary-color);
    color: white;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.nav-brand {
    font-size: 20px;
    font-weight: 600;
}

.nav-brand .brand-text {
    margin-left: 6px;
    font-weight: 700;
    color: white;
    vertical-align: middle;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Constrain site logo in navbar */
.site-logo,
#site-logo {
    width: 120px;
    height: auto;
    display: block;
    object-fit: contain;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* Dashboard Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.dashboard-header h2 {
    color: var(--text-color);
}

.action-buttons {
    display: flex;
    gap: 12px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--secondary-color);
    transition: all 0.3s;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Table */
.table-container {
    background: var(--card-background);
    border-radius: 8px;
    overflow-x: auto;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background-color: var(--background-color);
}

th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-color);
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

tr:hover {
    background-color: var(--background-color);
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.status-available {
    background-color: #d1fae5;
    color: #065f46;
}

.status-assigned {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-maintenance {
    background-color: #fef3c7;
    color: #92400e;
}

.status-retired {
    background-color: #fee2e2;
    color: #991b1b;
}

/* Equipment Grid */
.equipment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.equipment-card {
    background: var(--card-background);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s, box-shadow 0.3s;
}

.equipment-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.equipment-card h3 {
    margin-bottom: 12px;
    color: var(--primary-color);
}

.equipment-card p {
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--secondary-color);
}

.equipment-card strong {
    color: var(--text-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card-background);
    padding: 32px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    top: 16px;
    right: 24px;
    font-size: 28px;
    font-weight: bold;
    color: var(--secondary-color);
    cursor: pointer;
}

.close:hover {
    color: var(--text-color);
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.form-actions button {
    flex: 1;
}

/* Layout: sidebar + main */
.layout {
    display: flex;
    align-items: stretch;
    gap: 24px;
}

/* Sidebar base styles */
.sidebar {
    width: 220px;
    background: var(--card-background);
    border-right: 1px solid var(--border-color);
    padding: 16px 12px;
    height: calc(100vh - 72px);
    overflow: auto;
    transition: width 0.25s ease, transform 0.25s ease;
    box-shadow: 0 0 0 rgba(0,0,0,0);
    position: relative;
}

.sidebar .sidebar-top {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.sidebar-logo-img {
    width: 100%;
    max-width: 160px;
    height: auto;
    object-fit: contain;
}

/* Collapsed state: show icons only */
.sidebar.collapsed {
    width: 72px;
}

.sidebar.collapsed .sidebar-text {
    display: none;
}

.sidebar.collapsed .sidebar-logo-img {
    max-width: 48px;
}

.sidebar .sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar .sidebar-nav li a {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 8px;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 6px;
}

.sidebar .sidebar-nav li a .sidebar-icon img.inventario-logo-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.sidebar .sidebar-nav li a:hover {
    background-color: var(--background-color);
}

/* Hamburger styling */
.hamburger {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
}

.hamburger:focus {
    outline: 2px solid rgba(255,255,255,0.2);
}

/* Mobile behavior: overlay sidebar */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 72px;
        bottom: 0;
        transform: translateX(-110%);
        z-index: 80;
        width: 260px;
        box-shadow: 0 6px 24px rgba(0,0,0,0.15);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .layout {
        margin-left: 0;
    }

    .site-logo { width: 96px; }
}

/* Sidebar layout */
.layout {
    display: flex;
    min-height: calc(100vh - 72px); /* account for navbar */
}

.sidebar {
    width: 260px;
    background: var(--card-background); /* white */
    border-right: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    flex-direction: column;

}

/* Sidebar navigation when using UL */
.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 20px 0 0 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-nav li a.sidebar-link {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 600;
}

.sidebar-nav li a.sidebar-link:hover {
    background: rgba(37,99,235,0.06);
    color: var(--primary-color);
}

/* Active 'Inicio' button: dark blue background #003366 and white text */
.sidebar-nav li a.sidebar-link.active {
    background: var(--primary-dark);
    color: white;
}

/* Sidebar icon + text spacing */
.sidebar-icon {
    display: inline-block;
    width: 28px;
    text-align: center;
    margin-right: 8px;
}

.sidebar-text {
    vertical-align: middle;
}

/* Global inline SVG icon sizing */
.icon-svg {
    width: 20px;
    height: 20px;
    display: inline-block;
    vertical-align: middle;
    color: var(--secondary-color);
}

.sidebar-top .icon-svg {
    width: 36px;
    height: 36px;
    color: var(--primary-color);
}

/* ensure svg strokes inherit currentColor */
.icon-svg [stroke] {
    stroke: currentColor;
}

/* Card tweaks for generation view */
.card {
    background: var(--card-background);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.card h4 { margin-top: 0; }

/* Profile */
.profile {
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.profile img {
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.2);
}

.profile-menu {
    position: absolute;
    right: 0;
    top: 48px;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 50;
    min-width: 160px;
}

/* Dashboard cards */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--card-background);
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.stat-card .card-title {
    color: var(--secondary-color);
    font-weight: 600;
    margin-bottom: 8px;
}

.card-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
}

/* Header welcome */
.header-welcome {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.welcome-title {
    font-size: 22px;
    color: var(--text-color);
    margin: 0;
}

.role-badge {
    display: inline-block;
    background: var(--purple-badge);
    color: white;
    padding: 6px 10px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 13px;
    width: max-content;
}

/* Hero Card */
.hero-card {
    background: linear-gradient(180deg, #0b5ed7, #1e40af); /* blue banner */
    color: white;
    padding: 20px 24px;
    border-radius: 15px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.hero-title {
    font-size: 18px;
    font-weight: 700;
}

.hero-cta {
    background: white;
    color: var(--primary-dark);
    padding: 10px 16px;
    border-radius: 10px;
    border: none;
    font-weight: 700;
}

.hero-cta:hover {
    opacity: 0.95;
}

/* KPI Cards row */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 18px;
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(16,24,40,0.06);
}

.kpi-icon {
    font-size: 18px;
    line-height: 1;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: white;
}

.icon-green { background: #10b981; }
.icon-yellow { background: #f59e0b; }
.icon-red { background: #ef4444; }
.icon-blue { background: #2563eb; }

/* KPI animation and visual polish */
.kpi-card .card-value {
    font-size: 20px;
    color: var(--text-color);
    transition: transform 0.25s ease, color 0.25s ease;
    display: inline-block;
    min-width: 36px;
    text-align: right;
}

.kpi-pulse {
    animation: kpiPulse 360ms cubic-bezier(.2,.9,.2,1);
}

@keyframes kpiPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* subtle color flash when increased */
.kpi-flash-up {
    animation: kpiFlashUp 480ms ease;
}

@keyframes kpiFlashUp {
    0% { background: rgba(37,99,235,0.06); }
    100% { background: transparent; }
}

.kpi-card .card-title {
    margin: 0;
    font-size: 13px;
    color: var(--secondary-color);
}

.kpi-card .card-value {
    font-size: 20px;
    color: var(--text-color);
    transition: transform 0.25s ease, color 0.25s ease;
    display: inline-block;
    min-width: 36px;
    text-align: right;
}

/* Activity list styles */
.activity-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.activity-title {
    font-size: 14px;
    color: var(--text-color);
}

.activity-meta {
    font-size: 12px;
    color: var(--secondary-color);
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: rgba(255,255,255,0.9);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Disabled state helper */
.is-loading {
    opacity: 0.7;
    pointer-events: none;
}

input[disabled], button[disabled], select[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Small note style */
.note {
    font-size: 13px;
    color: var(--secondary-color);
}

/* Sidebar logo image styling */
.sidebar-logo-img {
    width: 140px; /* small logo in sidebar */
    height: auto;
    object-fit: contain;
    display: block;
}

/* Sidebar top layout */
.sidebar-top {
    display: flex;
    align-items: flex-start; /* align to the left */
    flex-direction: column; /* stack logo above the title */
    gap: 8px;
    margin-bottom: 12px;
}

/* Ensure the .sidebar-title aligns vertically with the logo */
.sidebar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-color);
}

/* Hamburger (sidebar toggle) */
.hamburger {
    background: transparent;
    border: none;
    color: white;
    font-size: 20px;
    margin-right: 12px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
}

.hamburger:hover {
    background: rgba(255,255,255,0.08);
}

/* Sidebar collapsed state */
.sidebar.collapsed {
    width: 68px; /* narrow bar */
    padding: 12px 8px;
}

.sidebar.collapsed .sidebar-logo-img {
    width: 40px;
}

.sidebar.collapsed .sidebar-text {
    display: none; /* hide text labels when collapsed */
}

.sidebar.collapsed .sidebar-icon {
    margin-right: 0;
    width: 100%;
    text-align: center;
}

/* When collapsed, shrink nav icons */
.sidebar.collapsed .icon-svg {
    width: 22px;
    height: 22px;
}

/* Smooth transition for collapsing */
.sidebar,
.main-content {
    transition: width 200ms ease, margin-left 200ms ease, padding 200ms ease;
}

/* Adjust main content margin when sidebar collapsed */
.layout .main-content {
    flex: 1;
}

/* Ensure the login logo doesn't overflow the login card */
.login-logo {
    max-height: 120px; /* limit height so it doesn't fill the whole screen */
}

/* Constrain site logo smaller for navbar */
.site-logo,
#site-logo {
    width: 120px;
    height: auto;
    display: block;
    object-fit: contain;
}

/* Sidebar logo: keep compact for top-left */
.sidebar-logo-img {
    width: 140px;
    height: auto;
    object-fit: contain;
    display: block;
}

/* When viewport is small, the hamburger appears and sidebar overlays */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 72px; /* below navbar */
        height: calc(100vh - 72px);
        transform: translateX(-100%);
        z-index: 200;
        transition: transform 220ms ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.08);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* When overlaying, keep main content full width behind */
    .layout {
        position: relative;
    }
}

/* Ensure inventor icon small image in sidebar nav (inventario link) */
.inventario-logo-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    display: inline-block;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar { width: 200px; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 12px;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .action-buttons {
        width: 100%;
    }

    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        order: 2;
    }

    .main-content {
        order: 1;
    }

    .kpi-row {
        grid-template-columns: 1fr;
    }

    .profile-menu {
        right: 12px;
    }
}

/* Responsive: make column-based form rows stack on small screens */
@media (max-width: 600px) {
    .form-row {
        display: block !important;
    }
    .form-row .form-group {
        width: 100% !important;
        min-width: 0 !important;
        margin-bottom: 12px;
    }
    .tabs { overflow-x: auto; }
}

/* Small utility helpers for layout used in index.html */
.items-center { align-items: center; }
.justify-end { justify-content: flex-end; }
.text-secondary { color: var(--secondary-color); }
