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

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-hover: #f8fafc;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --accent: #8b5cf6;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --sidebar-w: 260px;
    --topbar-h: 56px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #1e3a5f;
    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border: #334155;
    --border-light: #1e293b;
    --danger-light: #3b1111;
    --success-light: #0d3320;
    --warning-light: #3b2f04;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
}

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

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform var(--transition);
}
.sidebar.hidden { display: none; }

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 800; font-size: 0.875rem;
    flex-shrink: 0;
}
.sidebar-title { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.sidebar-toggle { display: none; background: none; border: none; font-size: 1.5rem; color: var(--text-muted); cursor: pointer; margin-left: auto; }

/* ── Mode Switch ── */
.mode-switch {
    display: flex;
    margin: 1rem;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 3px;
}
.mode-btn {
    flex: 1;
    padding: 0.45rem 0;
    border: none;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: var(--text-muted);
    transition: all var(--transition);
}
.mode-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* ── Sidebar Nav ── */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.75rem;
}
.sidebar-nav .nav-section {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.75rem 0.75rem 0.35rem;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
}
.sidebar-nav a:hover { background: var(--primary-light); color: var(--primary); }
.sidebar-nav a.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sidebar-nav a .nav-icon { font-size: 1.1rem; width: 1.25rem; text-align: center; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-user { font-size: 0.8125rem; color: var(--text-secondary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }

/* ── Main Wrapper ── */
.main-wrapper {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    transition: margin-left var(--transition);
}
.main-wrapper.full { margin-left: 0; }

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar.hidden { display: none; }
.topbar-title { font-size: 1.05rem; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    margin-right: 0.75rem;
}
.hamburger span {
    width: 20px; height: 2px;
    background: var(--text);
    border-radius: 1px;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 36px; height: 36px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    color: var(--text-secondary);
    transition: all var(--transition);
}
.theme-toggle:hover { background: var(--primary-light); color: var(--primary); }

/* ── App Content ── */
#app {
    padding: 1.5rem;
    max-width: 1100px;
}

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.card-title { font-weight: 600; font-size: 1rem; }
.card-meta { font-size: 0.8125rem; color: var(--text-muted); line-height: 1.5; }
.card-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-green { background: var(--success-light); color: #065f46; }
.badge-gray { background: var(--border-light); color: var(--text-muted); }
.badge-blue { background: var(--primary-light); color: var(--primary); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1;
}
.btn:hover { background: var(--surface-hover); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-light); }
.btn-ghost { border: none; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.7rem 1.5rem; font-size: 0.9375rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Google Button ── */
.btn-google {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-weight: 500;
    padding: 0.6rem 1rem;
    width: 100%;
}
.btn-google:hover { background: var(--surface-hover); box-shadow: var(--shadow-sm); }
.btn-google svg { width: 18px; height: 18px; flex-shrink: 0; }

.divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.25rem 0;
    color: var(--text-muted);
    font-size: 0.8125rem;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text-secondary);
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"],
textarea, select {
    width: 100%;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
textarea { resize: vertical; min-height: 60px; }

/* ── Searchable Dropdown ── */
.search-select { position: relative; }
.search-select input { cursor: text; }
.search-select .dropdown {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 240px;
    overflow-y: auto;
    z-index: 300;
    display: none;
}
.search-select .dropdown.open { display: block; }
.search-select .dropdown-item {
    padding: 0.5rem 0.85rem;
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.search-select .dropdown-item:hover { background: var(--primary-light); }
.search-select .dropdown-item.selected { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.search-select .dropdown-empty { padding: 0.75rem; color: var(--text-muted); font-size: 0.8125rem; text-align: center; }

/* ── Tags/Pills Input ── */
.tags-input-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: text;
    min-height: 38px;
    align-items: center;
    transition: border-color var(--transition);
}
.tags-input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.55rem;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    font-size: 0.8125rem;
    font-weight: 500;
}
.tag-pill .tag-remove {
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    opacity: 0.7;
}
.tag-pill .tag-remove:hover { opacity: 1; }
.tags-input-wrapper input {
    border: none;
    outline: none;
    padding: 0.2rem 0;
    font-size: 0.875rem;
    flex: 1;
    min-width: 80px;
    background: transparent;
    box-shadow: none;
}
.tags-input-wrapper input:focus { box-shadow: none; }

/* ── Range Slider ── */
.range-group { position: relative; }
.range-values {
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.range-inputs {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}
.range-inputs input[type="number"] { width: 120px; }
.range-inputs .range-sep { color: var(--text-muted); font-weight: 500; }

/* ── Utilities ── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.page-header h2 { font-size: 1.25rem; font-weight: 700; }
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}
.empty-state h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--text-secondary); }

.error { color: var(--danger); font-size: 0.875rem; margin-top: 0.5rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; }

.stat-card { text-align: center; padding: 1.25rem; }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }

.section-title {
    font-size: 0.9375rem;
    font-weight: 700;
    margin: 1.5rem 0 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* ── Modal ── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 500;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 1.75rem;
    width: 90%;
    max-width: 580px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: 1.25rem; font-size: 1.125rem; }
.modal-actions {
    display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem;
}

/* ── Extension Link Code ── */
.link-code {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-align: center;
    padding: 1rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 2px dashed var(--border);
    color: var(--primary);
    user-select: all;
}

/* ── Auth Pages (full-width, no sidebar) ── */
.auth-container {
    max-width: 420px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
}
.auth-container .auth-header {
    text-align: center;
    margin-bottom: 2rem;
}
.auth-container .auth-header .auth-logo {
    width: 56px; height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-lg);
    display: inline-flex; align-items: center; justify-content: center;
    color: white; font-weight: 800; font-size: 1.25rem;
    margin-bottom: 1rem;
}
.auth-container .auth-header h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.25rem; }
.auth-container .auth-header p { color: var(--text-muted); font-size: 0.9375rem; }

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}
.auth-footer a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-footer a:hover { text-decoration: underline; }

/* ── Tables ── */
.data-table {
    width: 100%;
    font-size: 0.8125rem;
    border-collapse: collapse;
}
.data-table thead tr { border-bottom: 2px solid var(--border); }
.data-table th { padding: 0.6rem 0.75rem; text-align: left; font-weight: 600; color: var(--text-secondary); }
.data-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border-light); }
.data-table tbody tr:hover { background: var(--surface-hover); }

/* ── Copy Button ── */
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition);
}
.copy-btn:hover { color: var(--primary); border-color: var(--primary); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-toggle { display: block; }
    .hamburger { display: flex; }
    .main-wrapper { margin-left: 0 !important; }
    #app { padding: 1rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
}
