:root {
    --bg: #f3f4f6;
    --card: #ffffff;
    --primary: #0f9fa8;
    --primary-dark: #0b7d84;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --danger: #dc2626;
    --success-bg: #dcfce7;
    --success-text: #166534;
}

body.dark {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: var(--bg);
    font-family: 'Inter', sans-serif;
    color: var(--text);
    min-height: 100vh;
}

/* Fondo: imagen tenue; paneles opacos evitan que se mezcle con iconos */
body.app-page,
body.login-page {
    background-color: #eef2f5;
}

a { color: inherit; text-decoration: none; }

.header {
    height: 70px;
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
    position: sticky;
    top: 0;
    z-index: 100;
}

body.dark .header {
    background: rgba(30, 41, 59, 0.94);
}

.logo {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.search-box input {
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    width: 260px;
}

.user-badge {
    font-size: 14px;
    color: var(--muted);
}

.role-badge {
    background: #fef3c7;
    color: #92400e;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
}

.btn-logout {
    background: var(--danger);
    color: white;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
}

.layout {
    display: flex;
    min-height: calc(100vh - 70px);
}

.sidebar {
    width: 260px;
    background: rgba(255, 255, 255, 0.98);
    border-right: 1px solid var(--border);
    padding: 24px 0;
    flex-shrink: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.06);
}

body.dark .sidebar {
    background: rgba(30, 41, 59, 0.98);
}

/* Categorías desplegables (HTML details/summary) */
.sidebar-details {
    margin: 8px 0 4px;
    border: none;
}

.sidebar-details-summary {
    list-style: none;
    cursor: pointer;
    padding: 12px 20px;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-details-summary::-webkit-details-marker {
    display: none;
}

.sidebar-details-summary::after {
    content: "▼";
    font-size: 10px;
    transition: transform 0.2s;
}

.sidebar-details[open] .sidebar-details-summary::after {
    content: "▲";
}

.sidebar-details-summary:hover {
    color: var(--primary);
    background: rgba(15, 159, 168, 0.06);
}

.sidebar-details-body {
    overflow: hidden;
}

.sidebar-empty {
    display: block;
    padding: 8px 20px 12px;
    font-size: 13px;
    color: var(--muted);
}

.sidebar-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 20px;
    margin: 16px 0 8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: var(--muted);
    transition: 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-item:hover,
.sidebar-item.active {
    background: rgba(15, 159, 168, 0.08);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.main {
    flex: 1;
    padding: 28px 32px 32px;
    overflow: visible;
    background: rgba(255, 255, 255, 0.92);
    margin: 12px 12px 12px 0;
    border-radius: 20px;
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.08);
}

body.dark .main {
    background: rgba(30, 41, 59, 0.92);
}

.page-title {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.page-subtitle {
    color: var(--muted);
    margin-bottom: 28px;
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 36px;
}

.category-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 22px;
    transition: 0.2s;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

body.dark .category-card {
    background: #1e293b;
}

.category-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(15, 159, 168, 0.12);
}

.category-icon { font-size: 28px; margin-bottom: 10px; }

.category-name {
    font-weight: 700;
    margin-bottom: 6px;
}

.category-count {
    font-size: 13px;
    color: var(--muted);
}

.doc-list { display: flex; flex-direction: column; gap: 12px; }

.doc-item {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.05);
}

body.dark .doc-item {
    background: #1e293b;
}

.doc-meta {
    font-size: 13px;
    color: var(--muted);
    margin-top: 4px;
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-block;
    font-size: 14px;
}

.btn:hover { background: var(--primary-dark); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.alert {
    padding: 14px 18px;
    border-radius: 14px;
    margin-bottom: 20px;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
}

.card-box {
    background: #ffffff;
    border-radius: 24px;
    padding: 32px;
    border: 1px solid var(--border);
    max-width: 720px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 5;
    overflow: visible;
}

body.dark .card-box {
    background: #1e293b;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

input[type="text"],
input[type="search"],
input[type="password"],
input[type="file"],
input[type="email"],
textarea {
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: #1f2937;
    font-size: 15px;
}

/* Select genérico (usuarios, etc.) */
select:not(.select-category) {
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: #1f2937;
    font-size: 15px;
}

body.dark input[type="text"],
body.dark input[type="search"],
body.dark input[type="password"],
body.dark input[type="file"] {
    background: #1e293b;
    color: #f1f5f9;
}

.form-group {
    margin-bottom: 20px;
    position: relative;
    z-index: 6;
    overflow: visible;
}

.form-hint {
    margin-top: 8px;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.4;
}

/* Categoría en subir: apariencia nativa del sistema (la flecha debe abrir el menú) */
select.select-category {
    all: revert;
    box-sizing: border-box;
    display: block;
    width: 100%;
    max-width: 100%;
    min-height: 2.75rem;
    margin-top: 4px;
    padding: 0.4rem 0.6rem;
    font-family: inherit;
    font-size: 15px;
    line-height: normal;
    cursor: pointer;
    pointer-events: auto;
    position: relative;
    z-index: 20;
    color-scheme: light;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.empty-state {
    text-align: center;
    padding: 48px;
    color: var(--muted);
}

.filter-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.filter-bar a {
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    font-size: 14px;
}

.filter-bar a.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Botón eliminar dentro de formularios inline */
form button.btn {
    font-family: inherit;
    border: none;
    cursor: pointer;
}

@media (max-width: 900px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
    .search-box input { width: 160px; }
}
