/* ================================================================
   Sambys Admin — Design System
   Mobile-first responsive layout
   ================================================================ */

:root {
    --bg-base: #0a0a0a;
    --bg-surface: #111111;
    --bg-cards: #171717;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    --text-main: #ededed;
    --text-muted: #a1a1a1;
    --color-primary: #d4af37;
    --color-primary-dim: rgba(212, 175, 55, 0.15);
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --radius-md: 8px;
    --radius-sm: 6px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-family);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

h1,
h2,
h3,
h4 {
    color: var(--text-main);
}

/* ================================================================
   LOGIN
   ================================================================ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-container {
    width: 100%;
    max-width: 400px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: var(--radius-md);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.login-brand h2 {
    color: var(--color-primary);
    font-weight: 800;
    letter-spacing: 2px;
    margin-bottom: 0.5rem;
}

.login-brand p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    background-color: var(--bg-cards);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    /* 16px mínimo para evitar zoom en iOS */
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-dim);
}

.btn-primary {
    width: 100%;
    background-color: var(--color-primary);
    color: #000;
    font-weight: 700;
    border: none;
    padding: 0.9rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    transition: opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-primary:active {
    opacity: 0.75;
}

.error-msg {
    color: #ff5c5c;
    font-size: 0.85rem;
    margin-top: 1rem;
    text-align: center;
    min-height: 1.2rem;
}

/* ================================================================
   DASHBOARD LAYOUT (Mobile-first)
   ================================================================ */

.dashboard-body {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar Overlay (visible solo en mobile) --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 40;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar__brand {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar__brand h2 {
    color: var(--text-main);
    font-size: 1.1rem;
    letter-spacing: 1px;
}

.sidebar__brand span {
    background-color: var(--color-primary-dim);
    color: var(--color-primary);
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 700;
}

/* Botón cerrar dentro de sidebar (mobile) */
.sidebar__close {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}

.sidebar__nav {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar__nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: background-color 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.sidebar__nav a i {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.sidebar__nav a:hover {
    color: var(--text-main);
    background-color: var(--bg-cards);
}

.sidebar__nav a.active {
    background-color: var(--color-primary-dim);
    color: var(--color-primary);
}

.sidebar__footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    width: 100%;
    padding: 0.85rem;
    border-radius: var(--radius-sm);
    transition: background-color 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-logout:hover {
    background-color: rgba(255, 92, 92, 0.1);
    color: #ff5c5c;
}

/* --- Contenido Principal --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Evita overflow en flex */
    width: 100%;
}

/* --- Topbar --- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--topbar-height);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background-color: var(--bg-base);
    border-bottom: 1px solid var(--border-color);
}

/* Botón hamburger */
.topbar__menu-btn {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s;
}

.topbar__menu-btn:hover {
    background-color: var(--bg-cards);
}

.topbar__title h1 {
    font-size: 1.1rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--bg-cards);
    padding: 0.35rem 0.75rem 0.35rem 0.35rem;
    border-radius: 50px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.topbar__user .avatar {
    width: 30px;
    height: 30px;
    background-color: var(--color-primary);
    color: #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.topbar__user .user-name {
    font-size: 0.85rem;
    color: var(--text-main);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Área de Contenido --- */
.content-wrapper {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ================================================================
   CARD & CARD HEADER
   ================================================================ */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.card-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

.btn-action {
    background-color: var(--text-main);
    color: var(--bg-base);
    border: none;
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn-action:hover {
    opacity: 0.9;
}

.btn-action:active {
    opacity: 0.75;
}

/* ================================================================
   TABLAS — con scroll horizontal en mobile
   ================================================================ */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
    /* Sombra sutil en el borde derecho para indicar scroll */
    background:
        linear-gradient(to right, var(--bg-surface), var(--bg-surface)),
        linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.3));
    background-repeat: no-repeat;
    background-attachment: local, scroll;
    background-size: 20px 100%, 10px 100%;
    background-position: right center, right center;
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 480px;
    /* Ancho mínimo para evitar colapso extremo */
}

.table th,
.table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    white-space: nowrap;
}

.table th {
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.5px;
    background-color: var(--bg-surface);
    position: sticky;
    top: 0;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background-color: var(--bg-cards);
}

/* Celdas editables en tabla */
[contenteditable="true"] {
    transition: background-color 0.15s, outline 0.15s;
    border-radius: 4px;
    white-space: normal;
    min-width: 60px;
}

[contenteditable="true"]:focus {
    background-color: rgba(255, 255, 255, 0.05);
    outline: 2px solid var(--color-primary);
    padding-left: 8px;
}

/* Select en tabla */
.table td select {
    background-color: var(--bg-cards);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

/* Aclaración de medidas recomendadas */
.upload-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    background: rgba(212, 175, 55, 0.07);
    border-left: 3px solid var(--color-primary);
    padding: 0.6rem 0.9rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.upload-hint strong {
    color: var(--color-primary);
}

/* ================================================================
   IMAGE UPLOAD EN TABLA
   ================================================================ */

/* Columna de imagen — ancho fijo */
.table .img-col {
    width: 64px;
}

/* Label clickable que actúa como botón de upload */
.img-upload-label {
    display: block;
    width: 52px;
    height: 52px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    background-color: var(--bg-cards);
    border: 1.5px dashed var(--border-color);
    transition: border-color 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.img-upload-label:hover {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-dim);
}

/* Ocultar el input real */
.img-upload-label input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    font-size: 0;
    /* evita espacio extra */
}

/* Thumbnail de la imagen */
.img-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

/* Placeholder cuando no hay imagen */
.img-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    font-size: 0.65rem;
    text-align: center;
    line-height: 1.2;
    padding: 4px;
    pointer-events: none;
}

/* Estado cargando */
.img-upload-label.uploading {
    opacity: 0.6;
    pointer-events: none;
}

.img-upload-label.uploading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    border-radius: var(--radius-sm);
}

/* Spinner de carga */
.img-upload-label.uploading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    z-index: 1;
}

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


/* Botón eliminar en tabla */
.btn-delete {
    background: none;
    border: none;
    color: #ff5c5c;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-delete:hover {
    background-color: rgba(255, 92, 92, 0.12);
}

/* ================================================================
   BADGES
   ================================================================ */
.badge {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.72rem;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.badge.success {
    background-color: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
}

.badge.warning {
    background-color: var(--color-primary-dim);
    color: var(--color-primary);
}

/* ================================================================
   FORMULARIO DE CONFIGURACION
   ================================================================ */
.admin-form .form-group {
    margin-bottom: 1.1rem;
}

.admin-form label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    font-weight: 500;
}

.admin-form input,
.admin-form textarea,
.admin-form select {
    width: 100%;
    background-color: var(--bg-cards);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    /* 16px mínimo para evitar zoom en iOS */
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
    font-family: var(--font-family);
}

.admin-form input:focus,
.admin-form textarea:focus {
    border-color: var(--color-primary);
}

.admin-form textarea {
    resize: vertical;
    min-height: 80px;
}

/* Grid de 2 columnas → 1 en mobile */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

/* ================================================================
   SECCIÓN FOOTER DEL CARD (guardar)
   ================================================================ */
.card-footer-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
}

.btn-save {
    background-color: var(--color-primary);
    color: #000;
    border: none;
    padding: 0.75rem 1.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
    width: 100%;
    /* Full width en mobile */
    -webkit-tap-highlight-color: transparent;
}

.btn-save:hover {
    opacity: 0.9;
}

.btn-save:active {
    opacity: 0.75;
}

.btn-save:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ================================================================
   TOAST NOTIFICATION (reemplaza alert())
   ================================================================ */
#admin-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 9999;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    max-width: calc(100vw - 2rem);
    text-align: center;
}

#admin-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

#admin-toast.toast-success {
    border-color: rgba(46, 204, 113, 0.4);
    color: #2ecc71;
}

#admin-toast.toast-error {
    border-color: rgba(255, 92, 92, 0.4);
    color: #ff5c5c;
}

/* ================================================================
   TABLET (≥ 640px)
   ================================================================ */
@media (min-width: 640px) {
    .content-wrapper {
        padding: 1.5rem;
    }

    .card {
        padding: 1.5rem;
    }

    .btn-save {
        width: auto;
    }

    .table th,
    .table td {
        padding: 0.875rem 1rem;
    }
}

/* ================================================================
   DESKTOP (≥ 900px) — Sidebar fija visible
   ================================================================ */
@media (min-width: 900px) {
    .sidebar {
        position: fixed;
        /* fixed para dejar al main-content fluir */
        transform: translateX(0);
        /* siempre visible */
        top: 0;
        left: 0;
        height: 100vh;
    }

    /* El main-content deja espacio al sidebar con margin */
    .main-content {
        margin-left: var(--sidebar-width);
    }

    /* Ocultar botón hamburger en desktop */
    .topbar__menu-btn {
        display: none;
    }

    /* Ocultar botón cerrar dentro del sidebar en desktop */
    .sidebar__close {
        display: none;
    }

    /* Overlay nunca visible en desktop */
    .sidebar-overlay {
        display: none !important;
    }

    .content-wrapper {
        padding: 2rem;
    }

    .card {
        padding: 1.75rem;
    }

    .form-grid {
        grid-template-columns: 1fr 1fr;
        gap: 2rem;
    }

    .btn-save {
        width: auto;
    }
}