/* ═══════════════════════════════════════════
   Zenegy Sales Platform — Design System
   Based on Figma: Zenegy Organization
   ═══════════════════════════════════════════ */

/* ─── Fonts ─── */
@font-face { font-family: 'PP Neue Montreal'; src: local('PP Neue Montreal'); font-weight: 400 800; }

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

/* ─── CSS Variables ─── */
:root {
    /* Font */
    --f: 'PP Neue Montreal', 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Purple scale */
    --pur: #6e30fd;
    --pur-h: #5b22e0;
    --pur-m: #9b6dff;
    --pur-l: #ebe6ff;
    --pur-u: #f5f2ff;

    /* Status colors */
    --grn: #22c55e;
    --grn-l: #dcfce7;
    --red: #ef4444;
    --red-l: #fef2f2;
    --amb: #f59e0b;
    --amb-l: #fffbeb;
    --blue: #3b82f6;
    --blue-l: #eff6ff;

    /* Neutrals */
    --bg-0: #ffffff;
    --bg-1: #f9fafb;
    --bg-2: #f3f4f6;
    --bg-3: #e5e7eb;
    --bor: #e5e7eb;
    --bor-l: #f3f4f6;
    --tx-1: #111827;
    --tx-2: #4b5563;
    --tx-3: #9ca3af;
    --tx-4: #d1d5db;

    /* Radii */
    --r: 12px;
    --r-sm: 8px;
    --r-xs: 6px;
    --r-pill: 96px;

    /* Shadows */
    --sh-sm: 0 1px 2px rgba(0,0,0,.05);
    --sh: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --sh-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.04);
    --sh-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);

    /* Sidebar */
    --sidebar-w: 209px;
    --topbar-h: 52px;
}

/* ─── Dark Theme ─── */
[data-theme="dark"] {
    --bg-0: #111827;
    --bg-1: #0f172a;
    --bg-2: #1e293b;
    --bg-3: #334155;
    --bor: #1e293b;
    --bor-l: #1e293b;
    --tx-1: #f1f5f9;
    --tx-2: #94a3b8;
    --tx-3: #64748b;
    --tx-4: #475569;
    --pur-l: rgba(110,48,253,.15);
    --pur-u: rgba(110,48,253,.08);
    --grn-l: rgba(34,197,94,.12);
    --red-l: rgba(239,68,68,.12);
    --amb-l: rgba(245,158,11,.12);
    --blue-l: rgba(59,130,246,.12);
    --sh-sm: 0 1px 2px rgba(0,0,0,.2);
    --sh: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --sh-md: 0 4px 6px -1px rgba(0,0,0,.3), 0 2px 4px -2px rgba(0,0,0,.2);
    --sh-lg: 0 10px 15px -3px rgba(0,0,0,.3), 0 4px 6px -4px rgba(0,0,0,.2);
    color-scheme: dark;
}
[data-theme="dark"] .sidebar { background: #0c1222; border-color: #1e293b; }
[data-theme="dark"] .sidebar-logo img { filter: brightness(0) invert(1); opacity: .85; }
[data-theme="dark"] .topbar { background: #111827; border-color: #1e293b; }
[data-theme="dark"] .form-input { background: #1e293b; border-color: #334155; color: #f1f5f9; }
[data-theme="dark"] .form-input:focus { border-color: var(--pur); }
[data-theme="dark"] .btn-secondary { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .btn-ghost { color: #94a3b8; }
[data-theme="dark"] .btn-ghost:hover { background: #1e293b; color: #f1f5f9; }
[data-theme="dark"] .table th { background: #0f172a; border-color: #1e293b; }
[data-theme="dark"] .table td { border-color: #1e293b; }
[data-theme="dark"] .alert { background: #1e293b; border-color: #334155; }

/* ─── Base ─── */
html { height: 100%; }
body {
    font-family: var(--f);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--tx-1);
    background: var(--bg-1);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100%;
}
a { color: var(--pur); text-decoration: none; }
a:hover { color: var(--pur-h); }

/* ─── App Layout ─── */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-0);
    border-right: 1px solid var(--bor);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 100;
}
.sidebar-logo {
    padding: 24px 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-logo img { height: 22px; }
.sidebar-logo .logo-icon {
    width: 28px;
    height: 28px;
    background: var(--pur);
    border-radius: var(--r-xs);
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-logo .logo-icon svg { width: 16px; height: 16px; color: #fff; }

.sidebar-nav { flex: 1; padding: 0 12px; }
.sidebar-nav-group { margin-bottom: 24px; }
.sidebar-nav-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--tx-3);
    padding: 0 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--r-sm);
    color: var(--tx-2);
    font-size: 14px;
    font-weight: 500;
    transition: all .15s;
    cursor: pointer;
    text-decoration: none;
}
.nav-item:hover { background: var(--bg-2); color: var(--tx-1); }
.nav-item.active {
    background: var(--pur-u);
    color: var(--pur);
    font-weight: 600;
}
.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke-width: 1.5;
}
.nav-item .badge-count {
    margin-left: auto;
    background: var(--red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--bor-l);
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background .15s;
}
.sidebar-user:hover { background: var(--bg-2); }
.sidebar-user .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--pur-l);
    color: var(--pur);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-user .user-info { overflow: hidden; }
.sidebar-user .user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--tx-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user .user-role {
    font-size: 11px;
    color: var(--tx-3);
}

/* ─── Main Content ─── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ─── Topbar ─── */
.topbar {
    height: var(--topbar-h);
    min-height: var(--topbar-h);
    background: var(--bg-0);
    border-bottom: 1px solid var(--bor);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right .btn-icon {
    width: 36px; height: 36px;
    border-radius: var(--r-sm);
    border: 1px solid var(--bor);
    background: var(--bg-0);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .15s;
    color: var(--tx-2);
}
.topbar-right .btn-icon:hover { background: var(--bg-2); color: var(--tx-1); }

/* ─── Content Area ─── */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
}

/* ─── Page Header ─── */
.page-header {
    margin-bottom: 28px;
}
.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--tx-1);
    line-height: 1.2;
}
.page-header .subtitle {
    font-size: 14px;
    color: var(--tx-3);
    margin-top: 4px;
}
.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

/* ─── Cards ─── */
.card {
    background: var(--bg-0);
    border: 1px solid var(--bor);
    border-radius: var(--r);
    padding: 20px;
    transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--sh); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--tx-1);
}
.card-subtitle {
    font-size: 13px;
    color: var(--tx-3);
    margin-top: 2px;
}

/* ─── KPI Cards ─── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.kpi-card {
    background: var(--bg-0);
    border: 1px solid var(--bor);
    border-radius: var(--r);
    padding: 20px;
}
.kpi-label {
    font-size: 13px;
    color: var(--tx-3);
    font-weight: 500;
    margin-bottom: 8px;
}
.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--tx-1);
    line-height: 1;
}
.kpi-unit {
    font-size: 14px;
    font-weight: 500;
    color: var(--tx-3);
    margin-left: 4px;
}
.kpi-change {
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.kpi-change.up { color: var(--grn); }
.kpi-change.down { color: var(--red); }

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--r-sm);
    font-family: var(--f);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .2s cubic-bezier(.16,1,.3,1);
    white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
    background: var(--pur);
    color: #fff;
}
.btn-primary:hover {
    background: var(--pur-h);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(110,48,253,.25);
}

.btn-secondary {
    background: var(--bg-0);
    color: var(--tx-1);
    border: 1px solid var(--bor);
}
.btn-secondary:hover { background: var(--bg-2); }

.btn-ghost {
    background: transparent;
    color: var(--tx-2);
}
.btn-ghost:hover { background: var(--bg-2); color: var(--tx-1); }

.btn-danger {
    background: var(--red);
    color: #fff;
}
.btn-danger:hover { background: #dc2626; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* ─── Form Controls ─── */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--tx-2);
    margin-bottom: 6px;
}
.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--bor);
    border-radius: var(--r-sm);
    font-family: var(--f);
    font-size: 14px;
    font-weight: 500;
    color: var(--tx-1);
    background: var(--bg-0);
    transition: border-color .15s, box-shadow .15s;
}
.form-input:focus {
    outline: none;
    border-color: var(--pur);
    box-shadow: 0 0 0 3px var(--pur-l);
}
.form-input::placeholder { color: var(--tx-4); }
.form-input.error { border-color: var(--red); }
.form-hint {
    font-size: 12px;
    color: var(--tx-3);
    margin-top: 4px;
}
.form-error {
    font-size: 12px;
    color: var(--red);
    margin-top: 4px;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

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

/* ─── Tables ─── */
.table-wrap {
    background: var(--bg-0);
    border: 1px solid var(--bor);
    border-radius: var(--r);
    overflow: hidden;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
    color: var(--tx-3);
    padding: 12px 16px;
    border-bottom: 1px solid var(--bor);
    background: var(--bg-1);
}
.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--bor-l);
    font-size: 14px;
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-1); }

/* ─── Badges ─── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--r-pill);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-purple { background: var(--pur-u); color: var(--pur); }
.badge-green { background: var(--grn-l); color: #16a34a; }
.badge-red { background: var(--red-l); color: var(--red); }
.badge-amber { background: var(--amb-l); color: #d97706; }
.badge-blue { background: var(--blue-l); color: var(--blue); }
.badge-gray { background: var(--bg-2); color: var(--tx-2); }

/* ─── Alerts / Toasts ─── */
.alert {
    padding: 12px 16px;
    border-radius: var(--r-sm);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-success { background: var(--grn-l); color: #16a34a; border: 1px solid #bbf7d0; }
.alert-error { background: var(--red-l); color: var(--red); border: 1px solid #fecaca; }
.alert-warning { background: var(--amb-l); color: #d97706; border: 1px solid #fde68a; }
.alert-info { background: var(--blue-l); color: var(--blue); border: 1px solid #bfdbfe; }

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--r-sm);
    background: var(--tx-1);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--sh-lg);
    animation: toastIn .3s ease;
    max-width: 400px;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Grid helpers ─── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.flex { display: flex; }
.flex-center { align-items: center; }
.flex-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }

/* ─── Status dot ─── */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.active { background: var(--grn); }
.status-dot.inactive { background: var(--tx-4); }

/* ─── Empty state ─── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--tx-3);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: .4; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--tx-2); margin-bottom: 4px; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ─── Login Page ─── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-1);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-0);
    border: 1px solid var(--bor);
    border-radius: var(--r);
    padding: 40px 32px;
    box-shadow: var(--sh-md);
}
.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo img { height: 24px; }
.login-title {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}
.login-subtitle {
    font-size: 14px;
    color: var(--tx-3);
    text-align: center;
    margin-bottom: 28px;
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all .2s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
    background: var(--bg-0);
    border-radius: var(--r);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--sh-lg);
    transform: translateY(10px);
    transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--bor);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--bor);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ─── Wizard ─── */
.wizard-progress { margin-bottom: 24px; }
.wizard-steps { display: flex; gap: 4px; margin-bottom: 12px; overflow-x: auto; }
.wizard-step {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 16px; border-radius: var(--rb);
    border: 1px solid var(--bor); background: var(--bg-1);
    font-size: 13px; font-weight: 500; color: var(--tx-3);
    cursor: pointer; white-space: nowrap; font-family: var(--f);
    transition: all .15s;
}
.wizard-step:hover { border-color: var(--pur-m); color: var(--tx-1); }
.wizard-step.active { background: var(--pur); color: #fff; border-color: var(--pur); }
.wizard-step.done { background: var(--pur-u); color: var(--pur); border-color: var(--pur-l); }
.step-num {
    width: 22px; height: 22px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    background: var(--bg-2); color: var(--tx-3);
}
.wizard-step.active .step-num { background: rgba(255,255,255,.2); color: #fff; }
.wizard-step.done .step-num { background: var(--pur); color: #fff; }
.wizard-bar { height: 3px; background: var(--bor-l); border-radius: 3px; overflow: hidden; }
.wizard-bar-fill { height: 100%; background: var(--pur); border-radius: 3px; transition: width .3s ease; width: 0; }
.wizard-panel { display: none; }
.wizard-panel.active { display: block; animation: fadeUp .25s ease; }
.wizard-nav { display: flex; gap: 12px; margin-top: 24px; align-items: center; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Product cards ─── */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.product-card input { display: none; }
.product-card-inner {
    padding: 20px; border-radius: var(--r); border: 2px solid var(--bor);
    cursor: pointer; transition: all .15s; text-align: center;
}
.product-card-inner:hover { border-color: var(--pur-m); }
.product-card input:checked + .product-card-inner {
    border-color: var(--pur); background: var(--pur-u);
}
.product-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 12px;
}
.product-name { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.product-desc { font-size: 12px; color: var(--tx-3); }

/* ─── Battlecard select ─── */
.battlecard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.battlecard-select input { display: none; }
.battlecard-select-inner {
    padding: 16px; border-radius: var(--r); border: 2px solid var(--bor);
    cursor: pointer; transition: all .15s;
}
.battlecard-select-inner:hover { border-color: var(--pur-m); }
.battlecard-select input:checked + .battlecard-select-inner {
    border-color: var(--pur); background: var(--pur-u);
}

/* ─── Preview ─── */
.preview-section { padding: 16px 0; border-bottom: 1px solid var(--bor-l); }
.preview-section:last-child { border-bottom: none; }
.preview-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--tx-3); font-weight: 600; margin-bottom: 4px; }
.preview-value { font-size: 14px; font-weight: 500; }

/* ─── Table ─── */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--tx-3); background: var(--bg-2); border-bottom: 1px solid var(--bor); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--bor-l); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-2); }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .content { padding: 16px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .page-header-row { flex-direction: column; align-items: flex-start; }
    .wizard-steps { gap: 2px; }
    .wizard-step { padding: 6px 10px; font-size: 12px; }
    .product-grid { grid-template-columns: 1fr 1fr; }
    .table { font-size: 13px; }
    .table th, .table td { padding: 8px 12px; }
}
