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

:root {
    --primary: #1a1a2e;
    --primary-light: #16213e;
    --accent: #e94560;
    --accent-hover: #c73e54;
    --success: #0f9b58;
    --warning: #f5a623;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 12px;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Header */
.app-header {
    background: var(--primary);
    color: white;
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-left h1 { font-size: 24px; font-weight: 700; }
.header-season { color: var(--accent); }
.header-subtitle { font-size: 13px; color: #9ca3af; margin-top: 2px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.collection-filter { display: flex; align-items: center; gap: 8px; }
.collection-filter label { font-size: 13px; color: #9ca3af; }
.collection-filter select {
    background: var(--primary-light);
    color: white;
    border: 1px solid #374151;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
}

/* Tabs */
.tabs {
    background: white;
    display: flex;
    border-bottom: 2px solid var(--border);
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.tab {
    padding: 14px 24px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.tab:hover { color: var(--text); background: #f9fafb; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-icon { font-size: 16px; }
.tab-badge {
    background: var(--border);
    color: var(--text-light);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.tab.active .tab-badge { background: var(--accent); color: white; }

/* Tab content */
.tab-content { display: none; padding: 24px 32px; }
.tab-content.active { display: block; }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.search-box input {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    width: 280px;
    outline: none;
    transition: border 0.2s;
}
.search-box input:focus { border-color: var(--accent); }
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-group label { font-size: 12px; color: var(--text-light); font-weight: 600; text-transform: uppercase; }
.filter-group select {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: white;
}
.counter-info { margin-left: auto; font-size: 13px; color: var(--text-light); font-weight: 500; }

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 20px;
}

/* Model Card */
.model-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
    border: 2px solid transparent;
}
.model-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.model-card.has-selection { border-color: var(--accent); }

/* Card Header */
.card-header {
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header-left h3 { font-size: 14px; font-weight: 700; }
.card-header-left .model-name { font-size: 12px; color: #9ca3af; margin-top: 2px; }
.card-header-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.card-bubble {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
    line-height: 1.2;
}
.card-bubble-title {
    font-size: 8px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    opacity: 0.8;
    font-weight: 500;
}
.card-bubble-value {
    font-size: 12px;
    font-weight: 700;
}
.card-srp {
    background: var(--accent);
    color: white;
}
.card-bubble-units {
    background: #3b82f6;
    color: white;
}
.card-bubble-revenue {
    background: #10b981;
    color: white;
}

/* Sort buttons */
.sort-buttons { display: flex; align-items: center; gap: 6px; }
.sort-label { font-size: 12px; color: var(--text-light); font-weight: 600; text-transform: uppercase; }
.btn-sort {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.15s;
}
.btn-sort:hover { border-color: var(--accent); color: var(--text); }
.btn-sort.active-asc { background: var(--primary); color: white; border-color: var(--primary); }
.btn-sort.active-desc { background: var(--accent); color: white; border-color: var(--accent); }
.card-collection-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    margin-left: 8px;
}
.badge-man { background: #3b82f6; color: white; }
.badge-jrb { background: #8b5cf6; color: white; }

/* Card Body */
.card-body { padding: 16px; }
.card-image-row {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}
.card-image {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
    background: #f3f4f6;
    flex-shrink: 0;
}
.card-image-placeholder {
    width: 100px;
    height: 100px;
    border-radius: 8px;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 11px;
    flex-shrink: 0;
}
.card-attrs {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.card-attr {
    display: flex;
    flex-direction: column;
}
.card-attr-label {
    font-size: 10px;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.card-attr-value {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card-attr-full { grid-column: 1 / -1; }
.card-attr-value.composition {
    white-space: normal;
    font-size: 11px;
    line-height: 1.3;
}

/* Card Footer - Colors */
.card-footer {
    border-top: 1px solid var(--border);
    padding: 12px 16px;
}
.card-footer-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-light);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.select-all-link {
    font-size: 11px;
    color: var(--accent);
    cursor: pointer;
    text-transform: none;
    font-weight: 500;
}
.select-all-link:hover { text-decoration: underline; }

.color-list { display: flex; flex-direction: column; gap: 6px; }
.color-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    background: #f9fafb;
    transition: background 0.15s;
}
.color-row:hover { background: #f0f2f5; }
.color-row.selected { background: #fef2f2; }

.color-checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}
.color-name { font-size: 13px; font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.color-stat {
    font-size: 11px;
    color: var(--text-light);
    text-align: right;
    white-space: nowrap;
}
.color-stat strong { color: var(--text); font-weight: 600; }

/* Push Button */
.card-actions {
    padding: 0 16px 12px;
    display: flex;
    gap: 8px;
}
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.btn-push {
    background: var(--accent);
    color: white;
    flex: 1;
    justify-content: center;
    opacity: 0.4;
    pointer-events: none;
}
.btn-push.active { opacity: 1; pointer-events: all; }
.btn-push:hover { background: var(--accent-hover); }
.btn-remove {
    background: #fee2e2;
    color: #dc2626;
}
.btn-remove:hover { background: #fecaca; }
.btn-danger {
    background: #fee2e2;
    color: #dc2626;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-danger:hover { background: #fecaca; }

/* Selected card variant */
.selected-card .card-header { background: var(--success); }
.selected-card .color-row { background: #f0fdf4; }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* Dashboard KPIs */
.kpi-banner {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.kpi-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    text-align: center;
}
.kpi-row { display: flex; justify-content: center; gap: 20px; margin-bottom: 6px; }
.kpi-col { display: flex; flex-direction: column; align-items: center; }
.kpi-label { font-size: 10px; color: var(--text-light); text-transform: uppercase; font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text); }
.kpi-value.highlight { color: var(--accent); }
.kpi-title { display: block; font-size: 11px; color: var(--text-light); font-weight: 600; text-transform: uppercase; margin-top: 4px; }
.kpi-subtitle { display: block; font-size: 10px; color: var(--text-light); }
.kpi-delta { font-size: 12px; font-weight: 600; }
.kpi-delta.positive { color: var(--success); }
.kpi-delta.negative { color: var(--accent); }

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}
.chart-container {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.chart-container h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.chart-container canvas { max-height: 350px; }

/* Detail Table */
.table-container {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    overflow-x: auto;
}
.table-container h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.detail-table th {
    background: var(--primary);
    color: white;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
}
.detail-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.detail-table tr:hover td { background: #f9fafb; }
.detail-table tr:nth-child(even) td { background: #fafbfc; }

/* Toggle / secondary toolbar */
.toolbar-secondary { border-top: 1px solid var(--border); padding-top: 12px; }
.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}
.toggle-label input { accent-color: var(--accent); width: 15px; height: 15px; }

/* Color swatch dot */
.color-swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.15);
    flex-shrink: 0;
    display: inline-block;
}

/* Selected indicator on card header */
.selected-indicator {
    font-size: 16px;
    margin-left: 6px;
}

/* Create button */
.btn-create {
    background: var(--success);
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-create:hover { background: #0d8a4e; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 500;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 720px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { transform: translateY(-20px); opacity: 0; } }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close {
    background: none; border: none; font-size: 24px; cursor: pointer;
    color: var(--text-light); line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* Form */
.modal-form { padding: 20px 24px; }
.form-row { display: flex; gap: 16px; margin-bottom: 14px; }
.form-row-colors { flex-wrap: wrap; }
.form-group { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.form-group-full { flex: 1 1 100%; }
.form-group label {
    font-size: 12px; font-weight: 600; color: var(--text-light);
    text-transform: uppercase; letter-spacing: 0.3px;
}
.form-group input, .form-group select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border 0.2s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); }
.readonly-field { background: #f3f4f6; color: var(--text-light); cursor: default; }
.auto-tag {
    background: #dbeafe;
    color: #2563eb;
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    font-weight: 700;
    margin-left: 4px;
}
.form-divider {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
    margin: 16px 0 12px;
    letter-spacing: 0.5px;
}
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.btn-cancel {
    background: #f3f4f6; color: var(--text); border: none; border-radius: 8px;
    padding: 10px 20px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-cancel:hover { background: #e5e7eb; }
.btn-save {
    background: var(--success); color: white; border: none; border-radius: 8px;
    padding: 10px 24px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-save:hover { background: #0d8a4e; }

/* Image upload */
.image-upload-area {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: 8px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s;
    overflow: hidden;
}
.image-upload-area:hover { border-color: var(--accent); }
.file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}
.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--text-light);
    font-size: 13px;
}
.upload-placeholder span:first-child { font-size: 28px; }
.image-preview {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 6px;
}

/* Color select with swatch preview */
.color-select { min-width: 140px; }

/* New model card variant */
.new-model-card .card-header { background: var(--success); }
.new-model-card .card-attr-value.pending { color: var(--warning); font-style: italic; }

/* Edit / Delete buttons for new models */
.btn-edit {
    background: #dbeafe; color: #2563eb; border: none; border-radius: 8px;
    padding: 8px 14px; font-size: 12px; font-weight: 600; cursor: pointer; flex: 1;
    text-align: center;
}
.btn-edit:hover { background: #bfdbfe; }
.btn-delete {
    background: #fee2e2; color: #dc2626; border: none; border-radius: 8px;
    padding: 8px 14px; font-size: 12px; font-weight: 600; cursor: pointer; flex: 1;
    text-align: center;
}
.btn-delete:hover { background: #fecaca; }

/* NOOS toggle */
.noos-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    cursor: pointer;
    user-select: none;
}
.noos-toggle input { display: none; }
.noos-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border: 1.5px solid #d1d5db;
    color: #9ca3af;
    background: white;
    transition: all 0.15s;
}
.noos-toggle input:checked + .noos-badge {
    background: #7c3aed;
    color: white;
    border-color: #7c3aed;
}

/* Export button */
.btn-export {
    background: #2563eb;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-export:hover { background: #1d4ed8; }
.toolbar-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* Responsive */
@media (max-width: 900px) {
    .cards-grid { grid-template-columns: 1fr; }
    .charts-row { grid-template-columns: 1fr; }
    .tab-content { padding: 16px; }
    .tabs { padding: 0 16px; overflow-x: auto; }
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--primary);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 1000;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2s forwards;
}
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* ---- LOGIN SCREEN ---- */
.login-overlay {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, var(--accent) 100%);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-header {
    text-align: center;
    margin-bottom: 2rem;
}
.login-header h1 {
    font-size: 2rem;
    color: var(--primary);
}
.login-header p {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-top: 0.3rem;
}
.login-field {
    margin-bottom: 1.2rem;
}
.login-field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.4rem;
}
.login-field input {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}
.login-field input:focus {
    outline: none;
    border-color: var(--accent);
}
.login-error {
    color: var(--accent);
    font-size: 0.85rem;
    min-height: 1.2rem;
    margin-bottom: 0.5rem;
    text-align: center;
}
.btn-login {
    width: 100%;
    padding: 0.8rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-login:hover {
    background: var(--accent-hover);
}

/* ---- USER INFO & LOGOUT ---- */
.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
    color: rgba(255,255,255,0.9);
    font-size: 0.85rem;
}
.btn-logout {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}
.btn-logout:hover {
    background: rgba(255,255,255,0.3);
}

/* ---- HISTORIAL TAB ---- */
#tab-historial .table-container {
    max-height: 70vh;
    overflow-y: auto;
}
#logsTable th, #logsTable td {
    font-size: 0.82rem;
    padding: 0.5rem 0.7rem;
}
#logsTable .action-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
}
.action-badge.select { background: var(--success); }
.action-badge.deselect { background: #ef4444; }
.action-badge.create { background: #3b82f6; }
.action-badge.update { background: #f59e0b; }
.action-badge.delete { background: #ef4444; }
.action-badge.noos { background: #8b5cf6; }
.action-badge.undo { background: #6b7280; }
.action-badge.clear { background: #dc2626; }
.btn-undo {
    padding: 3px 10px;
    font-size: 0.78rem;
    background: #f3f4f6;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-undo:hover { background: #e5e7eb; }
.btn-undo:disabled { opacity: 0.4; cursor: not-allowed; }
.logs-pagination .btn {
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
}
