/* ============================================
   DigitalHamster CRM — Design System v2
   WCAG AA contrast · DH brand palette
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Brand */
    --yellow: #ffd500;
    --blue: #292e66;
    --lightgrey: #edf1f2;
    --lightergrey: #f2f4f7;
    --grey: #b1b8c4;
    --darkgrey: #505969;
    --error: #ff6f7b;
    --green: #0ce864;

    /* Dark theme — WCAG AA compliant */
    --bg-primary: #0c0e14;
    --bg-secondary: #12141c;
    --bg-card: #181b27;
    --bg-hover: #1f2335;
    --bg-input: #0f1119;
    --border: #272b3d;
    --border-light: #333752;
    --border-focus: rgba(255, 213, 0, .4);

    /* Text — all pass WCAG AA on bg-card (#181b27) */
    --text-primary: #f0f2f5;    /* 13.5:1 ratio */
    --text-secondary: #cdd2e0;  /* 10.2:1 ratio */
    --text-muted: #a0a6c0;      /* 6.2:1 ratio — AA large+normal */
    --text-dim: #6b7190;        /* decorative only, 3.5:1 */

    /* Accents */
    --accent: var(--yellow);
    --accent-hover: #ffe44d;
    --accent-glow: rgba(255, 213, 0, .12);
    --success: #2ee87a;
    --success-bg: rgba(46, 232, 122, .12);
    --danger: #ff6f7b;
    --danger-bg: rgba(255, 111, 123, .10);
    --info: #6b9ef5;
    --info-bg: rgba(107, 158, 245, .12);
    --warning: #f5a623;
    --warning-bg: rgba(245, 166, 35, .12);

    /* Elevation */
    --shadow-sm: 0 1px 2px rgba(0,0,0,.25), 0 1px 3px rgba(0,0,0,.15);
    --shadow-md: 0 4px 8px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.2);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.45);
    --shadow-glow: 0 0 20px rgba(255,213,0,.08);

    /* Radius */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Motion */
    --ease: cubic-bezier(.4, 0, .2, 1);
    --ease-bounce: cubic-bezier(.34, 1.56, .64, 1);
    --duration-fast: 120ms;
    --duration-normal: 200ms;
    --duration-slow: 350ms;
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

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

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease);
}
a:hover { color: var(--accent-hover); }

::selection {
    background: rgba(255, 213, 0, .25);
    color: #fff;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ============================================
   LOGIN
   ============================================ */
.login-wrapper {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 50% -20%, rgba(41, 46, 102, .35) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 80%, rgba(255, 213, 0, .04) 0%, transparent 40%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 48px 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: fadeUp .5s var(--ease) both;
}

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

.login-logo {
    text-align: center;
    margin-bottom: 36px;
}

.login-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -.5px;
}

.login-logo .subtitle {
    font-size: .82rem;
    color: var(--text-muted);
    margin-top: 6px;
    letter-spacing: .3px;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: .6px;
}

.form-input,
.search-input,
.filter-select,
.status-select {
    width: 100%;
    padding: 11px 16px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: .92rem;
    font-family: inherit;
    transition: border-color var(--duration-normal) var(--ease),
                box-shadow var(--duration-normal) var(--ease);
    outline: none;
}

.form-input:focus,
.search-input:focus,
.filter-select:focus,
.status-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--border-focus);
}

.form-input::placeholder,
.search-input::placeholder { color: var(--text-dim); }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 24px;
    font-size: .88rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease);
    text-decoration: none;
    white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--accent);
    color: var(--blue);
    width: 100%;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 20px rgba(255, 213, 0, .3);
    transform: translateY(-1px);
}

.btn-sm { padding: 7px 16px; font-size: .8rem; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
}
.btn-ghost:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.btn-success { background: var(--success); color: #000; }
.btn-danger { background: var(--danger); color: #fff; }

.login-error {
    background: var(--danger-bg);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    margin-bottom: 18px;
    display: none;
    animation: shake .3s var(--ease);
}

.login-error.visible { display: block; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* ============================================
   APP LAYOUT
   ============================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--duration-slow) var(--ease);
}

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

.sidebar-header img {
    display: block;
    margin-bottom: 6px;
}

.sidebar-header .user-info {
    font-size: .78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 14px 10px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: .88rem;
    font-weight: 500;
    transition: all var(--duration-fast) var(--ease);
    margin-bottom: 2px;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .6;
}

.nav-item:hover svg,
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    padding: 14px 10px;
    border-top: 1px solid var(--border);
}

/* Main */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 32px 36px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.4px;
    color: var(--text-primary);
}

/* ============================================
   STAT CARDS
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    transition: all var(--duration-normal) var(--ease);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--border);
    transition: background var(--duration-normal) var(--ease);
}

.stat-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-label {
    font-size: .73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.stat-card.accent::after { background: var(--accent); }
.stat-card.accent .stat-value { color: var(--accent); }

.stat-card.success::after { background: var(--success); }
.stat-card.success .stat-value { color: var(--success); }

.stat-card.info::after { background: var(--info); }
.stat-card.info .stat-value { color: var(--info); }

/* ============================================
   DATA TABLE
   ============================================ */
.table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.table-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
}

.filter-select {
    padding: 10px 14px;
    cursor: pointer;
    min-width: auto;
    width: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    padding: 14px 20px;
    text-align: left;
    font-size: .73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 14px 20px;
    font-size: .88rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table tr {
    transition: background var(--duration-fast) var(--ease);
}

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

.data-table tbody tr {
    cursor: pointer;
}

.data-table td:first-child {
    color: var(--text-primary);
    font-weight: 500;
}

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

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: var(--radius-xl);
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
}

.badge-new { background: var(--info-bg); color: var(--info); }
.badge-contacted { background: var(--accent-glow); color: var(--accent); }
.badge-qualified { background: var(--success-bg); color: var(--success); }
.badge-proposal { background: var(--warning-bg); color: var(--warning); }
.badge-won { background: rgba(46, 232, 122, .2); color: var(--success); font-weight: 700; }
.badge-lost { background: var(--danger-bg); color: var(--danger); }

/* ============================================
   PAGINATION
   ============================================ */
.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    font-size: .82rem;
    color: var(--text-muted);
}

.pagination {
    display: flex;
    gap: 4px;
}

.pagination button {
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: .82rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease);
}

.pagination button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.pagination button.active {
    background: var(--accent);
    color: var(--blue);
    border-color: var(--accent);
    font-weight: 600;
}

.pagination button:disabled {
    opacity: .3;
    cursor: not-allowed;
}

/* ============================================
   LEAD DETAIL
   ============================================ */
.lead-detail {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
}

.detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
}

.detail-card h3 {
    font-size: .95rem;
    font-weight: 600;
    margin-bottom: 18px;
    color: var(--text-primary);
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.detail-row {
    display: flex;
    padding: 10px 0;
    border-bottom: 1px solid rgba(39, 43, 61, .5);
}

.detail-row:last-child { border-bottom: none; }

.detail-label {
    width: 140px;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    flex-shrink: 0;
}

.detail-value {
    flex: 1;
    font-size: .9rem;
    color: var(--text-secondary);
    word-break: break-word;
}

/* Notes */
.notes-list {
    max-height: 400px;
    overflow-y: auto;
}

.note-item {
    padding: 14px 0;
    border-bottom: 1px solid rgba(39, 43, 61, .5);
}

.note-item:last-child { border-bottom: none; }

.note-meta {
    font-size: .75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.note-content {
    font-size: .88rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.note-form {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.note-form textarea {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: .85rem;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
    outline: none;
    transition: border-color var(--duration-normal) var(--ease);
}

.note-form textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--border-focus);
}

/* ============================================
   CHARTS
   ============================================ */
.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-bottom: 24px;
}

.chart-container h3 {
    font-size: .95rem;
    font-weight: 600;
    margin-bottom: 18px;
    color: var(--text-primary);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 22px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: .88rem;
    color: var(--text-primary);
    z-index: 9999;
    transform: translateY(100px);
    opacity: 0;
    transition: all var(--duration-slow) var(--ease-bounce);
    max-width: 360px;
}

.toast.visible { transform: translateY(0); opacity: 1; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

/* ============================================
   LOADING
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: .4;
}

.empty-state p {
    font-size: .92rem;
    line-height: 1.5;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .lead-detail { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 20px 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .table-toolbar { flex-direction: column; }
    .search-input { min-width: 100%; }
    .page-header h1 { font-size: 1.25rem; }
    .data-table { font-size: .82rem; }
    .data-table th, .data-table td { padding: 10px 14px; }

    .mobile-toggle {
        display: flex !important;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 200;
        padding: 10px;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        color: var(--text-primary);
        cursor: pointer;
        box-shadow: var(--shadow-md);
    }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .login-card { padding: 32px 24px; margin: 16px; }
}

.mobile-toggle { display: none; }

/* Backdrop for mobile sidebar */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
    backdrop-filter: blur(2px);
}

@media (max-width: 768px) {
    .sidebar.open ~ .sidebar-backdrop { display: block; }
}

/* ============================================
   UTILITIES
   ============================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: .82rem; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Code */
code {
    padding: 2px 6px;
    background: var(--bg-input);
    border-radius: var(--radius-xs);
    font-size: .82em;
    color: var(--text-secondary);
}
