/* Variables */
:root {
    --bg: #f8f9fa;
    --bg-card: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-muted: #6b7280;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    line-height: 1.5;
    background: var(--bg);
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(160deg, #f0f1f5 0%, #e8eaef 100%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 2rem;
    border: 1px solid var(--border);
}

.login-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-header h1 {
    margin: 0 0 0.35rem;
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text);
}

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

.login-form .form-group {
    margin-bottom: 1.1rem;
}

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

.login-form input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: var(--bg-card);
}

.login-form input::placeholder {
    color: #9ca3af;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.error-msg {
    color: var(--danger);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

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

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

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    text-decoration: none;
}

.btn-ghost:hover {
    color: var(--text);
    background: rgba(0,0,0,.05);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
}

.btn-danger:hover {
    background: rgba(220, 38, 38, 0.08);
}

.btn-block {
    width: 100%;
    margin-top: 0.25rem;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
}

/* Dashboard layout */
.dashboard {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}

.logo-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
}

.nav-link {
    display: block;
    padding: 0.6rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
    color: var(--text);
    background: rgba(0,0,0,.04);
}

.nav-link.active {
    color: var(--primary);
    font-weight: 500;
    background: rgba(79, 70, 229, 0.08);
    border-right: 2px solid var(--primary);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.user-name {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Main content */
.main {
    flex: 1;
    padding: 1.5rem 2rem;
    overflow: auto;
}

.panel-section {
    display: none;
}

.panel-section.active {
    display: block;
}

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

.section-header h2 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text);
}

/* Table */
.table-wrap {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: visible;
    box-shadow: var(--shadow);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

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

.data-table tbody tr:hover {
    background: rgba(0,0,0,.02);
}

.data-table .thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--bg);
}

.data-table .actions-cell {
    position: relative;
    overflow: visible;
}

.data-table {
    overflow: visible;
}

.dropdown-trigger {
    background: none;
    border: none;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    border-radius: var(--radius);
}

.dropdown-trigger:hover {
    color: var(--text);
    background: rgba(0,0,0,.06);
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 2px;
    min-width: 140px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    padding: 0.25rem;
    display: none;
}

.dropdown-menu.is-open {
    display: block;
}

.dropdown-menu button,
.dropdown-menu a {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-size: 0.9rem;
    font-family: inherit;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    text-decoration: none;
    border-radius: 4px;
}

.dropdown-menu button:hover,
.dropdown-menu a:hover {
    background: rgba(0,0,0,.06);
}

.dropdown-menu button.danger,
.dropdown-menu .danger {
    color: var(--danger);
}

/* Categories grid */
.cards-wrap {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.category-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    box-shadow: var(--shadow);
}

.category-card .name {
    font-weight: 500;
    color: var(--text);
}

.category-card .actions {
    display: flex;
    gap: 0.25rem;
}

.category-card .actions button {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 4px;
}

.category-card .actions button:hover {
    color: var(--primary);
    background: rgba(79, 70, 229, 0.08);
}

.category-card .actions button.danger:hover {
    color: var(--danger);
    background: rgba(220, 38, 38, 0.08);
}

/* Catalog settings */
.catalog-settings {
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.catalog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.setting-block label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.image-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 140px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--bg);
    transition: border-color 0.15s, background 0.15s;
}

.image-upload:hover {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.04);
}

.image-upload.small {
    min-height: 100px;
    max-width: 200px;
}

.image-upload .preview-img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 6px;
}

.image-upload .placeholder {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.file-select-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.file-input {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}

.image-preview-wrap {
    pointer-events: none;
}

.form-message {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
}

.form-message.success {
    color: #059669;
}

.form-message.error {
    color: var(--danger);
}

/* Toasts */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.25s ease;
    pointer-events: auto;
    max-width: 360px;
    transition: opacity 0.2s, transform 0.2s;
    cursor: pointer;
}

.toast--success {
    background: #059669;
    color: #fff;
}

.toast--error {
    background: var(--danger);
    color: #fff;
}

.toast--info {
    background: var(--primary);
    color: #fff;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(1rem);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.4);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,.15);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
}

.modal-content.modal-sm {
    max-width: 360px;
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius);
}

.modal-close:hover {
    color: var(--text);
    background: rgba(0,0,0,.06);
}

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

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

.label-optional {
    font-weight: 400;
    color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--bg-card);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

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

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Repeater characteristics */
.repeater-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.repeater-item {
    display: flex;
    gap: 0.5rem;
}

.repeater-item input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
}

.repeater-item input:focus {
    outline: none;
    border-color: var(--primary);
}

.repeater-item .btn-remove {
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius);
}

.repeater-item .btn-remove:hover {
    color: var(--danger);
    background: rgba(220, 38, 38, 0.08);
}

.select-and-add {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.select-and-add select {
    flex: 1;
    min-width: 0;
}

.repeater-items--named .repeater-item {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.5rem;
    align-items: center;
}

.repeater-items--named .repeater-item input.repeater-name {
    min-width: 0;
}

#addCharacteristic {
    margin-top: 0.25rem;
}

/* Sidebar toggle (visible solo en móvil) */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 101;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    color: var(--text);
}

.sidebar-toggle-icon {
    width: 20px;
    height: 2px;
    background: currentColor;
    box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

.sidebar-close {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 98;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar-toggle {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 99;
        width: 260px;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
        box-shadow: none;
    }

    .dashboard.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,.15);
    }

    .sidebar-close {
        display: flex;
    }

    .sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .dashboard.sidebar-open .sidebar-overlay {
        display: block;
    }

    .main {
        padding: 1rem;
        padding-top: 3.5rem;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
    }

    .section-header .btn {
        width: 100%;
    }

    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-table {
        min-width: 600px;
        font-size: 0.85rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.6rem 0.75rem;
    }

    .data-table .thumb {
        width: 36px;
        height: 36px;
    }

    .modal {
        padding: 12px;
        align-items: flex-start;
    }

    .modal-content {
        max-height: calc(100vh - 24px);
        padding: 1rem;
    }

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

    .repeater-items--named .repeater-item {
        grid-template-columns: 1fr auto;
    }

    .repeater-items--named .repeater-item input.repeater-name {
        grid-column: 1 / -1;
    }

    .toast-container {
        left: 0.75rem;
        right: 0.75rem;
        top: auto;
        bottom: 1rem;
    }

    .toast {
        max-width: none;
    }

    .catalog-settings {
        max-width: none;
    }

    .file-select-row {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 1.5rem;
    }

    .main {
        padding: 0.75rem;
        padding-top: 3.25rem;
    }

    .data-table {
        min-width: 500px;
    }

    .select-and-add {
        flex-direction: column;
        align-items: stretch;
    }
}
