/* ============================================================
   NEXUS SYSTEM - Hoja de estilos principal
   Paleta: blanco, negro y grises. Diseño administrativo simple.
   ============================================================ */

:root {
    --bg: #f4f4f4;
    --surface: #ffffff;
    --surface-2: #fafafa;
    --border: #e3e3e3;
    --border-strong: #cdcdcd;
    --text: #111111;
    --text-soft: #3a3a3a;
    --muted: #6b6b6b;
    --faint: #8f8f8f;
    --black: #111111;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    --sidebar-w: 252px;
    --topbar-h: 77px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Estructura ---------- */

.app-shell { display: flex; min-height: 100vh; }

.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.content {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 26px;
    flex: 1;
}

/* ---------- Sidebar ---------- */

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    height: var(--topbar-h);
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    background: var(--black);
    color: #fff;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 17px;
}

.brand-text strong {
    display: block;
    font-size: 14px;
    letter-spacing: 0.14em;
    line-height: 1.2;
}

.brand-text span {
    font-size: 10px;
    letter-spacing: 0.24em;
    color: var(--muted);
}

.nav {
    padding: 12px;
    overflow-y: auto;
    flex: 1;
}

.nav-label {
    margin: 16px 10px 6px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--faint);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-soft);
    font-weight: 500;
    font-size: 13.5px;
}

.nav-link svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-link:hover { background: #f2f2f2; color: var(--text); }
.nav-link.is-active { background: var(--black); color: #fff; }

.sidebar-foot {
    padding: 14px;
    border-top: 1px solid var(--border);
    display: grid;
    gap: 8px;
}

.server-chip {
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 8px;
    padding: 9px 11px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.server-chip .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--black);
    flex: 0 0 7px;
}

.server-chip strong { font-weight: 600; }
.server-chip small { margin-left: auto; color: var(--faint); font-size: 10.5px; }

.version {
    text-align: center;
    font-size: 10.5px;
    color: var(--faint);
    letter-spacing: 0.04em;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
    z-index: 35;
}

/* ---------- Topbar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: var(--topbar-h);
    padding: 0 26px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--border);
}

.icon-btn {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: none;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
}

.icon-btn:hover { background: #f2f2f2; }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; }

.crumb {
    font-size: 12px;
    color: var(--muted);
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crumb strong { color: var(--text); font-weight: 600; }

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.chip {
    font-size: 11.5px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: #555;
    padding: 5px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.chip-strong { background: var(--black); border-color: var(--black); color: #fff; }

/* ---------- Encabezado de página ---------- */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.page-head h1 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin-bottom: 4px;
}

.page-head .muted { max-width: 640px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- Tarjetas / estadísticas ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 17px 18px;
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: var(--muted);
    font-weight: 600;
}

.stat-value {
    font-size: 30px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 5px 0 2px;
    line-height: 1.2;
}

.stat-meta { font-size: 12px; color: var(--faint); }

.grid-2 {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 16px;
}

.grid-2 .card { margin-bottom: 0; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.card-head h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 18px; }

.link {
    font-size: 12.5px;
    color: var(--text-soft);
    text-decoration: none;
    border-bottom: 1px solid #bbb;
    padding-bottom: 1px;
}

.link:hover { color: #000; border-color: #000; }

/* ---------- Tablas ---------- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
    text-align: left;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    color: var(--faint);
    font-weight: 600;
    padding: 10px 18px;
    background: #fbfbfb;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 12px 18px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafafa; }

.cell-title { font-weight: 600; }

.cell-sub {
    font-size: 12px;
    color: var(--muted);
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 30px 18px;
    font-size: 13px;
}

.code {
    font-family: var(--mono);
    font-size: 11.5px;
    background: #f4f4f4;
    border: 1px solid #e6e6e6;
    border-radius: 4px;
    padding: 2px 6px;
    white-space: nowrap;
}

.actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    white-space: nowrap;
}

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--text-soft);
    white-space: nowrap;
}

.badge-dark { background: #4a4a4a; border-color: #4a4a4a; color: #fff; }
.badge-black { background: var(--black); border-color: var(--black); color: #fff; }
.badge-soft { background: #f4f4f4; border-color: #e2e2e2; color: var(--muted); }

/* ---------- Botones ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.btn:hover { background: #f2f2f2; }

.btn-primary { background: var(--black); border-color: var(--black); color: #fff; }
.btn-primary:hover { background: #2c2c2c; }

.btn-danger { border-color: var(--black); color: var(--text); }
.btn-danger:hover { background: var(--black); color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: #555;
    justify-content: flex-start;
    padding: 8px 10px;
    font-size: 12.5px;
}

.btn-ghost:hover { background: #f2f2f2; color: #111; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Toolbar / filtros ---------- */

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 13px 15px;
    margin-bottom: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.toolbar-filters {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

input[type="search"],
input[type="text"],
input[type="number"],
input[type="email"],
select,
textarea {
    border: 1px solid var(--border-strong);
    background: #fff;
    border-radius: 8px;
    padding: 9px 11px;
    font-size: 13.5px;
    outline: none;
}

input[type="search"] { min-width: 240px; }

input:focus,
select:focus,
textarea:focus {
    border-color: var(--black);
    box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.08);
}

.result-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 0 10px;
    font-size: 12px;
    color: var(--muted);
}

/* ---------- Formularios / modal ---------- */

.form { display: grid; gap: 16px; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.field { display: grid; gap: 6px; }

.field > span {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-soft);
}

.field-full { grid-column: 1 / -1; }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { resize: vertical; min-height: 78px; }

.form-error {
    border: 1px solid var(--black);
    background: #f4f4f4;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    margin: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 2px;
}

.modal-text { font-size: 13.5px; color: var(--text-soft); }
.modal-text + .modal-actions { margin-top: 16px; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 34px 16px;
    background: rgba(0, 0, 0, 0.45);
    overflow-y: auto;
}

.modal-backdrop.is-open { display: flex; }

.modal {
    width: 100%;
    max-width: 560px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    animation: modal-in 0.14s ease-out;
}

.modal.is-wide { max-width: 840px; }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-head h2 { font-size: 16px; font-weight: 600; }

.modal-close {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border: 0;
    border-radius: 50%;
    background: #f4f4f4;
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover { background: #e8e8e8; }
.modal-body { padding: 20px; }
.modal-foot:empty { display: none; }

body.modal-open { overflow: hidden; }

/* ---------- Actividad ---------- */

.activity { list-style: none; padding: 4px 18px 8px; margin: 0; }

.activity li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid #f1f1f1;
    font-size: 13.5px;
}

.activity li:last-child { border-bottom: 0; }
.activity .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--black); flex: 0 0 7px; margin-top: 7px; }
.activity-body { min-width: 0; }
.activity-body strong { font-weight: 600; }
.activity-detail { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.activity .when { margin-left: auto; color: var(--faint); font-size: 11.5px; white-space: nowrap; }

/* ---------- Gestor de archivos ---------- */

.dropzone {
    border: 1.5px dashed #bdbdbd;
    border-radius: 10px;
    background: var(--surface-2);
    padding: 24px 18px;
    text-align: center;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.dropzone.is-drag { background: #eeeeee; border-color: var(--black); }
.dropzone strong { display: block; font-size: 14px; margin-bottom: 3px; }
.dropzone .hint { margin-top: 6px; }
.dropzone-actions { margin-top: 12px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.selected-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }

.selected-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12.5px;
}

.selected-list .grow {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-cell { display: flex; align-items: center; gap: 10px; min-width: 210px; }

.file-badge {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f3f3f3;
    display: grid;
    place-items: center;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #444;
}

.preview { background: #f4f4f4; border: 1px solid var(--border); border-radius: 8px; padding: 12px; text-align: center; }
.preview img { max-width: 100%; max-height: 58vh; border: 1px solid var(--border); background: #fff; }
.preview-frame { width: 100%; height: 58vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.preview-media { display: block; width: 100%; max-height: 58vh; margin: 0 auto 16px; }

.preview-text {
    max-height: 52vh;
    overflow: auto;
    background: #f7f7f7;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    font-family: var(--mono);
    font-size: 12.5px;
    white-space: pre-wrap;
}

.preview-empty {
    border: 1px solid var(--border);
    background: #fafafa;
    border-radius: 8px;
    padding: 28px 18px;
    text-align: center;
    display: grid;
    gap: 8px;
    justify-items: center;
}

.fake-pdf {
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    padding: 26px 28px;
    min-height: 300px;
    text-align: left;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}

.fake-pdf h3 { font-size: 17px; margin-bottom: 3px; }
.fake-pdf .fake-sub { font-size: 11.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); }
.fake-line { height: 8px; border-radius: 4px; background: #ededed; margin: 11px 0; }
.fake-line.short { width: 62%; }
.fake-line.tiny { width: 38%; }
.fake-space { height: 12px; }

.file-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 18px;
    margin-top: 14px;
    font-size: 12px;
}

.file-meta div {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px dashed #ececec;
    padding-bottom: 4px;
}

.file-meta span:first-child { color: var(--muted); }
.file-meta span:last-child { text-align: right; overflow-wrap: anywhere; }

/* ---------- Toasts ---------- */

.toast-stack {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 120;
    display: grid;
    gap: 8px;
    max-width: min(370px, calc(100vw - 36px));
}

.toast {
    background: var(--black);
    color: #fff;
    border-radius: 9px;
    padding: 11px 14px;
    font-size: 13px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
    transition: opacity 0.2s ease, transform 0.2s ease;
    overflow-wrap: anywhere;
}

.toast.is-info { background: #4a4a4a; }
.toast.is-error { background: #fff; color: var(--text); border: 1px solid var(--black); border-left: 5px solid var(--black); }
.toast.is-out { opacity: 0; transform: translateY(8px); }

/* ---------- Pie ---------- */

.app-footer {
    padding: 8px 26px 24px;
    text-align: center;
    font-size: 11.5px;
    color: var(--faint);
}

/* ---------- Responsive ---------- */

@media (max-width: 1120px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh;
        transform: translateX(-103%);
        transition: transform 0.18s ease;
        box-shadow: 12px 0 40px rgba(0, 0, 0, 0.18);
    }

    body.nav-open .sidebar { transform: none; }
    body.nav-open .sidebar-overlay { opacity: 1; pointer-events: auto; }

    .icon-btn { display: inline-flex; }
    .content { padding: 18px 16px; }
    .topbar { padding: 0 16px; }
    .page-head h1 { font-size: 20px; }
    .form-grid { grid-template-columns: 1fr; }
    .modal-backdrop { padding: 0; align-items: flex-end; }
    .modal { border-radius: 12px 12px 0 0; max-height: 94vh; overflow-y: auto; }
    .modal.is-wide { max-width: 100%; }
    .file-meta { grid-template-columns: 1fr; }
    .app-footer { padding: 8px 16px 20px; }
}

@media (max-width: 640px) {
    .stats-grid { grid-template-columns: 1fr; }
    .topbar-right .chip:first-child { display: none; }
    .toolbar-filters { flex-direction: column; align-items: stretch; }
    .toolbar-filters > * { width: 100%; }
    input[type="search"] { min-width: 0; }
    .toolbar > .btn { width: 100%; }
    .actions { justify-content: flex-start; }
    .page-head-actions { width: 100%; }
    .page-head-actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
