@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Geist:wght@300;400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-base:        #f7f7f5;
    --bg-surface:     #ffffff;
    --bg-muted:       #f2f2f0;
    --bg-hover:       #f0f0ee;
    --border:         #e8e8e5;
    --border-strong:  #d4d4d0;
    --accent:         #4f46e5;
    --accent-light:   #ede9fe;
    --accent-hover:   #4338ca;
    --success:        #16a34a;
    --success-light:  #dcfce7;
    --warning:        #d97706;
    --warning-light:  #fef3c7;
    --danger:         #dc2626;
    --danger-light:   #fee2e2;
    --purple:         #7c3aed;
    --purple-light:   #ede9fe;
    --text-primary:   #1a1a1a;
    --text-secondary: #6b7280;
    --text-muted:     #9ca3af;
    --sidebar-w:      220px;
    --radius:         8px;
    --radius-sm:      5px;
    --shadow-sm:      0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow:         0 4px 16px rgba(0,0,0,0.08);
}

html, body {
    height: 100%;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: 'Geist', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── LAYOUT ───────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ── SIDEBAR ──────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    padding-bottom: 20px;
}

.sidebar-brand {
    padding: 18px 16px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
}

.brand-name {
    font-family: 'Geist', sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
    letter-spacing: 0.3px;
}

.sidebar-nav { flex: 1; padding: 6px 10px; overflow-y: auto; }

.nav-section-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 14px 6px 5px;
    font-weight: 500;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 400;
    transition: all 0.12s;
    margin-bottom: 1px;
    cursor: pointer;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 500;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 25%; bottom: 25%;
    width: 2.5px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

.nav-icon {
    width: 15px; height: 15px;
    opacity: 0.65;
    flex-shrink: 0;
}

.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
    padding: 10px 10px 0;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-muted);
}

.user-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

.user-name { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.user-role { font-size: 11px; color: var(--text-muted); }

.signout-link {
    display: block;
    text-align: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.signout-link:hover { color: var(--danger); }

/* ── MAIN ─────────────────────────────────────────── */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: 52px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    background: var(--bg-surface);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.page-content { padding: 28px; flex: 1; max-width: 1200px; }

/* ── PAGE HEADER ──────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.back-link {
    font-size: 13px;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.back-link:hover { color: var(--text-primary); }

/* ── STATS ────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: box-shadow 0.15s;
}

.stat-card:hover { box-shadow: var(--shadow-sm); }

.stat-label {
    font-size: 11.5px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.stat-value {
    font-family: 'DM Mono', monospace;
    font-size: 26px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1;
}

.stat-pill {
    display: inline-block;
    margin-top: 8px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 500;
}

/* ── CARD ─────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.card + .card { margin-top: 16px; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.1px;
}

/* ── TABLE ────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }

.data-table th {
    text-align: left;
    padding: 9px 14px;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
    background: var(--bg-muted);
}

.data-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.data-table th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13.5px;
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-muted); }
.data-table td.td-primary { color: var(--text-primary); font-weight: 500; }

/* ── BUTTONS ──────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-family: 'Geist', sans-serif;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.12s;
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--bg-muted); color: var(--text-primary); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 10px; }

/* ── BADGES ───────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-new       { background: #dbeafe; color: #1d4ed8; }
.badge-contacted { background: var(--purple-light); color: var(--purple); }
.badge-follow_up { background: var(--warning-light); color: var(--warning); }
.badge-qualified { background: var(--success-light); color: var(--success); }
.badge-won       { background: var(--success-light); color: var(--success); }
.badge-lost      { background: var(--danger-light);  color: var(--danger); }
.badge-low       { background: var(--bg-muted); color: var(--text-muted); }
.badge-medium    { background: var(--warning-light); color: var(--warning); }
.badge-high      { background: var(--danger-light);  color: var(--danger); }

/* ── FORMS ────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.span-2 { grid-column: span 2; }

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 8px 11px;
    font-family: 'Geist', sans-serif;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.12s, box-shadow 0.12s;
    width: 100%;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.form-group textarea { resize: vertical; min-height: 88px; }

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

/* ── FILTER TABS ──────────────────────────────────── */
.filter-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.filter-tab {
    padding: 7px 14px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.12s;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-weight: 400;
}

.filter-tab:hover { color: var(--text-primary); }

.filter-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 500;
}

/* ── SEARCH ───────────────────────────────────────── */
.search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
}

.search-input {
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 7px 12px;
    font-family: 'Geist', sans-serif;
    font-size: 13.5px;
    outline: none;
    width: 260px;
    transition: border-color 0.12s, box-shadow 0.12s;
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.search-input::placeholder { color: var(--text-muted); }

/* ── ALERTS ───────────────────────────────────────── */
.alert {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 18px;
    border-left: 3px solid;
}

.alert-error   { background: var(--danger-light);  color: #991b1b; border-color: var(--danger); }
.alert-success { background: var(--success-light); color: #14532d; border-color: var(--success); }

/* ── PRODUCT TILES ────────────────────────────────── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.product-tile {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.product-tile:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.product-icon {
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    font-family: 'Geist', sans-serif;
}

.product-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.product-arrow {
    font-size: 16px;
    color: var(--text-muted);
    margin-top: auto;
    transition: color 0.12s, transform 0.12s;
}

.product-tile:hover .product-arrow {
    color: var(--accent);
    transform: translateX(3px);
}

/* ── TIMELINE ─────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }

.timeline-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.timeline-item:last-child { border-bottom: none; }

.timeline-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    margin-top: 7px;
    flex-shrink: 0;
    background: var(--accent);
}

.timeline-dot.t-note     { background: var(--purple); }
.timeline-dot.t-status   { background: var(--warning); }
.timeline-dot.t-followup { background: var(--success); }
.timeline-dot.t-created  { background: var(--accent); }
.timeline-dot.t-edited   { background: var(--text-muted); }

.t-desc { font-size: 13.5px; color: var(--text-primary); }
.t-time { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ── DETAIL VIEW ──────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
}

.detail-row:last-child { border-bottom: none; }
.detail-key   { color: var(--text-muted); font-size: 12.5px; }
.detail-value { color: var(--text-primary); font-weight: 500; }

/* ── EMPTY STATE ──────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    font-size: 13.5px;
}

/* ── AUTH ─────────────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-base);
    background-image: radial-gradient(circle at 20% 50%, rgba(79,70,229,0.04) 0%, transparent 60%),
                      radial-gradient(circle at 80% 20%, rgba(124,58,237,0.03) 0%, transparent 50%);
}

.auth-card {
    width: 360px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px;
    box-shadow: var(--shadow);
}

.auth-brand {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.auth-brand-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.auth-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 28px;
}

.auth-card .form-group { margin-bottom: 14px; }

/* ── SCROLLBAR ────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ── RESPONSIVE ───────────────────────────────────── */
@media (max-width: 768px) {

    /* Hide sidebar, show topbar as full nav */
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-brand {
        flex: 1;
        border-bottom: none;
        padding: 12px 16px;
    }

    .sidebar-nav {
        display: none;
    }

    .sidebar-footer {
        border-top: none;
        padding: 8px 12px;
    }

    .user-chip {
        background: transparent;
        padding: 4px 0;
    }

    .signout-link {
        display: none;
    }

    /* Main content fills full width */
    .main {
        margin-left: 0;
    }

    .app-layout {
        flex-direction: column;
    }

    /* Topbar */
    .topbar {
        padding: 0 16px;
    }

    /* Page content padding reduced */
    .page-content {
        padding: 16px;
    }

    /* Products stack single column */
    .products-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Stats grid 2 columns on mobile */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    /* Form grid single column */
    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group.span-2 {
        grid-column: span 1;
    }

    /* Detail grid single column */
    .detail-grid {
        grid-template-columns: 1fr;
    }

    /* Table horizontal scroll */
    .card {
        overflow-x: auto;
    }

    /* Page header stack */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    /* Auth card full width */
    .auth-card {
        width: 100%;
        margin: 16px;
        padding: 24px;
    }

    /* Filter tabs scroll horizontally */
    .filter-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .product-card-name {
        font-size: 15px;
    }

    .topbar-title {
        font-size: 13px;
    }
}
/* ── MOBILE NAV TOGGLE ────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: column;
        padding: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-brand {
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: none;
        padding: 14px 16px;
    }

    .sidebar-nav {
        display: none;
        padding: 8px 12px 4px;
        border-top: 1px solid var(--border);
    }

    .sidebar-nav.open { display: block; }

    .sidebar-footer {
        display: none;
        border-top: 1px solid var(--border);
        padding: 10px 12px;
    }

    .sidebar-footer.open { display: block; }

    .hamburger {
        display: flex;
        flex-direction: column;
        gap: 5px;
        cursor: pointer;
        padding: 4px;
        background: none;
        border: none;
    }

    .hamburger span {
        display: block;
        width: 22px;
        height: 2px;
        background: var(--text-secondary);
        border-radius: 2px;
        transition: all 0.2s;
    }

    .hamburger.open span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }

    .hamburger.open span:nth-child(2) {
        opacity: 0;
    }

    .hamburger.open span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    .main { margin-left: 0; }
    .app-layout { flex-direction: column; }
}

@media (min-width: 769px) {
    .hamburger { display: none; }
}