:root {
    --primary-color: #003366;
    --primary-hover: #002244;
    --accent-color: #00fcdf;
    --bg-light: #f4f6f9;
    --text-color: #333333;
    --border-color: #cccccc;
    --sidebar-width: 250px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

[hidden] {
    display: none !important;
}

body {
    background-color: var(--bg-light);
    color: var(--text-color);
}

button, input, select {
    font: inherit;
}

code, pre {
    font-family: Consolas, 'Courier New', monospace;
    background: #eef2f6;
    border-radius: 4px;
    font-size: 0.82rem;
}

code { padding: 0.1rem 0.35rem; }
pre { padding: 0.75rem; overflow: auto; line-height: 1.6; margin: 0.5rem 0; }

.muted { color: #666; font-size: 0.85rem; }

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background: linear-gradient(135deg, #003366 0%, #001122 100%);
}

.login-container {
    background: #ffffff;
    padding: 2.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-header h2 { font-size: 1.2rem; color: var(--primary-color); }
.login-header h3 { font-size: 1rem; color: #555; margin-bottom: 0.5rem; }
.login-header p { font-size: 0.9rem; font-weight: bold; margin-bottom: 1.5rem; color: #777; }
.login-form { text-align: left; }

.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper input {
    width: 100%;
    padding-right: 2.5rem;
}

.btn-toggle-eye {
    position: absolute;
    right: 0.5rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
}

.btn-toggle-eye:hover { color: var(--primary-color); }
.btn-toggle-eye .eye-closed { display: none; }
.btn-toggle-eye.showing .eye-open { display: none; }
.btn-toggle-eye.showing .eye-closed { display: block; }

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

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: var(--primary-color);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sidebar-header {
    padding: 1.5rem 1rem;
    background-color: var(--primary-hover);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.sidebar-header-text {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.sidebar-collapse-btn {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar-collapse-btn:hover { background: rgba(255, 255, 255, 0.22); }
.sidebar-collapse-btn .icon-expand { display: none; }

.sidebar-menu {
    list-style: none;
    margin-top: 1rem;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    color: #ecf0f1;
    text-decoration: none;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.sidebar-menu li a:hover, .sidebar-menu li.active a {
    background-color: rgba(255, 255, 255, 0.15);
    border-left: 4px solid var(--accent-color);
}

.sidebar-icon {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar-label {
    flex: 1;
    min-width: 0;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.85rem;
}

.btn-logout {
    color: #ff6b6b;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.sidebar-backdrop { display: none; }

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    min-width: 0;
}

.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    width: 38px;
    height: 38px;
    cursor: pointer;
}

.menu-toggle:active { background: var(--primary-hover); }

.top-bar {
    background: #ffffff;
    padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.75rem, 2vw, 2rem);
    border-bottom: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: 1rem;
}

.top-bar-start {
    justify-self: start;
    display: flex;
    align-items: center;
}

.top-bar-title {
    justify-self: center;
    text-align: center;
    grid-column: 2;
}

.top-bar-title h2 {
    font-size: clamp(0.85rem, 1.4vw, 1.15rem);
    line-height: 1.25;
}

.top-bar-title p {
    margin-top: 0.15rem;
    color: #666;
    font-size: 0.9rem;
}

.top-bar-actions {
    justify-self: end;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    grid-column: 3;
}

.content-section {
    padding: clamp(0.5rem, 1.5vw, 1.5rem);
}

@media (min-width: 769px) {
    .sidebar {
        transition: width 0.25s ease, min-width 0.25s ease;
        overflow: hidden;
    }

    .top-bar .menu-toggle { display: none; }

    body.sidebar-collapsed { --sidebar-width: 68px; }

    body.sidebar-collapsed .sidebar-header {
        flex-direction: column;
        justify-content: center;
        padding: 0.75rem 0.35rem;
        gap: 0.35rem;
    }

    body.sidebar-collapsed .sidebar-header-text,
    body.sidebar-collapsed .sidebar-label,
    body.sidebar-collapsed .sidebar-footer-text {
        display: none;
    }

    body.sidebar-collapsed .sidebar-collapse-btn .icon-collapse { display: none; }
    body.sidebar-collapsed .sidebar-collapse-btn .icon-expand { display: block; }

    body.sidebar-collapsed .sidebar-menu li a {
        justify-content: center;
        padding: 0.9rem 0.4rem;
        border-left: none;
        gap: 0;
    }

    body.sidebar-collapsed .sidebar-menu li a:hover,
    body.sidebar-collapsed .sidebar-menu li.active a {
        border-left: none;
        background-color: rgba(255, 255, 255, 0.18);
    }

    body.sidebar-collapsed .sidebar-footer {
        padding: 0.75rem 0.35rem;
        text-align: center;
    }

    body.sidebar-collapsed .btn-logout {
        margin-top: 0;
        justify-content: center;
        width: 100%;
    }
}

/* Formularios y botones */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.3rem; font-size: 0.85rem; font-weight: bold; }

.form-group input, .form-group select,
.filters input, .filters select,
.detail-form input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: #fff;
    color: var(--text-color);
}

input:focus, select:focus {
    outline: 2px solid rgba(0, 252, 223, 0.55);
    border-color: var(--primary-color);
}

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.45; cursor: wait; }
.btn-primary { background: var(--primary-color); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #6c757d; color: white; }
.btn-secondary:hover:not(:disabled) { background: #5a6268; }
.btn-block { width: 100%; }

.alert {
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.88rem;
    line-height: 1.5;
}

.alert strong { display: block; margin-bottom: 0.2rem; }
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* Encabezado de sección */
.section-panel {
    margin-bottom: 1rem;
    padding: 0.7rem 0.9rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-color);
    border-radius: 6px;
}

.section-panel h1 {
    font-size: 1.05rem;
    color: var(--primary-color);
    margin-bottom: 0.1rem;
}

.section-panel p {
    font-size: 0.85rem;
    color: #666;
}

/* Indicadores */
.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stats article {
    background: #fff;
    border: 1px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 6px;
    padding: 0.9rem 1rem;
}

.stats span { display: block; font-size: 0.82rem; font-weight: 600; color: #555; }
.stats strong { display: block; font-size: 1.9rem; color: var(--primary-color); margin: 0.3rem 0 0.15rem; }
.stats small { font-size: 0.75rem; color: #777; }
.stats .stat-ok { border-top-color: #28a745; }
.stats .stat-ok strong { color: #1e7e34; }
.stats .stat-muted { border-top-color: #6c757d; }
.stats .stat-muted strong { color: #5a6268; }
.stats .stat-warn { border-top-color: #e0a800; }
.stats .stat-warn strong { color: #b07d00; }

/* Tablas */
.results-panel {
    padding: 0.7rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 1rem;
}

.results-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
}

.results-meta h3 { font-size: 1rem; color: var(--primary-color); }

.count {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.75rem;
    vertical-align: middle;
}

.filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filters input { width: 240px; }
.filters select { width: auto; font-size: 0.85rem; }

.table-wrap {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th,
.data-table td {
    border: 1px solid var(--border-color);
    padding: 0.55rem 0.6rem;
    text-align: left;
    vertical-align: top;
}

.data-table td {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table thead th {
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
}

.data-table tbody tr:nth-child(even) { background: #f3f6f9; }
.data-table tbody tr:hover { background: rgba(0, 51, 102, 0.06); }
.data-table td small { display: block; margin-top: 0.2rem; font-size: 0.75rem; color: #777; }

.device-link {
    border: none;
    background: none;
    padding: 0;
    color: var(--primary-color);
    font-weight: 600;
    cursor: pointer;
}

.device-link:hover { text-decoration: underline; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 10px;
    background: #d4edda;
    color: #155724;
    font-size: 0.75rem;
    font-weight: 600;
}

.data-table td.age { font-weight: 600; }
.data-table td.age small { color: inherit; font-weight: 400; opacity: 0.85; }
.data-table td.age-1 { background: #d4edda; color: #155724; }
.data-table td.age-2 { background: #e6f4c7; color: #4b6b0f; }
.data-table td.age-3 { background: #fff3cd; color: #856404; }
.data-table td.age-4 { background: #ffe0c2; color: #8a4b08; }
.data-table td.age-5 { background: #f8d7da; color: #721c24; }

.badge.stale { background: #e2e3e5; color: #383d41; }
.data-table td small.alert-tag { color: #b07d00; font-weight: 600; }

.table-footer {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: #777;
}

.empty {
    text-align: center;
    padding: 2.5rem 1rem;
}

.empty h3 { color: var(--primary-color); margin-bottom: 0.5rem; }
.empty p { color: #666; margin-bottom: 1rem; font-size: 0.9rem; }

.section-title {
    font-size: 1rem;
    color: var(--primary-color);
    margin: 1.2rem 0 0.6rem;
}

/* Token del pendrive */
.token-panel {
    padding: 0.7rem 1rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.88rem;
}

.token-panel summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--primary-color);
}

.token-panel[open] summary { margin-bottom: 0.6rem; }
.token-panel p { margin-bottom: 0.5rem; }
.token-panel h4 { color: var(--primary-color); margin: 1rem 0 0.4rem; }
.token-panel code.token { overflow-wrap: anywhere; user-select: all; }
.token-panel .btn { margin-bottom: 0.6rem; }

/* Ficha del equipo */
dialog.modal-content {
    margin: auto;
    border: none;
    padding: 2rem;
    border-radius: 8px;
    width: min(820px, 94vw);
    max-height: 90vh;
    overflow-y: auto;
    color: var(--text-color);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

dialog.modal-content::backdrop { background: rgba(0,0,0,0.5); }

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--primary-color);
}

.dialog-kicker { font-size: 0.72rem; font-weight: 700; color: #777; letter-spacing: 0.05em; }
.dialog-header h3 { font-size: 1.3rem; color: var(--primary-color); }

.modal-close {
    border: none;
    background: transparent;
    font-size: 1.6rem;
    line-height: 1;
    color: #888;
    cursor: pointer;
}

.modal-close:hover { color: #c0392b; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

.detail-cell {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: #f8fafc;
    font-size: 0.88rem;
    overflow-wrap: anywhere;
}

.detail-cell small {
    display: block;
    margin-bottom: 0.2rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

#detail-content > p { font-size: 0.88rem; margin-bottom: 0.35rem; }
#detail-content > p small { color: #777; }

.detail-form {
    display: grid;
    gap: 0.75rem;
    margin-top: 1.2rem;
    padding: 0.9rem;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-color);
    border-radius: 6px;
}

.detail-form label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.85rem;
    font-weight: bold;
}

.detail-form .btn { justify-self: start; }
#annotation-status { font-size: 0.85rem; color: #555; }

.history-entry {
    padding: 0.6rem 0;
    border-bottom: 1px solid #e5e8ec;
    font-size: 0.85rem;
}

.history-entry p { margin-top: 0.2rem; overflow-wrap: anywhere; }

/* Pantallas medianas */
@media (max-width: 1200px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .results-meta { align-items: flex-start; flex-direction: column; }
}

/* Móvil */
@media (max-width: 768px) {
    .app-shell {
        flex-direction: column;
        height: 100dvh;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 270px;
        min-width: 0;
        z-index: 1100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.45);
    }

    .sidebar-header { padding: 0.9rem 1rem; }
    .sidebar-header h3 { font-size: 1rem; white-space: nowrap; }
    .sidebar-header small { display: block; font-size: 0.75rem; }

    .sidebar-menu li a {
        padding: 0.9rem 1.25rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 1050;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-backdrop.show {
        opacity: 1;
        pointer-events: auto;
    }

    .main-content { min-height: 0; }

    .top-bar {
        grid-template-columns: auto 1fr;
        gap: 0.5rem;
        padding: 0.6rem 0.75rem;
    }

    .top-bar-start { grid-column: 1; }

    .top-bar-title {
        grid-column: 2;
        justify-self: stretch;
        text-align: left;
    }

    .top-bar-title h2 { font-size: 0.9rem; }
    .top-bar-title p { font-size: 0.72rem; }

    .top-bar-actions {
        grid-column: 1 / -1;
        justify-self: stretch;
        justify-content: flex-start;
    }

    .content-section { padding: 0.75rem; }
    .stats { gap: 0.5rem; }
    .stats strong { font-size: 1.5rem; }
    .filters, .filters input { width: 100%; }
    .filters select { flex: 1; }
    .detail-grid { grid-template-columns: 1fr; }
    dialog.modal-content { padding: 1.2rem; }
    .login-container { padding: 1.75rem; }
}
