/* ═══════════════════════════════════════
   InvoiceFlow — Theme System
   Light (default) + Dark mode
   Toggle saved in cookie (persists across sessions)
   ═══════════════════════════════════════ */

/* ─── LIGHT THEME (default) ──────────── */
:root, [data-theme="light"] {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface2: #f0f1f5;
  --border: #e2e4ea;
  --text: #1a1d2e;
  --dim: #6b7280;
  --brand: #d63384;
  --green: #16a34a;
  --blue: #2563eb;
  --orange: #ea580c;
  --red: #dc2626;
  --purple: #7c3aed;
  --yellow: #ca8a04;
  --cyan: #0891b2;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

/* ─── DARK THEME ─────────────────────── */
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1c28;
  --surface2: #22253a;
  --border: #2e3248;
  --text: #e0e2ef;
  --dim: #8489a3;
  --brand: #e84393;
  --green: #34d399;
  --blue: #38bdf8;
  --orange: #fb923c;
  --red: #f87171;
  --purple: #a78bfa;
  --yellow: #fbbf24;
  --cyan: #22d3ee;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

/* ─── BASE ───────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; font-size: 14px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── AUTH PAGES ─────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.auth-container { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; padding: 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.auth-logo { text-align: center; margin-bottom: 4px; font-size: 28px; }
.logo-text { font-weight: 800; color: var(--text); }
.logo-accent { font-weight: 800; color: var(--brand); }
.auth-subtitle { text-align: center; color: var(--dim); font-size: 13px; margin-bottom: 20px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-footer { text-align: center; margin-top: 16px; font-size: 13px; color: var(--dim); }
.auth-security-note { font-size: 11px; color: var(--dim); text-align: center; }

/* ─── FORMS ──────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 13px; color: var(--dim); font-weight: 600; display: flex; align-items: center; gap: 4px; }
.form-group input, .form-group select, .form-group textarea {
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; color: var(--text); font-size: 14px; outline: none; transition: border-color .2s; width: 100%; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(214,51,132,.1); }
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--dim); opacity: 0.5; }

.btn { padding: 10px 20px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid var(--border); transition: all .15s; background: var(--surface); color: var(--text); }
.btn-primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn-primary:hover { opacity: .9; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-outline { background: transparent; color: var(--dim); }
.btn-outline:hover { border-color: var(--brand); color: var(--text); }
.btn-full { width: 100%; text-align: center; display: block; text-decoration: none; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; }
.alert-danger { background: rgba(220,38,38,.08); border: 1px solid rgba(220,38,38,.2); color: var(--red); }
.alert-warning { background: rgba(202,138,4,.08); border: 1px solid rgba(202,138,4,.2); color: var(--yellow); }
.alert-success { background: rgba(22,163,74,.08); border: 1px solid rgba(22,163,74,.2); color: var(--green); }

/* ─── COMPANY SELECTOR ───────────────── */
.company-list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.company-card { width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: all .15s; color: var(--text); font-size: 14px; text-align: left; }
.company-card:hover { border-color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow); }
.company-card-icon { width: 40px; height: 40px; border-radius: 10px; background: rgba(214,51,132,.1); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--brand); font-size: 18px; flex-shrink: 0; }
.company-card-info { flex: 1; }
.company-card-name { font-weight: 600; }
.company-card-role { font-size: 11px; color: var(--dim); text-transform: capitalize; }
.company-card-arrow { color: var(--dim); font-size: 18px; }
.empty-state { text-align: center; padding: 20px; color: var(--dim); font-size: 13px; }

/* ─── TOPBAR ─────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 20px; display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow); }
.topbar-left { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.topbar-version { font-size: 10px; color: var(--dim); background: var(--surface2); padding: 2px 8px; border-radius: 4px; font-family: monospace; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.company-switcher select { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 12px; color: var(--text); font-size: 12px; cursor: pointer; }
.sync-indicator { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.topbar-btn { width: 30px; height: 30px; border-radius: 50%; background: var(--surface2); border: 1px solid var(--border); color: var(--dim); cursor: pointer; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; transition: .15s; }
.topbar-btn:hover { border-color: var(--brand); color: var(--brand); }
.user-menu { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: rgba(214,51,132,.12); color: var(--brand); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.user-name { font-size: 12px; color: var(--dim); }

/* Theme Toggle */
.theme-toggle { width: 30px; height: 30px; border-radius: 50%; background: var(--surface2); border: 1px solid var(--border); cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; transition: .15s; }
.theme-toggle:hover { border-color: var(--brand); }

/* ─── APP LAYOUT ─────────────────────── */
.app-layout { display: flex; min-height: calc(100vh - 49px); }

/* ─── SIDEBAR ────────────────────────── */
.sidebar { width: 230px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto; }
.sidebar-company { padding: 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.sidebar-company-icon { width: 34px; height: 34px; border-radius: 8px; background: rgba(214,51,132,.1); color: var(--brand); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.sidebar-company-name { font-size: 13px; font-weight: 700; line-height: 1.2; }
.sidebar-company-role { font-size: 10px; color: var(--dim); text-transform: capitalize; }
.sidebar-nav { flex: 1; padding: 8px 0; }
.sidebar-section { padding: 14px 16px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--dim); font-weight: 700; }
.sidebar-link { display: flex; align-items: center; gap: 8px; padding: 8px 16px; font-size: 13px; color: var(--dim); text-decoration: none; border-left: 3px solid transparent; transition: all .1s; }
.sidebar-link:hover { color: var(--text); background: rgba(0,0,0,.03); text-decoration: none; }
[data-theme="dark"] .sidebar-link:hover { background: rgba(255,255,255,.03); }
.sidebar-link.active { color: var(--brand); background: rgba(214,51,132,.06); border-left-color: var(--brand); font-weight: 600; }
.sidebar-link.disabled { opacity: .35; pointer-events: none; }
.sidebar-icon { font-size: 15px; width: 22px; text-align: center; }
.sidebar-badge { font-size: 9px; margin-left: auto; padding: 1px 7px; border-radius: 8px; }
.sidebar-badge.soon { background: var(--surface2); color: var(--dim); }
.sidebar-footer { margin-top: auto; }

/* ─── MAIN CONTENT ───────────────────── */
.main-content { flex: 1; padding: 24px; overflow-y: auto; background: var(--bg); }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-label { font-family: monospace; font-size: 10px; text-transform: uppercase; letter-spacing: 2px; color: var(--brand); margin-bottom: 2px; font-weight: 700; }
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.page-subtitle { font-size: 12px; color: var(--dim); margin-top: 2px; }
.date-filter { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 14px; color: var(--text); font-size: 12px; cursor: pointer; }

/* ─── BANNERS ────────────────────────── */
.success-banner { background: rgba(22,163,74,.06); border: 1px solid rgba(22,163,74,.2); border-radius: var(--radius); padding: 18px 20px; display: flex; gap: 14px; align-items: flex-start; margin-bottom: 20px; }
.success-banner-icon { font-size: 22px; flex-shrink: 0; }
.success-banner-content h3 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.success-banner-content p { font-size: 12px; color: var(--dim); margin: 0; }

/* ─── METRIC CARDS ───────────────────── */
.metrics-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 20px; }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); transition: all .15s; }
.metric-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.metric-label { font-size: 12px; color: var(--dim); margin-bottom: 6px; display: flex; align-items: center; gap: 4px; font-weight: 600; }
.metric-value { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.metric-value.placeholder { color: var(--dim); font-size: 18px; font-weight: 400; }
.metric-sub { font-size: 10px; color: var(--dim); margin-top: 4px; }

/* ─── BUILD PROGRESS ─────────────────── */
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 6px; }
.build-progress { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.steps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.step-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface2); border: 1px solid var(--border); }
.step-item.done { border-color: rgba(22,163,74,.3); background: rgba(22,163,74,.04); }
.step-item.next { border-color: var(--brand); background: rgba(214,51,132,.04); }
.step-number { width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.step-item.done .step-number { background: rgba(22,163,74,.12); color: var(--green); }
.step-item.next .step-number { background: rgba(214,51,132,.12); color: var(--brand); }
.step-item.upcoming .step-number { background: var(--surface2); color: var(--dim); }
.step-name { font-size: 11px; font-weight: 600; }
.step-status { font-size: 9px; color: var(--dim); }
.step-item.done .step-status { color: var(--green); }

/* ─── SECURITY PANEL ─────────────────── */
.security-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.security-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px; }
.security-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; border-radius: var(--radius-sm); }
.security-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.security-item.ok .security-dot { background: var(--green); }
.security-item.warn .security-dot { background: var(--yellow); }
.security-status { margin-left: auto; font-size: 11px; color: var(--dim); font-family: monospace; }
.security-item.ok .security-status { color: var(--green); }
.security-item.warn .security-status { color: var(--yellow); }

/* ─── HELP SYSTEM ────────────────────── */
.help-icon { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%; background: var(--surface2); border: 1px solid var(--border); color: var(--dim); font-size: 9px; font-weight: 700; cursor: help; flex-shrink: 0; transition: .15s; font-style: normal; }
.help-icon:hover { background: rgba(214,51,132,.1); color: var(--brand); border-color: var(--brand); }
.help-tooltip { position: fixed; z-index: 1000; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; max-width: 280px; box-shadow: var(--shadow-lg); pointer-events: none; }
.help-tooltip-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.help-tooltip-body { font-size: 12px; color: var(--dim); line-height: 1.5; }
.help-panel { position: fixed; top: 0; right: -360px; width: 360px; height: 100vh; background: var(--surface); border-left: 1px solid var(--border); z-index: 100; transition: right .25s ease; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.help-panel.open { right: 0; }
.help-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.help-panel-header h3 { font-size: 16px; font-weight: 700; }
.help-close { background: none; border: none; color: var(--dim); font-size: 24px; cursor: pointer; }
.help-panel-search { padding: 12px 20px; border-bottom: 1px solid var(--border); }
.help-panel-search input { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; color: var(--text); font-size: 13px; }
.help-panel-content { flex: 1; overflow-y: auto; padding: 16px 20px; }
.help-empty { color: var(--dim); font-size: 13px; text-align: center; padding: 40px 0; }

/* ─── SETTINGS ───────────────────────── */
.settings-tabs { display: flex; gap: 4px; margin-bottom: 20px; overflow-x: auto; padding-bottom: 4px; }
.settings-tab { padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--dim); background: var(--surface); border: 1px solid var(--border); text-decoration: none; white-space: nowrap; transition: all .15s; }
.settings-tab:hover { border-color: var(--brand); color: var(--text); text-decoration: none; }
.settings-tab.active { background: var(--brand); color: white; border-color: var(--brand); }
.settings-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.settings-card-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.settings-card-desc { font-size: 13px; color: var(--dim); margin-bottom: 16px; }
.settings-form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; }
.form-actions { display: flex; gap: 8px; padding-top: 8px; }
.help-inline { font-size: 12px; color: var(--dim); line-height: 1.7; padding: 12px 14px; background: var(--surface2); border-radius: var(--radius-sm); margin-top: 12px; }

/* Channel Cards */
.channel-card { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.channel-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.channel-card-icon { font-size: 24px; }
.channel-card-info { flex: 1; }
.channel-card-name { font-size: 14px; font-weight: 700; }
.channel-card-type { font-size: 11px; color: var(--dim); }
.channel-card-vat { font-size: 11px; color: var(--dim); background: var(--surface); padding: 4px 10px; border-radius: 6px; }
.channel-config-form { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }

/* Users */
.users-list { display: flex; flex-direction: column; gap: 6px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface2); border-radius: var(--radius-sm); }
.user-row-avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(214,51,132,.1); color: var(--brand); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.user-row-info { flex: 1; }
.user-row-name { font-size: 14px; font-weight: 600; }
.user-row-email { font-size: 12px; color: var(--dim); }
.role-badge { font-size: 10px; padding: 3px 12px; border-radius: 12px; font-weight: 700; text-transform: capitalize; }
.role-owner { background: rgba(214,51,132,.1); color: var(--brand); }
.role-admin { background: rgba(37,99,235,.1); color: var(--blue); }
.role-viewer { background: var(--surface2); color: var(--dim); }
.role-accountant { background: rgba(124,58,237,.1); color: var(--purple); }
.btn-icon { background: none; border: none; color: var(--dim); cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 4px; }
.btn-icon:hover { color: var(--red); background: rgba(220,38,38,.08); }

/* Credit Cards */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.credit-card-item { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.cc-header { display: flex; justify-content: space-between; margin-bottom: 8px; }
.cc-name { font-size: 14px; font-weight: 700; }
.cc-provider { font-size: 11px; color: var(--dim); }
.cc-number { font-family: monospace; font-size: 15px; color: var(--dim); margin-bottom: 12px; letter-spacing: 2px; }
.cc-details { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cc-label { font-size: 10px; color: var(--dim); }
.cc-value { font-size: 13px; font-weight: 600; }
.overdraft-item { display: flex; gap: 20px; padding: 12px 16px; background: var(--surface2); border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 13px; flex-wrap: wrap; }

/* Notifications */
.notification-grid { display: flex; flex-direction: column; gap: 4px; }
.notification-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--surface2); border-radius: var(--radius-sm); }
.notification-info { flex: 1; }
.notification-name { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.notification-desc { font-size: 12px; color: var(--dim); }
.toggle { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--border); border-radius: 24px; transition: .2s; }
.toggle-slider:before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .2s; }
.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider:before { transform: translateX(18px); }

/* Audit */
.audit-list { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.audit-item { display: flex; gap: 12px; padding: 8px 12px; font-size: 12px; border-bottom: 1px solid var(--border); }
.audit-time { color: var(--dim); font-family: monospace; font-size: 11px; flex-shrink: 0; min-width: 90px; }
.audit-action { font-weight: 700; min-width: 120px; }
.audit-fail { color: var(--red); }
.audit-ok { color: var(--green); }

/* ─── RESPONSIVE ─────────────────────── */
@media (max-width: 1024px) { .metrics-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 768px) {
  .sidebar { display: none; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar-right .sync-indicator, .topbar-right .user-name { display: none; }
}
