/* ============================================================
   OwnRecord Design System
   Light + Dark Theme | Modern, Clean, Professional
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables: Light Theme ── */
:root, [data-theme="light"] {
    --bg-primary: #FAFBFC;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F1F5F9;
    --bg-elevated: #FFFFFF;
    --bg-hover: #F1F5F9;
    --bg-active: #E2E8F0;
    --bg-input: #FFFFFF;
    --bg-overlay: rgba(15, 23, 42, 0.5);

    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-tertiary: #94A3B8;
    --text-inverse: #FFFFFF;
    --text-link: #2563EB;

    --border-primary: #E2E8F0;
    --border-secondary: #CBD5E1;
    --border-focus: #2563EB;

    --accent-primary: #2563EB;
    --accent-primary-hover: #1D4ED8;
    --accent-primary-light: #DBEAFE;
    --accent-primary-text: #FFFFFF;

    --accent-success: #16A34A;
    --accent-success-light: #DCFCE7;
    --accent-warning: #D97706;
    --accent-warning-light: #FEF3C7;
    --accent-danger: #DC2626;
    --accent-danger-light: #FEE2E2;
    --accent-info: #0891B2;
    --accent-info-light: #CFFAFE;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.06);

    --sidebar-bg: #FFFFFF;
    --sidebar-border: #E2E8F0;
    --sidebar-text: #475569;
    --sidebar-active-bg: #EFF6FF;
    --sidebar-active-text: #2563EB;

    --topbar-bg: #FFFFFF;
    --topbar-border: #E2E8F0;

    --card-bg: #FFFFFF;
    --card-border: #E2E8F0;

    --badge-bg: #F1F5F9;
    --badge-text: #475569;

    --scrollbar-track: #F1F5F9;
    --scrollbar-thumb: #CBD5E1;
}

/* ── CSS Variables: Dark Theme ── */
[data-theme="dark"] {
    --bg-primary: #0B1120;
    --bg-secondary: #111827;
    --bg-tertiary: #1E293B;
    --bg-elevated: #1E293B;
    --bg-hover: #1E293B;
    --bg-active: #334155;
    --bg-input: #1E293B;
    --bg-overlay: rgba(0, 0, 0, 0.7);

    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-tertiary: #64748B;
    --text-inverse: #0F172A;
    --text-link: #60A5FA;

    --border-primary: #1E293B;
    --border-secondary: #334155;
    --border-focus: #3B82F6;

    --accent-primary: #3B82F6;
    --accent-primary-hover: #2563EB;
    --accent-primary-light: rgba(59, 130, 246, 0.15);
    --accent-primary-text: #FFFFFF;

    --accent-success: #22C55E;
    --accent-success-light: rgba(34, 197, 94, 0.15);
    --accent-warning: #F59E0B;
    --accent-warning-light: rgba(245, 158, 11, 0.15);
    --accent-danger: #EF4444;
    --accent-danger-light: rgba(239, 68, 68, 0.15);
    --accent-info: #06B6D4;
    --accent-info-light: rgba(6, 182, 212, 0.15);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);

    --sidebar-bg: #111827;
    --sidebar-border: #1E293B;
    --sidebar-text: #94A3B8;
    --sidebar-active-bg: rgba(59, 130, 246, 0.12);
    --sidebar-active-text: #60A5FA;

    --topbar-bg: #111827;
    --topbar-border: #1E293B;

    --card-bg: #111827;
    --card-border: #1E293B;

    --badge-bg: #1E293B;
    --badge-text: #94A3B8;

    --scrollbar-track: #1E293B;
    --scrollbar-thumb: #334155;
}

/* ── 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;
    scroll-behavior: smooth;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: var(--text-link); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-primary-hover); }

img { max-width: 100%; height: auto; display: block; }

::selection { background: var(--accent-primary); color: var(--accent-primary-text); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}
h1 { font-size: 1.875rem; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; letter-spacing: -0.015em; }
h3 { font-size: 1.25rem; letter-spacing: -0.01em; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }

.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-success { color: var(--accent-success); }
.text-warning { color: var(--accent-warning); }
.text-danger { color: var(--accent-danger); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-mono { font-family: 'JetBrains Mono', monospace; }

/* ── Layout ── */
.app-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: 64px 1fr;
    min-height: 100vh;
}

.sidebar {
    grid-row: 1 / -1;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 30;
    transition: background-color 0.3s, border-color 0.3s;
}

.sidebar-logo {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo svg { width: 32px; height: 32px; flex-shrink: 0; }
.sidebar-logo span {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

.sidebar-nav { flex: 1; padding: 16px 12px; }

.nav-section { margin-bottom: 24px; }
.nav-section-title {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    padding: 0 12px 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 2px;
    text-decoration: none;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}
.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; opacity: 0.7; }
.nav-link.active svg { opacity: 1; }
.nav-link .badge {
    margin-left: auto;
    background: var(--accent-primary);
    color: #fff;
    font-size: 0.6875rem;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
}

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

/* ── Topbar ── */
.topbar {
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 20;
    transition: background-color 0.3s, border-color 0.3s;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.topbar-search {
    position: relative;
    width: 360px;
}
.topbar-search input {
    width: 100%;
    padding: 9px 16px 9px 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 10px;
    font-size: 0.875rem;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
}
.topbar-search input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-primary-light);
    background: var(--bg-input);
}
.topbar-search input::placeholder { color: var(--text-tertiary); }
.topbar-search svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
}

/* ── Main Content ── */
.main-content {
    padding: 32px;
    overflow-y: auto;
    min-height: calc(100vh - 64px);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 16px;
}
.page-header h1 { margin: 0; }
.page-header-actions { display: flex; gap: 12px; align-items: center; }

/* ── Cards ── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 24px;
    transition: all 0.2s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-primary);
}
.card-title { font-size: 1rem; font-weight: 600; }
.card-grid { display: grid; gap: 24px; }
.card-grid-2 { grid-template-columns: repeat(2, 1fr); }
.card-grid-3 { grid-template-columns: repeat(3, 1fr); }
.card-grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Stat Cards ── */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon.blue { background: var(--accent-primary-light); color: var(--accent-primary); }
.stat-icon.green { background: var(--accent-success-light); color: var(--accent-success); }
.stat-icon.amber { background: var(--accent-warning-light); color: var(--accent-warning); }
.stat-icon.red { background: var(--accent-danger-light); color: var(--accent-danger); }
.stat-icon.teal { background: var(--accent-info-light); color: var(--accent-info); }
.stat-content {}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.8125rem; color: var(--text-secondary); margin-top: 4px; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent-primary);
    color: var(--accent-primary-text);
    border-color: var(--accent-primary);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-primary-hover); border-color: var(--accent-primary-hover); color: #fff; }

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-active); color: var(--text-primary); }

.btn-danger { background: var(--accent-danger); color: #fff; border-color: var(--accent-danger); }
.btn-danger:hover:not(:disabled) { background: #B91C1C; border-color: #B91C1C; color: #fff; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 6px 14px; font-size: 0.8125rem; border-radius: 8px; }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: 12px; }
.btn-icon { padding: 10px; }
.btn-icon.btn-sm { padding: 6px; }

/* ── Forms ── */
.form-group { margin-bottom: 20px; }
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.form-hint { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 4px; }
.form-error { font-size: 0.75rem; color: var(--accent-danger); margin-top: 4px; }

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-primary-light);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-tertiary); }
.form-input.error, .form-textarea.error { border-color: var(--accent-danger); }
.form-textarea { resize: vertical; min-height: 100px; }
.form-select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394A3B8' viewBox='0 0 16 16'%3E%3Cpath d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.form-check {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}
.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

/* ── Tables ── */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    background: var(--card-bg);
}
table {
    width: 100%;
    border-collapse: collapse;
}
thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
    white-space: nowrap;
}
tbody td {
    padding: 14px 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-primary);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--badge-bg);
    color: var(--badge-text);
}
.badge-blue { background: var(--accent-primary-light); color: var(--accent-primary); }
.badge-green { background: var(--accent-success-light); color: var(--accent-success); }
.badge-amber { background: var(--accent-warning-light); color: var(--accent-warning); }
.badge-red { background: var(--accent-danger-light); color: var(--accent-danger); }
.badge-teal { background: var(--accent-info-light); color: var(--accent-info); }

/* ── Modals ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal {
    background: var(--bg-secondary);
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    transform: translateY(20px);
    transition: transform 0.2s;
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 24px 0;
}
.modal-header h3 { font-size: 1.125rem; }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-primary);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ── Alerts / Toast ── */
.alert {
    padding: 14px 18px;
    border-radius: 10px;
    font-size: 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}
.alert svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--accent-success-light); color: var(--accent-success); border: 1px solid var(--accent-success); }
.alert-warning { background: var(--accent-warning-light); color: var(--accent-warning); border: 1px solid var(--accent-warning); }
.alert-danger { background: var(--accent-danger-light); color: var(--accent-danger); border: 1px solid var(--accent-danger); }
.alert-info { background: var(--accent-info-light); color: var(--accent-info); border: 1px solid var(--accent-info); }

.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 14px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 320px;
    max-width: 480px;
    animation: toastIn 0.3s ease forwards;
    font-size: 0.875rem;
}
.toast.removing { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* ── Item Grid ── */
.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}
.item-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.2s ease;
    cursor: pointer;
}
.item-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.item-card-image {
    aspect-ratio: 4/3;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}
.item-card-image img { width: 100%; height: 100%; object-fit: cover; }
.item-card-image .no-image { color: var(--text-tertiary); }
.item-card-image .no-image svg { width: 48px; height: 48px; }
.item-card-body { padding: 16px; }
.item-card-name { font-weight: 600; font-size: 0.9375rem; margin-bottom: 4px; color: var(--text-primary); }
.item-card-meta { font-size: 0.8125rem; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.item-card-value { font-weight: 700; color: var(--accent-primary); font-size: 1.0625rem; margin-top: 10px; }
.item-card-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* ── Bins Grid ── */
.bin-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    gap: 16px;
    transition: all 0.2s;
    cursor: pointer;
}
.bin-card:hover { box-shadow: var(--shadow-md); }
.bin-color-bar { width: 4px; border-radius: 4px; flex-shrink: 0; }
.bin-info { flex: 1; min-width: 0; }
.bin-name { font-weight: 600; font-size: 0.9375rem; margin-bottom: 4px; }
.bin-meta { font-size: 0.8125rem; color: var(--text-secondary); }
.bin-count { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 8px; }

/* ── Empty States ── */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-secondary);
}
.empty-state svg { width: 64px; height: 64px; color: var(--text-tertiary); margin: 0 auto 16px; }
.empty-state h3 { font-size: 1.125rem; margin-bottom: 8px; color: var(--text-primary); }
.empty-state p { margin-bottom: 24px; max-width: 400px; margin-left: auto; margin-right: auto; font-size: 0.9rem; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 24px; }
.pagination a, .pagination span {
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.pagination a:hover { background: var(--bg-hover); color: var(--text-primary); }
.pagination .active { background: var(--accent-primary); color: #fff; }

/* ── Theme Toggle ── */
.theme-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
}
.theme-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--accent-primary);
    border-radius: 50%;
    transition: all 0.3s;
}
[data-theme="dark"] .theme-toggle::after { transform: translateX(20px); }

/* ── User Menu ── */
.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
}
.user-menu:hover { background: var(--bg-hover); }
.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--accent-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8125rem;
}
.user-name { font-weight: 600; font-size: 0.875rem; }

/* ── Dropdown ── */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: 6px;
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.15s;
}
.dropdown-menu.active { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s;
    text-decoration: none;
    width: 100%;
    border: none;
    background: none;
    font-family: inherit;
    text-align: left;
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item svg { width: 16px; height: 16px; color: var(--text-secondary); }
.dropdown-divider { border-top: 1px solid var(--border-primary); margin: 4px 0; }

/* ── Auth Pages ── */
.auth-wrapper {
    min-height: 100vh;
    /* Use dynamic viewport on browsers that support it — avoids the iOS
       address-bar height jump that crops the bottom of the auth card. */
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Honor iPhone notch / home indicator safe areas. */
    padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
    background: var(--bg-primary);
}
.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}
.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 32px;
}
.auth-logo svg { width: 36px; height: 36px; }
.auth-logo span { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.03em; }
.auth-title { text-align: center; margin-bottom: 8px; font-size: 1.25rem; }
.auth-subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 32px; font-size: 0.9rem; }
.auth-footer { text-align: center; margin-top: 24px; font-size: 0.875rem; color: var(--text-secondary); }

/* ── Responsive ── */
.mobile-menu-toggle { display: none; }

/* Prevent horizontal scroll globally */
html, body { overflow-x: hidden; max-width: 100%; }

/* Sidebar backdrop (mobile drawer) */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.6);
    z-index: 45;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.active { opacity: 1; visibility: visible; }
[data-theme="dark"] .sidebar-backdrop { background: rgba(0, 0, 0, 0.75); }

@media (max-width: 1024px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 64px 1fr;
    }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 260px;
        height: 100vh;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform 0.28s ease;
        z-index: 50;
        box-shadow: var(--shadow-xl);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu-toggle { display: inline-flex; }
    .topbar { padding: 0 20px; }
    .topbar-search { width: 220px; }
    .main-content { padding: 24px 20px; }
    .card-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .card-grid-3 { grid-template-columns: repeat(2, 1fr); }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .topbar {
        padding: 0 16px;
        height: 60px;
    }
    .topbar-search { display: none; }
    .topbar-left { gap: 8px; }
    .topbar-right { gap: 6px; }

    .main-content {
        padding: 16px;
        min-height: calc(100vh - 60px);
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        margin-bottom: 20px;
    }
    .page-header h1 { font-size: 1.5rem; }
    .page-header-actions {
        flex-wrap: wrap;
        width: 100%;
    }
    .page-header-actions .btn { flex: 1 1 auto; min-width: 0; }

    /* Stack card grids */
    .card-grid-2, .card-grid-3, .card-grid-4 { grid-template-columns: 1fr; gap: 16px; }
    .quick-stats { grid-template-columns: 1fr 1fr !important; gap: 12px; }

    /* Cards: tighter padding */
    .card, .stat-card { padding: 18px; }
    .card-header { margin-bottom: 16px; padding-bottom: 12px; }

    /* Items / bins grid */
    .item-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 14px;
    }

    /* Modals */
    .modal {
        width: 95%;
        max-width: 95%;
        max-height: 92vh;
        border-radius: 14px;
    }
    .modal-body { padding: 20px; }
    .modal-header { padding: 20px 20px 0; }
    .modal-footer {
        padding: 14px 20px;
        flex-wrap: wrap;
    }
    .modal-footer .btn { flex: 1 1 auto; }

    /* Tables: ensure they scroll horizontally */
    .table-container { border-radius: 10px; }
    table { min-width: 560px; }
    thead th, tbody td { padding: 10px 12px; }

    /* Touch targets: 44px minimum */
    .btn {
        min-height: 44px;
        padding: 10px 18px;
    }
    .btn-sm { min-height: 36px; }
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }
    .btn-icon.btn-sm {
        min-width: 36px;
        min-height: 36px;
        padding: 7px;
    }

    /* Prevent iOS zoom on focus */
    .form-input, .form-select, .form-textarea, .topbar-search input {
        font-size: 16px;
    }
    .form-input, .form-select { min-height: 44px; }

    /* Dropdown menus: wider tap targets */
    .dropdown-item { padding: 12px 14px; font-size: 0.9375rem; }

    /* Auth card */
    .auth-card { padding: 28px 22px; border-radius: 14px; }

    /* Toast positioning */
    .toast-container { top: 12px; right: 12px; left: 12px; }
    .toast { min-width: 0; max-width: 100%; }

    /* Tabs: horizontal scroll */
    .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
    .tab { flex-shrink: 0; white-space: nowrap; }

    /* User menu: hide name on mobile, show avatar only */
    .user-menu .user-name { display: none; }
    .user-menu { padding: 4px; }
}

@media (max-width: 480px) {
    html { font-size: 15px; }
    h1 { font-size: 1.375rem; }
    h2 { font-size: 1.25rem; }
    .main-content { padding: 12px; }
    .card, .stat-card { padding: 14px; border-radius: 10px; }
    .stat-value { font-size: 1.375rem; }
    .quick-stats { grid-template-columns: 1fr !important; }
    .item-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .auth-card { padding: 22px 18px; }
    .auth-logo { margin-bottom: 22px; }
    .page-header-actions { flex-direction: column; }
    .page-header-actions .btn { width: 100%; }
}

/* ── Dark Mode Polish ── */
[data-theme="dark"] .qr-display { background: #F1F5F9; }
[data-theme="dark"] .twofa-setup .qr-code { background: #F1F5F9; }
[data-theme="dark"] .email-preview-frame { background: #F1F5F9; }

/* Dark-mode badge variants: use translucent tints so text stays readable */
[data-theme="dark"] .badge-blue { background: rgba(59, 130, 246, 0.18); color: #93C5FD; }
[data-theme="dark"] .badge-green { background: rgba(34, 197, 94, 0.18); color: #86EFAC; }
[data-theme="dark"] .badge-amber { background: rgba(245, 158, 11, 0.18); color: #FCD34D; }
[data-theme="dark"] .badge-red { background: rgba(239, 68, 68, 0.18); color: #FCA5A5; }
[data-theme="dark"] .badge-teal { background: rgba(6, 182, 212, 0.18); color: #67E8F9; }

/* Dark-mode alerts: keep them readable */
[data-theme="dark"] .alert-success { color: #86EFAC; border-color: rgba(34, 197, 94, 0.4); }
[data-theme="dark"] .alert-warning { color: #FCD34D; border-color: rgba(245, 158, 11, 0.4); }
[data-theme="dark"] .alert-danger { color: #FCA5A5; border-color: rgba(239, 68, 68, 0.4); }
[data-theme="dark"] .alert-info { color: #67E8F9; border-color: rgba(6, 182, 212, 0.4); }

/* Dark-mode form inputs */
[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-textarea,
[data-theme="dark"] .topbar-search input {
    background: var(--bg-input);
    border-color: var(--border-secondary);
}
[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748B' viewBox='0 0 16 16'%3E%3Cpath d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
}

/* Dark-mode pagination active state uses variable */
.pagination .active { background: var(--accent-primary); color: var(--accent-primary-text); }

/* Make sure pinned/sticky headers stay above drawer content */
.topbar { backdrop-filter: saturate(180%) blur(6px); }

/* ── Utility ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.p-4 { padding: 16px; }
.p-6 { padding: 24px; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.relative { position: relative; }

/* ── Loading ── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-primary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: skeleton 1.5s ease-in-out infinite;
    border-radius: 8px;
}
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Tabs ── */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: 24px;
    gap: 0;
}
.tab {
    padding: 12px 20px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent-primary); border-bottom-color: var(--accent-primary); }

/* ── QR Code ── */
.qr-display {
    background: #FFFFFF;
    padding: 24px;
    border-radius: 12px;
    display: inline-block;
    border: 1px solid var(--border-primary);
}
.qr-display img { width: 200px; height: 200px; }

/* ── Global Search Dropdown ── */
.search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-xl);
    max-height: 420px;
    overflow-y: auto;
    z-index: 1000;
}
.search-group {
    padding: 6px 0;
}
.search-group + .search-group {
    border-top: 1px solid var(--border-primary);
}
.search-group-title {
    padding: 8px 16px 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    text-decoration: none;
    color: var(--text-primary);
    transition: background 0.1s;
    cursor: pointer;
}
.search-result-item:hover {
    background: var(--bg-hover);
}
.search-result-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 8px;
    color: var(--text-secondary);
}
.search-result-icon svg {
    width: 16px;
    height: 16px;
}
.search-result-content {
    flex: 1;
    min-width: 0;
}
.search-result-name {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-result-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}
.search-badge {
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 1px 8px;
    background: var(--accent-primary-light);
    color: var(--accent-primary);
    border-radius: 9999px;
}
.search-value {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-success);
    font-family: 'JetBrains Mono', monospace;
}
.search-meta-text {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}
.search-empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-tertiary);
}
