/* ═══════════════════════════════════════
   FurnBooks — E-Commerce Furniture Finance
   Dark Luxury Theme with Gold Accents
   ═══════════════════════════════════════ */

:root {
    --bg: #0c0c0f;
    --surface: #141418;
    --surface2: #1a1a20;
    --surface3: #222228;
    --border: #2a2a32;
    --border-light: #35353f;
    --text: #e8e6e3;
    --text-secondary: #b0aea8;
    --text-muted: #6b6a68;
    --accent: #c9a96e;
    --accent-hover: #dbb978;
    --accent-dim: rgba(201,169,110,0.12);
    --income: #4ade80;
    --income-bg: rgba(74,222,128,0.1);
    --expense: #f87171;
    --expense-bg: rgba(248,113,113,0.1);
    --info: #60a5fa;
    --info-bg: rgba(96,165,250,0.1);
    --warning: #fbbf24;
    --warning-bg: rgba(251,191,36,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --sidebar-width: 260px;
    --header-height: 56px;
    --bottom-nav-height: 64px;
    --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

*,*::before,*::after { margin:0; padding:0; box-sizing:border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; }
table { border-collapse: collapse; width: 100%; }

.offline-banner {
    position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
    background: var(--warning); color: #000; text-align: center;
    padding: 8px; font-size: 13px; font-weight: 600;
    animation: slideDown .3s;
}
@keyframes slideDown { from { transform:translateY(-100%); } }

.mobile-header {
    display: none; position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-height); background: var(--surface);
    border-bottom: 1px solid var(--border); z-index: 100;
    align-items: center; padding: 0 16px; gap: 12px;
}
.menu-toggle {
    background: none; border: none; cursor: pointer; width: 36px; height: 36px;
    display: flex; flex-direction: column; justify-content: center; gap: 5px; padding: 6px;
}
.menu-toggle span { display: block; height: 2px; width: 100%; background: var(--text); border-radius: 2px; transition: var(--transition); }
.mobile-title { flex: 1; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-actions { display: flex; gap: 8px; }
.btn-icon {
    background: none; border: none; color: var(--text-secondary); cursor: pointer;
    width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
    border-radius: 50%; transition: var(--transition);
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 199; backdrop-filter: blur(4px); }
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-width);
    background: var(--surface); border-right: 1px solid var(--border); z-index: 200;
    display: flex; flex-direction: column; overflow-y: auto;
    transition: transform .3s cubic-bezier(0.4,0,0.2,1);
}
.sidebar-brand { padding: 24px 20px 16px; display: flex; align-items: baseline; gap: 10px; border-bottom: 1px solid var(--border); }
.sidebar-brand h2 { font-family: 'Instrument Serif', serif; font-size: 24px; color: var(--accent); font-weight: 400; }
.version-badge { font-size: 10px; background: var(--accent-dim); color: var(--accent); padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.sidebar-user { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.user-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-dim); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 14px; font-weight: 600; }
.user-role { font-size: 12px; color: var(--text-muted); }

.sidebar-nav { flex: 1; padding: 12px 10px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 14px; font-weight: 500; transition: var(--transition); margin-bottom: 2px; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }
.nav-divider { height: 1px; background: var(--border); margin: 10px 14px; }
.nav-logout { color: var(--expense); }
.nav-logout:hover { background: var(--expense-bg); color: var(--expense); }

.main-content { margin-left: var(--sidebar-width); min-height: 100vh; padding: 32px; }

.bottom-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; height: var(--bottom-nav-height); background: var(--surface); border-top: 1px solid var(--border); z-index: 100; justify-content: space-around; align-items: center; padding-bottom: env(safe-area-inset-bottom, 0); }
.bottom-nav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--text-muted); font-size: 11px; font-weight: 500; padding: 6px 12px; border-radius: var(--radius-sm); transition: var(--transition); }
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item svg { opacity: .6; }
.bottom-nav-item.active svg { opacity: 1; }

.fab { display: none; position: fixed; bottom: calc(var(--bottom-nav-height) + 16px); right: 16px; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--bg); border: none; cursor: pointer; z-index: 99; box-shadow: 0 4px 16px rgba(201,169,110,0.4); transition: var(--transition); align-items: center; justify-content: center; }
.fab:hover { transform: scale(1.08); }
.fab:active { transform: scale(0.95); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; transition: var(--transition); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.card-title { font-size: 16px; font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%; }
.stat-card.income::after { background: var(--income); }
.stat-card.expense::after { background: var(--expense); }
.stat-card.info::after { background: var(--info); }
.stat-card.warning::after { background: var(--warning); }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; font-family: 'DM Sans', monospace; line-height: 1.2; }
.stat-change { font-size: 12px; margin-top: 6px; font-weight: 600; }
.stat-change.up { color: var(--income); }
.stat-change.down { color: var(--expense); }

.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { min-width: 600px; }
.data-table th { background: var(--surface2); padding: 12px 16px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
.data-table td { padding: 14px 16px; font-size: 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: var(--surface2); }
.data-table tr:last-child td { border-bottom: none; }

.badge { display: inline-flex; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-income { background: var(--income-bg); color: var(--income); }
.badge-expense { background: var(--expense-bg); color: var(--expense); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-draft { background: var(--surface3); color: var(--text-muted); }
.badge-paid { background: var(--income-bg); color: var(--income); }
.badge-overdue { background: var(--expense-bg); color: var(--expense); }

.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 12px 16px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-family: inherit; font-size: 15px; transition: border-color .2s; }
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.form-textarea { resize: vertical; min-height: 100px; }
.form-select { appearance: none; cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 24px; border: none; border-radius: var(--radius); font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; transition: var(--transition); white-space: nowrap; }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface3); }
.btn-danger { background: var(--expense-bg); color: var(--expense); }
.btn-danger:hover { background: rgba(248,113,113,0.2); }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; }

.alert { padding: 14px 18px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; display: flex; align-items: center; justify-content: space-between; }
.alert-error { background: var(--expense-bg); color: var(--expense); border: 1px solid rgba(248,113,113,0.2); }
.alert-success { background: var(--income-bg); color: var(--income); border: 1px solid rgba(74,222,128,0.2); }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(96,165,250,0.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(251,191,36,0.2); }
.alert-close { background: none; border: none; color: inherit; cursor: pointer; font-size: 20px; line-height: 1; margin-left: 12px; }
.flash-alert { animation: fadeIn .3s; }
@keyframes fadeIn { from { opacity:0; transform:translateY(-8px); } }

.modal { display: none; position: fixed; inset: 0; z-index: 300; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.modal-content { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 90%; max-width: 560px; max-height: 90vh; overflow-y: auto; animation: modalIn .3s; z-index: 1; }
.modal-sm { max-width: 380px; }
@keyframes modalIn { from { opacity:0; transform:translateY(16px) scale(0.98); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 17px; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 24px; line-height: 1; }
.modal-body { padding: 24px; }

.quick-link { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius); color: var(--text); transition: var(--transition); margin-bottom: 6px; }
.quick-link:hover { background: var(--surface2); }
.quick-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; background: var(--surface3); }
.quick-link.income .quick-icon { background: var(--income-bg); }
.quick-link.expense .quick-icon { background: var(--expense-bg); }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-size: 22px; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

.filters-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-chip { padding: 8px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; font-size: 13px; font-weight: 500; color: var(--text-secondary); cursor: pointer; transition: var(--transition); }
.filter-chip:hover, .filter-chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { margin-bottom: 16px; opacity: .3; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text-secondary); }
.empty-state p { font-size: 14px; margin-bottom: 24px; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 24px; }
.page-btn { padding: 8px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px; font-weight: 500; cursor: pointer; transition: var(--transition); }
.page-btn:hover, .page-btn.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

.chart-container { position: relative; height: 300px; width: 100%; }

.sync-indicator { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--income); }
.sync-dot.offline { background: var(--warning); }
.sync-dot.syncing { background: var(--info); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{ opacity:1; } 50%{ opacity:.3; } }

.update-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 16px; }
.update-card .version-tag { display: inline-flex; padding: 4px 12px; background: var(--accent-dim); color: var(--accent); border-radius: 20px; font-size: 13px; font-weight: 700; margin-bottom: 12px; }
.update-card h3 { font-size: 16px; margin-bottom: 8px; }
.update-card p { font-size: 14px; color: var(--text-secondary); }
.update-progress { height: 6px; background: var(--surface3); border-radius: 3px; margin-top: 16px; overflow: hidden; }
.update-progress-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width .5s; }

.text-income { color: var(--income) !important; }
.text-expense { color: var(--expense) !important; }
.text-accent { color: var(--accent) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

.pwa-banner { position: fixed; bottom: calc(var(--bottom-nav-height) + 8px); left: 12px; right: 12px; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; z-index: 90; box-shadow: var(--shadow); animation: fadeIn .3s; }
.pwa-banner p { font-size: 13px; } .pwa-banner .btn-sm { flex-shrink: 0; }

@media (max-width: 1024px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } .main-content { padding: 24px; } }

@media (max-width: 768px) {
    .mobile-header { display: flex; }
    .sidebar { transform: translateX(-100%); width: 280px; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .main-content { margin-left: 0; padding: 16px; padding-top: calc(var(--header-height) + 16px); padding-bottom: calc(var(--bottom-nav-height) + 80px); }
    .bottom-nav { display: flex; }
    .fab { display: flex; }
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 16px; }
    .stat-value { font-size: 22px; }
    .page-header h2 { font-size: 18px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .form-row { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .card { padding: 18px; border-radius: var(--radius); }
    .btn-group { flex-wrap: wrap; }
    .filters-bar { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
    .chart-container { height: 220px; }
    .data-table { min-width: 500px; }
    .modal-content { width: 96%; border-radius: var(--radius); }
    .truncate { max-width: 120px; }
}

@media (max-width: 480px) { .stat-grid { grid-template-columns: 1fr; } .main-content { padding: 12px; padding-top: calc(var(--header-height) + 12px); padding-bottom: calc(var(--bottom-nav-height) + 72px); } }

@media print { .sidebar, .mobile-header, .bottom-nav, .fab { display: none !important; } .main-content { margin: 0 !important; padding: 20px !important; } body { background: #fff; color: #000; } .card { border: 1px solid #ddd; box-shadow: none; } }

.skeleton { background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 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;} }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
::selection { background: var(--accent); color: var(--bg); }

/* ── AJAX Loading Spinner ── */
.ow-spinner { width:40px; height:40px; border:3px solid var(--border); border-top-color:var(--accent); border-radius:50%; animation:owSpin .7s linear infinite; }
@keyframes owSpin { to { transform:rotate(360deg); } }
.ow-spin-inline { display:inline-block; width:14px; height:14px; border:2px solid rgba(0,0,0,0.2); border-top-color:currentColor; border-radius:50%; animation:owSpin .6s linear infinite; vertical-align:middle; }

/* ── AJAX Transitions ── */
#mainContent { transition: opacity .15s ease; }
.data-table tr { transition: all .3s ease-out; }
.flash-alert { transition: opacity .3s, transform .3s; }

/* ── Delete animation ── */
.data-table tr.deleting { opacity:0; max-height:0; overflow:hidden; padding:0; }

/* ── Searchable Select ── */
.search-select-wrap { position: relative; }
.search-select-display { cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.ss-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-arrow { font-size: 11px; color: var(--text-muted); margin-left: 8px; transition: transform .2s; }
.search-select-dropdown.open + .search-select-display .ss-arrow,
.search-select-dropdown.open ~ .search-select-display .ss-arrow { transform: rotate(180deg); }
.search-select-dropdown { display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 500; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-top: 4px; box-shadow: 0 8px 32px rgba(0,0,0,0.4); max-height: 280px; overflow: hidden; }
.search-select-dropdown.open { display: block; animation: fadeIn .15s; }
.ss-search { border: none !important; border-bottom: 1px solid var(--border) !important; border-radius: 0 !important; padding: 10px 14px !important; font-size: 14px !important; box-shadow: none !important; }
.ss-options { max-height: 220px; overflow-y: auto; }
.ss-option { padding: 10px 14px; font-size: 14px; cursor: pointer; transition: background .15s; }
.ss-option:hover { background: var(--surface2); }
.ss-option.active { background: var(--accent-dim); color: var(--accent); }
.ss-placeholder { color: var(--text-muted); font-style: italic; }
.ss-empty { color: var(--text-muted); text-align: center; padding: 16px; font-size: 13px; }

/* ── Modal Large ── */
.modal-lg { max-width: 720px; }
@media (max-width: 768px) { .modal-lg { max-width: 96%; } }
.modal-content { max-height: 92vh; overflow-y: auto; }

/* ── Receipt Upload ── */
#receiptPreview { display:flex; align-items:center; flex-wrap:wrap; gap:8px; }
#receiptPreview img { border-radius:8px; border:1px solid var(--border); }

/* ── Offline Banner ── */
.offline-banner { position:fixed;top:0;left:0;right:0;z-index:9999;background:#f59e0b;color:#000;text-align:center;padding:6px 16px;font-size:13px;font-weight:600; }
.sync-dot { width:8px;height:8px;border-radius:50%;background:var(--income);display:inline-block; }
.sync-dot.offline { background:var(--expense);animation:pulse 1.5s infinite; }
