:root {
    --azul: #2563eb;
    --azul-oscuro: #1e40af;
    --gris-bg: #f3f4f6;
    --gris-borde: #d1d5db;
    --texto: #1f2937;
    --verde: #16a34a;
    --amarillo: #d97706;
    --rojo: #dc2626;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--gris-bg);
    color: var(--texto);
    margin: 0;
}

.topbar {
    background: var(--azul-oscuro);
    color: white;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.topbar-izquierda { display: flex; align-items: center; gap: 12px; }
.topbar-hamburguesa {
    display: none; background: rgba(255,255,255,0.15); color: white; border: none;
    width: 36px; height: 36px; border-radius: 6px; cursor: pointer; font-size: 1.1em;
}
.topbar-brand {
    font-weight: bold;
    font-size: 1.15em;
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    text-decoration: none;
}
.topbar-logo { height: 34px; width: auto; border-radius: 4px; background: white; padding: 2px; }
.topbar-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.topbar-nav a { color: white; text-decoration: none; font-size: 0.95em; display: inline-flex; align-items: center; gap: 5px; }
.topbar-nav a:hover { text-decoration: underline; }
.topbar-user { opacity: 0.9; font-size: 0.9em; display: inline-flex; align-items: center; gap: 5px; }
.topbar-user em { font-style: normal; opacity: 0.75; }
.topbar-logout { background: var(--rojo); padding: 5px 12px; border-radius: 6px; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }

/* --- Layout con sidebar (admin) --- */
.app-shell { display: flex; align-items: flex-start; }
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: white;
    border-right: 2px solid var(--gris-borde);
    min-height: calc(100vh - 61px);
    padding: 18px 0;
}
.sidebar-nav { display: flex; flex-direction: column; }
.sidebar-titulo {
    text-transform: uppercase; font-size: 0.72em; font-weight: 700; letter-spacing: 0.06em;
    color: #9ca3af; margin: 16px 20px 6px;
}
.sidebar-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px; color: var(--texto); text-decoration: none; font-size: 0.95em;
    border-left: 3px solid transparent;
}
.sidebar-nav a i { width: 20px; text-align: center; color: var(--azul); font-size: 1.05em; }
.sidebar-nav a:hover { background: #f3f4f6; border-left-color: var(--azul); }
.container-con-sidebar { flex: 1; min-width: 0; }

@media (max-width: 900px) {
    .topbar-hamburguesa { display: inline-flex; align-items: center; justify-content: center; }
    .app-shell { position: relative; }
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; z-index: 40;
        transform: translateX(-100%); transition: transform 0.2s ease;
        box-shadow: 4px 0 16px rgba(0,0,0,0.15);
        overflow-y: auto; -webkit-overflow-scrolling: touch;
    }
    .sidebar.sidebar-abierto { transform: translateX(0); }
}

html.tema-oscuro .sidebar { background: #1f2937; border-color: #374151; }
html.tema-oscuro .sidebar-nav a { color: #e5e7eb; }
html.tema-oscuro .sidebar-nav a:hover { background: #273244; }
html.alto-contraste .sidebar { border-right-width: 3px; }

.footer { text-align: center; padding: 16px; color: #6b7280; font-size: 0.85em; }

h1 { margin-top: 0; }
h2 { margin-top: 32px; }

.form-card {
    background: white;
    border: 2px solid var(--gris-borde);
    border-radius: 10px;
    padding: 20px;
    margin: 16px 0;
    max-width: 600px;
    box-shadow: 0 2px 0 rgba(0,0,0,0.05), 0 4px 12px rgba(0,0,0,0.06);
}

label { display: block; margin: 10px 0 4px; font-weight: 600; font-size: 0.9em; }
input, select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 2px solid var(--gris-borde);
    border-radius: 6px;
    font-size: 1em;
    font-family: inherit;
    background: white;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--azul);
    box-shadow: 0 0 0 3px rgba(var(--azul-rgb), 0.15);
}
button, .boton, .boton-secundario {
    display: inline-block;
    margin-top: 14px;
    background: var(--azul);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95em;
    text-decoration: none;
}
button:hover, .boton:hover { background: var(--azul-oscuro); }
.boton-secundario { background: var(--amarillo); }

/* --- Hero / banner de bienvenida --- */
.hero {
    display: flex;
    align-items: center;
    gap: 20px;
    background: linear-gradient(135deg, var(--azul), var(--azul-oscuro));
    color: white;
    border-radius: 12px;
    padding: 24px 28px;
    margin-bottom: 24px;
    box-shadow: 0 4px 14px rgba(var(--azul-rgb), 0.35);
}
.hero h1 { margin: 0; color: white; }
.hero-sub { margin: 4px 0 0; opacity: 0.9; }
.hero-logo { height: 60px; width: 60px; object-fit: contain; background: white; border-radius: 10px; padding: 6px; }
.hero-icono {
    height: 60px; width: 60px; border-radius: 10px; background: rgba(255,255,255,0.15);
    display: flex; align-items: center; justify-content: center; font-size: 1.8em;
}
.badge-rol { background: rgba(255,255,255,0.25); }

/* --- Tarjetas de estadísticas --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin: 14px 0 22px; }
.stat-card {
    background: white;
    border-radius: 14px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 160px;
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 2px 0 rgba(0,0,0,0.03), 0 10px 24px rgba(0,0,0,0.08);
    transition: transform 0.2s cubic-bezier(.2,.8,.2,1), box-shadow 0.2s ease;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: 0 4px 0 rgba(0,0,0,0.04), 0 16px 30px rgba(0,0,0,0.14); }
.stat-card i {
    font-size: 1.2em; width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(107,114,128,0.12); color: #4b5563;
}
.stat-card div { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.stat-card strong { font-size: 1.5em; }
.stat-card span { font-size: 0.8em; color: #6b7280; font-weight: 600; white-space: normal; }
/* Cada variante colorea solo el círculo del ícono y un acento superior — nunca el fondo completo,
   para que el texto siempre quede oscuro sobre blanco y se lea bien. */
.stat-card.badge-nuevo, .stat-card.resumen-total { background: white; border-top: 3px solid var(--azul); }
.stat-card.badge-nuevo i { background: rgba(107,114,128,0.14); color: #4b5563; }
.stat-card.resumen-total i { background: rgba(var(--azul-rgb), 0.14); color: var(--azul); }
.stat-card.badge-asignado { background: white; border-top: 3px solid var(--azul); }
.stat-card.badge-asignado i { background: rgba(var(--azul-rgb), 0.14); color: var(--azul); }
.stat-card.badge-proceso { background: white; border-top: 3px solid var(--amarillo); }
.stat-card.badge-proceso i { background: rgba(217,119,6,0.14); color: var(--amarillo); }
.stat-card.badge-resuelto { background: white; border-top: 3px solid var(--verde); }
.stat-card.badge-resuelto i { background: rgba(22,163,74,0.14); color: var(--verde); }
.stat-card.badge-cerrado { background: white; border-top: 3px solid #374151; }
.stat-card.badge-cerrado i { background: rgba(55,65,81,0.14); color: #374151; }
.stat-card.badge-reabierto { background: white; border-top: 3px solid var(--rojo); }
.stat-card.badge-reabierto i { background: rgba(220,38,38,0.14); color: var(--rojo); }

.alert {
    background: #dbeafe;
    border-left: 4px solid var(--azul);
    padding: 12px 16px;
    border-radius: 4px;
    margin: 12px 0;
}
.alert-error { background: #fee2e2; border-left-color: var(--rojo); }

.tabla { width: 100%; border-collapse: separate; border-spacing: 0; background: white; margin-top: 12px; border: 2px solid var(--gris-borde); border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.tabla th, .tabla td { padding: 10px 12px; border-bottom: 2px solid var(--gris-borde); text-align: left; font-size: 0.92em; }
.tabla th { background: #e5e7eb; border-bottom: 2px solid #9ca3af; font-weight: 700; }
.tabla tr:last-child td { border-bottom: none; }
.tabla tbody tr:hover { background: #f9fafb; }
.fila-pendiente { background: #fef9c3; }
.fila-demorada { background: #fee2e2; }

.cards-grid { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0; }
.card-accion {
    background: white; border: 2px solid var(--gris-borde); border-radius: 10px;
    padding: 18px 20px; text-decoration: none; color: var(--texto); font-weight: 600;
    flex: 1 1 200px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 2px 0 rgba(0,0,0,0.04), 0 3px 8px rgba(0,0,0,0.06);
    transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
}
.card-accion:hover { border-color: var(--azul); transform: translateY(-2px); box-shadow: 0 4px 0 rgba(0,0,0,0.05), 0 8px 16px rgba(0,0,0,0.1); }
.card-icono { font-size: 1.5em; color: var(--azul); }

.badges-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.badge { padding: 4px 10px; border-radius: 12px; font-size: 0.85em; color: white; }
.badge-nuevo { background: #6b7280; }
.badge-asignado { background: var(--azul); }
.badge-proceso { background: var(--amarillo); }
.badge-resuelto { background: var(--verde); }
.badge-cerrado { background: #374151; }
.badge-reabierto { background: var(--rojo); }
.badge-alta { background: var(--rojo); }
.badge-media { background: var(--amarillo); }
.badge-baja { background: var(--verde); }

.nota { color: #6b7280; font-size: 0.9em; }
.paginacion { display: flex; align-items: center; justify-content: center; gap: 20px; margin: 18px 0; }
.paginacion a, .paginacion-deshabilitado { font-size: 0.9em; }
.paginacion-deshabilitado { color: #9ca3af; }
.paginacion-info { color: #6b7280; font-size: 0.85em; }

/* --- Bloques de gráficas (reportes y dashboard) --- */
.reporte-bloque { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; margin: 12px 0 20px; }
.grafica-caja {
    flex: 1 1 320px; max-width: 420px; background: white; border: 1px solid rgba(0,0,0,0.06); border-radius: 14px;
    padding: 18px; box-shadow: 0 2px 0 rgba(0,0,0,0.03), 0 10px 24px rgba(0,0,0,0.08);
    transition: transform 0.2s cubic-bezier(.2,.8,.2,1), box-shadow 0.2s ease;
}
.grafica-caja:hover { transform: translateY(-4px); box-shadow: 0 4px 0 rgba(0,0,0,0.04), 0 16px 30px rgba(0,0,0,0.14); }
.grafica-pequena { max-width: 260px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.filtros { display: flex; gap: 10px; margin-bottom: 10px; }
.especialidades-check label { display: inline-block; font-weight: normal; margin-right: 8px; font-size: 0.85em; }
.especialidades-check input { width: auto; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form select { width: auto; }

.detalle-ticket { background: white; border: 2px solid var(--gris-borde); border-radius: 10px; padding: 18px 22px; max-width: 700px; box-shadow: 0 2px 0 rgba(0,0,0,0.04), 0 3px 10px rgba(0,0,0,0.06); }
.detalle-ticket p { border-bottom: 1px solid #f0f1f3; padding-bottom: 8px; margin: 8px 0; }
.detalle-ticket p:last-child { border-bottom: none; }
.historial { list-style: none; padding: 0; }
.historial li { background: white; border: 2px solid var(--gris-borde); border-left: 5px solid var(--azul); border-radius: 6px; padding: 10px 14px; margin-bottom: 8px; font-size: 0.9em; box-shadow: 0 2px 6px rgba(0,0,0,0.05); }
.galeria { display: flex; flex-wrap: wrap; gap: 10px; }
.miniatura { width: 140px; height: 140px; object-fit: cover; border-radius: 6px; border: 1px solid var(--gris-borde); }
.miniatura-inventario { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--gris-borde); display: block; }
.miniatura-vacia { display: flex; align-items: center; justify-content: center; color: #d1d5db; background: #f9fafb; font-size: 1.1em; }

.etiqueta-qr { text-align: center; border: 1px dashed #999; padding: 16px; width: 220px; background: white; border-radius: 8px; }
.etiqueta-folio { font-weight: bold; margin: 8px 0 2px; }
.etiqueta-detalle { font-size: 0.85em; color: #6b7280; margin: 0; }

.comentario { background: white; border: 2px solid var(--gris-borde); border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; }
.comentario-cabecera { margin-bottom: 4px; }
.comentario-texto { white-space: pre-line; }
.estrellas { display: flex; gap: 14px; margin: 8px 0; }
.estrellas label { font-weight: normal; display: flex; align-items: center; gap: 4px; }
html.tema-oscuro .comentario { background: #273244; border-color: #374151; }

.logo-preview { margin: 6px 0 12px; }
.logo-preview img { max-height: 80px; max-width: 200px; background: #f9fafb; border: 1px solid var(--gris-borde); border-radius: 6px; padding: 6px; }
input[type="color"] { width: 70px; height: 38px; padding: 2px; cursor: pointer; }

@media (max-width: 700px) {
    .grid-2 { grid-template-columns: 1fr; }
    .topbar-nav { gap: 8px; }
    .container { padding: 16px 12px 60px; }
    .hero { flex-direction: column; text-align: center; padding: 20px; }
    .hero h1 { font-size: 1.3em; }
    .detalle-ticket { padding: 14px 16px; }
    .tabla { font-size: 0.85em; }
    .tabla th, .tabla td { padding: 7px 8px; }
    button, .boton, .boton-secundario { width: 100%; text-align: center; }
    .cards-grid { flex-direction: column; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .card-accion { flex: 1 1 auto; }
    .reporte-bloque { flex-direction: column; }
    .grafica-caja, .tabla-chica { max-width: 100%; }
    .kanban { flex-direction: column; }
    .kanban-columna { min-width: 0; }
}

@media print {
    .topbar, .footer, button, a.boton, a.boton-secundario { display: none !important; }
    body { background: white; }
    .container { max-width: 100%; }
    .form-card, .detalle-ticket, .tabla, .stat-card, .card-accion { box-shadow: none !important; }
}

/* --- Modo oscuro --- */
.topbar-tema {
    background: rgba(255,255,255,0.15);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0;
    padding: 0;
}
.topbar-tema:hover { background: rgba(255,255,255,0.3); }

html.tema-oscuro body { background: #111827; color: #e5e7eb; }
html.tema-oscuro .form-card,
html.tema-oscuro .tabla,
html.tema-oscuro .card-accion,
html.tema-oscuro .stat-card,
html.tema-oscuro .detalle-ticket,
html.tema-oscuro .historial li,
html.tema-oscuro .grafica-caja,
html.tema-oscuro .etiqueta-qr {
    background: #1f2937;
    color: #e5e7eb;
    border-color: #374151;
}
html.tema-oscuro .tabla th { background: #374151; color: #e5e7eb; border-color: #4b5563; }
html.tema-oscuro .tabla tbody tr:hover { background: #273244; }
html.tema-oscuro input, html.tema-oscuro select, html.tema-oscuro textarea {
    background: #111827; color: #e5e7eb; border-color: #374151;
}
html.tema-oscuro .nota { color: #9ca3af; }
html.tema-oscuro .card-accion { color: #e5e7eb; }
html.tema-oscuro .logo-preview img, html.tema-oscuro .topbar-logo { background: #e5e7eb; }

/* --- Accesibilidad: tamaño de texto --- */
html.texto-grande { font-size: 112%; }
html.texto-extra-grande { font-size: 128%; }

/* --- Accesibilidad: alto contraste --- */
html.alto-contraste { --azul: #0044cc; --azul-oscuro: #002a80; --gris-borde: #000; --texto: #000; }
html.alto-contraste body { background: #fff; }
html.alto-contraste .form-card, html.alto-contraste .tabla, html.alto-contraste .card-accion,
html.alto-contraste .stat-card, html.alto-contraste .detalle-ticket, html.alto-contraste .historial li {
    border-width: 3px; box-shadow: none;
}
html.alto-contraste a { text-decoration: underline; }
