/* ===== NeoFact Design System ===== */
:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1e293b;
  --bg-card: #151d2e;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent2: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --border: #1e293b;
  --border2: #334155;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --nav-h: 72px;
  --header-h: 60px;
}

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

html { font-size: 15px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Splash */
.splash-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
  animation: splashFade 0.5s 1.8s forwards;
}
.splash-content { text-align: center; }
.splash-logo { animation: splashPulse 1.5s ease infinite; }
.splash-title { font-size: 2rem; font-weight: 800; margin-top: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.splash-subtitle { color: var(--text2); margin-top: 4px; font-size: 0.9rem; }
.splash-loader { width: 120px; height: 3px; background: var(--bg-tertiary);
  border-radius: 3px; margin: 24px auto 0; overflow: hidden; }
.splash-loader-bar { width: 40%; height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  animation: splashLoad 1.5s ease forwards; }

@keyframes splashPulse { 0%,100%{ transform:scale(1); } 50%{ transform:scale(1.08); } }
@keyframes splashLoad { 0%{ width:0; } 100%{ width:100%; } }
@keyframes splashFade { to { opacity:0; pointer-events:none; visibility:hidden; } }

/* Header */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h); display: flex; align-items: center;
  justify-content: space-between; padding: 0 16px;
  background: rgba(10,14,23,0.85); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.header-left, .header-right { display: flex; align-items: center; gap: 8px; min-width: 44px; }
.header-btn { background: none; border: none; color: var(--text2); padding: 8px;
  border-radius: 10px; cursor: pointer; transition: all 0.2s; }
.header-btn:hover { color: var(--text); background: var(--bg-tertiary); }
.header-logo svg { display: block; }
.page-title { font-size: 1.1rem; font-weight: 700; white-space: nowrap; }

/* Search */
.search-bar {
  position: fixed; top: var(--header-h); left: 0; right: 0; z-index: 99;
  padding: 8px 16px; background: rgba(10,14,23,0.95); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  animation: slideDown 0.25s ease;
}
.search-input-wrap {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-tertiary); border-radius: 12px; padding: 10px 14px;
}
.search-input-wrap svg { flex-shrink: 0; color: var(--text3); }
.search-input { flex: 1; background: none; border: none; color: var(--text);
  font-size: 0.95rem; font-family: inherit; outline: none; }
.search-input::placeholder { color: var(--text3); }
.search-clear { background: none; border: none; color: var(--text3); padding: 4px; cursor: pointer; }

/* Main */
.main-content {
  padding: calc(var(--header-h) + 16px) 16px calc(var(--nav-h) + 24px);
  min-height: 100dvh;
  animation: fadeIn 0.3s ease;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h); display: flex; align-items: center; justify-content: space-around;
  background: rgba(17,24,39,0.92); backdrop-filter: blur(24px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none; color: var(--text3); font-size: 0.65rem; font-weight: 500;
  padding: 6px 0; transition: color 0.2s; min-width: 52px;
}
.nav-item.active { color: var(--accent); }
.nav-item.active svg { filter: drop-shadow(0 0 8px rgba(99,102,241,0.5)); }

/* FAB */
.fab {
  position: fixed; bottom: calc(var(--nav-h) + 16px); right: 16px; z-index: 99;
  width: 56px; height: 56px; border-radius: 16px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(99,102,241,0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(99,102,241,0.5); }
.fab:active { transform: scale(0.95); }

/* Cards */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  transition: transform 0.2s, border-color 0.2s;
}
.card:active { transform: scale(0.98); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.card-title { font-size: 0.95rem; font-weight: 600; }
.card-subtitle { font-size: 0.8rem; color: var(--text2); margin-top: 2px; }
.card-amount { font-size: 1.1rem; font-weight: 700; text-align: right; }
.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px;
  padding-top: 10px; border-top: 1px solid var(--border); }
.card-actions { display: flex; gap: 6px; }
.card-action-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-tertiary); color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.card-action-btn:hover { border-color: var(--accent); color: var(--accent); }
.card-action-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 20px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.3px;
}
.badge-draft { background: rgba(100,116,139,0.15); color: var(--text3); }
.badge-sent { background: rgba(99,102,241,0.15); color: var(--accent); }
.badge-accepted { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-refused { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-converted { background: rgba(6,182,212,0.15); color: var(--accent2); }
.badge-paid { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-partial { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-overdue { background: rgba(239,68,68,0.15); color: var(--danger); }

/* KPI Grid */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.kpi-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.kpi-card.success::before { background: linear-gradient(90deg, var(--success), #34d399); }
.kpi-card.warning::before { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.kpi-card.danger::before { background: linear-gradient(90deg, var(--danger), #f87171); }
.kpi-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 10px;
  background: rgba(99,102,241,0.12); color: var(--accent);
}
.kpi-card.success .kpi-icon { background: rgba(16,185,129,0.12); color: var(--success); }
.kpi-card.warning .kpi-icon { background: rgba(245,158,11,0.12); color: var(--warning); }
.kpi-card.danger .kpi-icon { background: rgba(239,68,68,0.12); color: var(--danger); }
.kpi-value { font-size: 1.4rem; font-weight: 800; }
.kpi-label { font-size: 0.75rem; color: var(--text2); margin-top: 2px; }

/* Section */
.section-title {
  font-size: 0.95rem; font-weight: 700; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.section-link { font-size: 0.8rem; color: var(--accent); font-weight: 500; text-decoration: none; }

/* Quick Actions */
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 24px; }
.quick-action {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: all 0.2s;
  text-decoration: none; color: var(--text);
}
.quick-action:active { transform: scale(0.96); }
.quick-action-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.quick-action-icon.indigo { background: rgba(99,102,241,0.15); color: var(--accent); }
.quick-action-icon.cyan { background: rgba(6,182,212,0.15); color: var(--accent2); }
.quick-action-icon.emerald { background: rgba(16,185,129,0.15); color: var(--success); }
.quick-action span { font-size: 0.75rem; font-weight: 500; text-align: center; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text2);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 12px 14px; background: var(--bg-tertiary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 0.95rem;
  transition: border-color 0.2s; outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { appearance: none; cursor: pointer;
  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 6l4 4 4-4'/%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: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--radius-sm); border: none;
  font-family: inherit; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: white; box-shadow: 0 4px 14px rgba(99,102,241,0.3);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(99,102,241,0.4); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-danger { background: rgba(239,68,68,0.12); color: var(--danger); }
.btn-danger:hover { background: rgba(239,68,68,0.2); }
.btn-success { background: rgba(16,185,129,0.12); color: var(--success); }
.btn-sm { padding: 8px 14px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 10px; margin-top: 20px; }
.btn-group .btn { flex: 1; }

/* Line Items Table */
.line-items { margin: 16px 0; }
.line-item {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px;
  position: relative;
}
.line-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.line-item-num { font-size: 0.75rem; color: var(--text3); font-weight: 600; }
.line-item-remove { background: none; border: none; color: var(--danger); cursor: pointer; padding: 4px; }
.line-item-desc { font-weight: 600; font-size: 0.9rem; margin-bottom: 8px; }
.line-item-details { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.line-item-detail { text-align: center; }
.line-item-detail label { display: block; font-size: 0.65rem; color: var(--text3); text-transform: uppercase; margin-bottom: 2px; }
.line-item-detail span { font-size: 0.85rem; font-weight: 600; }
.line-item-total { text-align: right; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.line-item-total span { font-weight: 700; color: var(--accent); }

/* Add line button */
.add-line-btn {
  width: 100%; padding: 12px; border: 2px dashed var(--border);
  border-radius: var(--radius-sm); background: none; color: var(--text3);
  cursor: pointer; font-family: inherit; font-size: 0.85rem; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all 0.2s;
}
.add-line-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Totals */
.totals-section {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-top: 16px;
}
.total-row { display: flex; justify-content: space-between; padding: 6px 0;
  font-size: 0.9rem; color: var(--text2); }
.total-row.grand { font-size: 1.15rem; font-weight: 800; color: var(--text);
  border-top: 2px solid var(--border); margin-top: 8px; padding-top: 12px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-content {
  background: var(--bg-secondary); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 500px; max-height: 85dvh; overflow-y: auto;
  animation: slideUp 0.3s ease;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 20px 12px; position: sticky; top: 0;
  background: var(--bg-secondary); z-index: 1;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text2); padding: 4px; cursor: pointer; }
.modal-body { padding: 16px 20px 24px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px); left: 50%; transform: translateX(-50%);
  z-index: 2000; padding: 12px 24px; border-radius: 12px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s ease; font-size: 0.85rem; font-weight: 500;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* Tabs / Filters */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto;
  padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border);
  background: none; color: var(--text2); font-family: inherit; font-size: 0.8rem;
  font-weight: 500; cursor: pointer; white-space: nowrap; transition: all 0.2s;
}
.tab.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Empty State */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text3);
}
.empty-state svg { margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 { font-size: 1rem; color: var(--text2); margin-bottom: 8px; }
.empty-state p { font-size: 0.85rem; margin-bottom: 20px; }

/* Logo upload */
.logo-upload {
  width: 120px; height: 120px; border: 2px dashed var(--border);
  border-radius: var(--radius); display: flex; flex-direction: column;
  align-items: center; justify-content: center; cursor: pointer;
  transition: border-color 0.2s; overflow: hidden; position: relative;
}
.logo-upload:hover { border-color: var(--accent); }
.logo-upload img { width: 100%; height: 100%; object-fit: contain; }
.logo-upload-text { font-size: 0.75rem; color: var(--text3); text-align: center; padding: 8px; }
.logo-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Separator */
.separator { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Settings sections */
.settings-section { margin-bottom: 24px; }
.settings-section-title {
  font-size: 0.8rem; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px;
}

/* Confirm dialog */
.confirm-actions { display: flex; gap: 10px; margin-top: 20px; }
.confirm-actions .btn { flex: 1; }

/* Article card */
.article-type-badge {
  display: inline-flex; padding: 2px 8px; border-radius: 4px;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
}
.article-type-badge.article { background: rgba(99,102,241,0.12); color: var(--accent); }
.article-type-badge.service { background: rgba(6,182,212,0.12); color: var(--accent2); }

/* Client section */
.client-section {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.client-section-title {
  font-size: 0.8rem; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}

/* Status selector */
.status-select { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.status-option {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: none; color: var(--text2); font-family: inherit; font-size: 0.78rem;
  font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.status-option.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Article selector in form */
.article-selector {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); max-height: 200px; overflow-y: auto;
  margin-bottom: 8px;
}
.article-selector-item {
  padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background 0.15s; display: flex; justify-content: space-between; align-items: center;
}
.article-selector-item:hover { background: rgba(99,102,241,0.08); }
.article-selector-item:last-child { border-bottom: none; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideDown { from { transform: translateY(-100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastIn { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* Page transitions */
.view-enter { animation: viewSlideIn 0.3s ease; }
@keyframes viewSlideIn { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: translateY(0); } }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* PDF hidden render area */
#pdf-render { position: fixed; left: -9999px; top: 0; }
