:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2b3039;
    --text: #e6e8ec;
    --text-dim: #9aa1ad;
    --accent: #6d8bff;
    --accent-strong: #4d6bff;
    --busco: #f59e0b;
    --busco-bg: rgba(245, 158, 11, .14);
    --tengo: #34d399;
    --tengo-bg: rgba(52, 211, 153, .14);
    --sobra: #60a5fa;
    --sobra-bg: rgba(96, 165, 250, .14);
    --danger: #f87171;
    --radius: 12px;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1:focus { outline: none; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.25rem;
}

/* ---------- Header ---------- */
.site-header {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 20;
}
.site-header .inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}
.brand {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand .dot { color: var(--accent); }
.nav-actions { display: flex; gap: .5rem; align-items: center; }

/* ---------- Layout helpers ---------- */
.page { padding: 2rem 0 4rem; }
.muted { color: var(--text-dim); }
.eyebrow {
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: .75rem;
    color: var(--text-dim);
    margin-bottom: .35rem;
}
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

/* ---------- Cards ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.1rem;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); }
a.card:hover { text-decoration: none; transform: translateY(-2px); }
.card-body { padding: 1rem 1.1rem; }
.card-title { font-size: 1.1rem; font-weight: 650; color: var(--text); margin: 0 0 .25rem; }

/* ---------- Article cards ---------- */
.articulos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.1rem;
}
.articulo {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.articulo .thumb {
    aspect-ratio: 2 / 3;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.articulo .thumb img { width: 100%; height: 100%; object-fit: cover; }
.articulo .thumb .no-img { color: var(--text-dim); font-size: .8rem; }
.articulo .info { padding: .7rem .8rem; display: flex; flex-direction: column; gap: .35rem; }
.articulo .nombre { font-weight: 600; color: var(--text); }
.articulo .obs { font-size: .82rem; color: var(--text-dim); }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .72rem;
    font-weight: 650;
    padding: .18rem .5rem;
    border-radius: 999px;
    width: fit-content;
}
.estado-busco { color: var(--busco); background: var(--busco-bg); }
.estado-tengo { color: var(--tengo); background: var(--tengo-bg); }
.estado-sobra { color: var(--sobra); background: var(--sobra-bg); }

/* ---------- Sections ---------- */
.seccion-estado { margin-bottom: 2.5rem; }
.seccion-estado h2 {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: 1.15rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.1rem;
}
.count-chip {
    font-size: .78rem;
    color: var(--text-dim);
    font-weight: 500;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    font-size: .9rem;
    font-weight: 600;
    padding: .5rem .9rem;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: background .15s, border-color .15s;
    text-decoration: none;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: rgba(248, 113, 113, .12); border-color: transparent; }
.btn-sm { padding: .32rem .6rem; font-size: .8rem; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }

/* ---------- Forms ---------- */
.form-row { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.form-row label { font-size: .85rem; font-weight: 600; color: var(--text-dim); }
.form-control, .form-select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: .55rem .7rem;
    font-size: .95rem;
    font-family: inherit;
}
.form-control:focus, .form-select:focus { outline: none; border-color: var(--accent); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: .6rem; margin-top: .5rem; }
.validation-message { color: var(--danger); font-size: .82rem; }
.invalid { border-color: var(--danger) !important; }

/* ---------- Table ---------- */
.tabla { width: 100%; border-collapse: collapse; }
.tabla th, .tabla td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--border); }
.tabla th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }
.tabla tr:hover td { background: var(--surface); }
.tabla .acciones { display: flex; gap: .3rem; justify-content: flex-end; }

/* ---------- Admin shell ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.admin-side {
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    position: sticky;
    top: 0;
    height: 100vh;
}
.admin-side .brand { margin-bottom: 1.5rem; display: block; }
.admin-side .nav-link {
    display: flex; align-items: center; gap: .55rem;
    padding: .55rem .7rem;
    border-radius: 8px;
    color: var(--text-dim);
    font-weight: 550;
}
.admin-side .nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.admin-side .nav-link.active { background: var(--accent-strong); color: #fff; }
.admin-side .spacer { flex: 1; }
.admin-main { flex: 1; padding: 2rem 2.25rem; max-width: 1000px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-card {
    width: 100%; max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

/* ---------- Image search ---------- */
.img-search-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: .7rem;
    margin-top: 1rem;
    max-height: 360px;
    overflow-y: auto;
    padding: .25rem;
}
.img-option {
    border: 2px solid var(--border);
    border-radius: 9px;
    overflow: hidden;
    cursor: pointer;
    background: var(--surface-2);
    padding: 0;
    display: flex;
    flex-direction: column;
}
.img-option:hover { border-color: var(--accent); }
.img-option.selected { border-color: var(--accent-strong); box-shadow: 0 0 0 2px var(--accent-strong); }
.img-option img { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; }
.img-option .cap { font-size: .68rem; padding: .25rem .35rem; color: var(--text-dim); }

.img-preview {
    width: 120px; aspect-ratio: 2/3; object-fit: cover;
    border-radius: 9px; border: 1px solid var(--border);
}

/* ---------- Misc ---------- */
.alert {
    padding: .7rem .9rem; border-radius: 9px; font-size: .88rem;
    border: 1px solid var(--border); margin-bottom: 1rem;
}
.alert-error { color: var(--danger); background: rgba(248, 113, 113, .1); border-color: transparent; }
.alert-info { color: var(--text-dim); background: var(--surface); }
.alert-success { color: #4ade80; background: rgba(74, 222, 128, .1); border-color: transparent; }
.empty-state {
    text-align: center; padding: 3rem 1rem; color: var(--text-dim);
    border: 1px dashed var(--border); border-radius: var(--radius);
}
.spinner { color: var(--text-dim); font-size: .9rem; }

@media (max-width: 720px) {
    .admin-shell { flex-direction: column; }
    .admin-side { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; }
    .admin-main { padding: 1.25rem; }
}

/* ---------- Blazor error UI ---------- */
.blazor-error-boundary {
    background: var(--danger);
    padding: 1rem;
    color: white;
}
#blazor-error-ui {
    background: #2b1a1a;
    color: #f7caca;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none;
    left: 0;
    padding: .8rem 1.2rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; top: .6rem; }
.valid.modified:not([type=checkbox]) { outline: 1px solid var(--tengo); }
