/* ==============================
   VARIABLES
   ============================== */
:root {
    --bg: #faf8f5;
    --surface: #ffffff;
    --surface-2: #f3efe9;
    --border: #e2dbd3;
    --border-soft: #ede8e2;

    --text: #2a2018;
    --text-2: #6d5d4b;
    --text-3: #a08c78;

    --accent: #7a6452;
    --accent-hover: #5e4d3d;
    --accent-soft: rgba(122, 100, 82, 0.09);
    --accent-softer: rgba(122, 100, 82, 0.05);

    --blue: #2d6cdf;
    --blue-hover: #2453aa;
    --blue-soft: rgba(45, 108, 223, 0.09);

    --red: #c0392b;
    --red-hover: #962d22;
    --red-soft: rgba(192, 57, 43, 0.09);

    --green: #2e7d50;
    --green-soft: rgba(46, 125, 80, 0.1);

    --radius: 10px;
    --radius-sm: 6px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
    --shadow: 0 4px 12px rgba(0, 0, 0, .07), 0 1px 3px rgba(0, 0, 0, .05);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .10), 0 2px 8px rgba(0, 0, 0, .06);

    --transition: .18s ease;

    --font: 'Lato', system-ui, sans-serif;
}

/* ==============================
   RESET / BASE
   ============================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    height: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    min-height: 100%;
    -webkit-font-smoothing: antialiased;
}

/* ==============================
   LAYOUT
   ============================== */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ==============================
   HEADER
   ============================== */
.admin-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.admin-header-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: .9rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.admin-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: .02em;
}

.admin-nav {
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* ==============================
   MAIN
   ============================== */
.admin-main {
    padding: 2rem 1.5rem 4rem;
}

/* ==============================
   TIPOGRAFÍA
   ============================== */
h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.01em;
}

h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

p {
    font-size: .95rem;
    color: var(--text-2);
}

/* ==============================
   BOTONES
   ============================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    border-radius: var(--radius-pill);
    padding: .48rem 1.1rem;
    font-size: .82rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: background var(--transition), box-shadow var(--transition), color var(--transition), border-color var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1;
}

.btn--primary {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}

.btn--primary:hover {
    background: var(--blue-hover);
    border-color: var(--blue-hover);
    box-shadow: 0 4px 14px rgba(45, 108, 223, .25);
}

.btn--accent {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn--accent:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 4px 14px rgba(122, 100, 82, .22);
}

.btn--ghost {
    background: transparent;
    color: var(--text-2);
    border-color: var(--border);
}

.btn--ghost:hover {
    background: var(--surface-2);
    border-color: var(--accent);
    color: var(--accent);
}

.btn--danger {
    background: transparent;
    color: var(--red);
    border-color: var(--border);
}

.btn--danger:hover {
    background: var(--red-soft);
    border-color: var(--red);
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
    pointer-events: none;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .38rem .9rem;
    border-radius: var(--radius-pill);
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-2);
    text-decoration: none;
    border: 1.5px solid var(--border);
    transition: all var(--transition);
}

.nav-link:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

/* ==============================
   UTILIDADES
   ============================== */
.hidden {
    display: none !important;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: .18rem .55rem;
    border-radius: var(--radius-pill);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
}

.chip--yes {
    background: var(--green-soft);
    color: var(--green);
}

.chip--no {
    background: var(--red-soft);
    color: var(--red);
}

/* ==============================
   TOAST (reemplaza alerts)
   ============================== */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1.1rem;
    border-radius: var(--radius);
    background: var(--text);
    color: #fff;
    font-size: .85rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    max-width: 340px;
    pointer-events: all;
    animation: toastIn .25s ease forwards;
}

.toast.toast--success {
    background: #1e6b3e;
}

.toast.toast--error {
    background: var(--red);
}

.toast.toast--info {
    background: var(--accent);
}

.toast.toast--out {
    animation: toastOut .2s ease forwards;
}

.toast-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.toast-msg {
    flex: 1;
    line-height: 1.3;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(8px);
    }
}

/* ==============================
   MODAL DE CONFIRMACIÓN
   ============================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    backdrop-filter: blur(3px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    animation: fadeIn .15s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.75rem 2rem;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: scaleIn .18s ease;
}

.modal-box h3 {
    margin-bottom: .5rem;
}

.modal-box p {
    margin-bottom: 1.25rem;
    font-size: .92rem;
}

.modal-actions {
    display: flex;
    gap: .6rem;
    justify-content: flex-end;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ==============================
   LOGIN VIEW
   ============================== */
.login-card {
    max-width: 380px;
    margin: 4rem auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.25rem 2rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-card .brand {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -.02em;
    margin-bottom: .3rem;
}

.login-card p {
    margin-bottom: 1.5rem;
    font-size: .9rem;
}

/* ==============================
   DASHBOARD HEADER
   ============================== */
.dashboard-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.dashboard-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* ==============================
   BUSCADOR
   ============================== */
.search-wrap {
    position: relative;
    margin-bottom: 1.1rem;
}

.search-wrap svg {
    position: absolute;
    left: .85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: .6rem .9rem .6rem 2.4rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--text);
    font-size: .88rem;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-input::placeholder {
    color: var(--text-3);
}

/* ==============================
   LISTA DE POSTS
   ============================== */
.post-list-admin {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.post-list-admin .loading {
    padding: 2rem;
    text-align: center;
    color: var(--text-3);
    font-size: .9rem;
}

.post-grid {
    list-style: none;
}

.post-grid-item {
    border-bottom: 1px solid var(--border-soft);
    transition: background var(--transition);
}

.post-grid-item:last-child {
    border-bottom: none;
}

.edit-link {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: .1rem .75rem;
    padding: .85rem 1.1rem;
    text-decoration: none;
    color: inherit;
    transition: background var(--transition);
}

.edit-link:hover {
    background: var(--accent-softer);
}

.post-grid-title {
    font-weight: 700;
    font-size: .95rem;
    color: var(--text);
    grid-column: 1;
    grid-row: 1;
}

.post-grid-title h3 {
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
}

.post-grid-meta {
    display: flex;
    align-items: center;
    gap: .6rem;
    grid-column: 1;
    grid-row: 2;
    flex-wrap: wrap;
}

.post-grid-id {
    font-size: .72rem;
    color: var(--text-3);
    font-family: monospace;
    background: var(--surface-2);
    padding: .1rem .4rem;
    border-radius: 4px;
}

.post-grid-date {
    font-size: .77rem;
    color: var(--text-3);
}

.post-grid-tag {
    font-size: .72rem;
    background: var(--accent-soft);
    color: var(--accent);
    padding: .1rem .5rem;
    border-radius: var(--radius-pill);
    font-weight: 600;
}

.post-grid-badge {
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: center;
}

.post-list-footer {
    padding: .6rem 1.1rem;
    border-top: 1px solid var(--border-soft);
    display: flex;
    justify-content: flex-end;
}

/* ==============================
   EDITOR
   ============================== */
.editor-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 2rem;
    box-shadow: var(--shadow-sm);
}

.editor-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-soft);
}

.editor-top h2 {
    font-size: 1.2rem;
}

.editor-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

label {
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-3);
}

input[type="text"],
input[type="search"],
textarea,
select {
    width: 100%;
    padding: .55rem .75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: .9rem;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--surface);
}

input[readonly] {
    background: var(--surface-2);
    color: var(--text-2);
    cursor: default;
}

textarea {
    min-height: 280px;
    resize: vertical;
    font-family: 'Courier New', monospace;
    font-size: .85rem;
    line-height: 1.6;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236d5d4b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    padding-right: 2.2rem;
}

#id-status-message {
    font-size: .77rem;
    font-weight: 600;
    min-height: 1em;
}

#id-status-message.available {
    color: var(--green);
}

#id-status-message.unavailable {
    color: var(--red);
}

.editor-actions {
    display: flex;
    gap: .6rem;
    padding-top: .5rem;
    border-top: 1px solid var(--border-soft);
    flex-wrap: wrap;
}

.editor-actions .btn--danger {
    margin-left: auto;
}

/* ==============================
   LIVE BADGE
   ============================== */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--green);
    background: var(--green-soft);
    padding: .25rem .7rem;
    border-radius: var(--radius-pill);
}

.live-badge--offline {
    background: var(--red-soft);
    color: var(--red);
}

.live-badge--offline .live-dot {
    background: var(--red);
    animation: none;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 1.8s ease infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: .4;
        transform: scale(.7);
    }
}

/* ==============================
   FOOTER
   ============================== */
.admin-footer {
    border-top: 1px solid var(--border);
    padding: 1.25rem 1.5rem;
    text-align: center;
    font-size: .78rem;
    color: var(--text-3);
}

/* ==============================
   CALLBACK PAGE
   ============================== */
.callback-center {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.callback-card {
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    max-width: 380px;
    width: 100%;
    box-shadow: var(--shadow);
}

.callback-card .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto 1.25rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.callback-card h2 {
    font-size: 1.1rem;
    margin-bottom: .4rem;
}

.callback-card p {
    font-size: .85rem;
}

/* ==============================
   STATUS NOTIFICACIONES
   ============================== */
#status {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(150%);
    padding: .6rem 1.4rem;
    border-radius: var(--radius-pill);
    font-family: var(--font);
    font-size: .85rem;
    font-weight: 700;
    color: #fff;
    z-index: 10000;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: transform .35s ease, opacity .35s ease;
    white-space: nowrap;
}

#status.is-visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

#status.is-online {
    background: #2ea44f;
}

#status.is-offline {
    background: var(--red);
}

#status.is-update {
    background: var(--accent);
    cursor: pointer;
}

/* ==============================
   MOBILE
   ============================== */
@media (max-width: 640px) {
    .admin-header-inner {
        flex-wrap: wrap;
        gap: .6rem;
    }

    .field-row {
        grid-template-columns: 1fr;
    }

    .editor-card {
        padding: 1.25rem 1rem;
    }

    .editor-actions .btn--danger {
        margin-left: 0;
    }

    .dashboard-top {
        flex-direction: column;
        align-items: flex-start;
    }
}