/* Smart Documents Writer - Styles */
:root {
  --bg: #0f1219;
  --bg-2: #161a23;
  --bg-3: #1e2230;
  --bg-4: #262b3a;
  --border: #2a2f3d;
  --border-soft: #1f232e;
  --text: #e8ecf4;
  --text-muted: #9aa3b2;
  --text-dim: #6b7280;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --accent-soft: rgba(91, 140, 255, 0.12);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* Layout */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 240px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 100vh;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.logo-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 700; color: white;
  box-shadow: 0 4px 12px rgba(91,140,255,0.35);
}
.logo-text { font-weight: 700; font-size: 15px; }
.logo-sub { font-size: 11px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer; font-size: 13px;
  transition: background .15s, color .15s;
  user-select: none;
}
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-section { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); padding: 14px 10px 6px; font-weight: 600; }

.sidebar-footer { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-dim); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: 60px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: var(--bg-2); flex-shrink: 0;
}
.topbar-title { font-size: 18px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-3);
  color: var(--text); font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  font-family: inherit;
}
.btn:hover { background: var(--bg-4); border-color: #3a3f4d; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { background: #6d9bff; }
.btn.success { background: var(--success); border-color: var(--success); color: #0a2a1a; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: rgba(248,113,113,0.1); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-3); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn svg { width: 14px; height: 14px; }

.content { flex: 1; overflow: auto; padding: 24px; }

/* Cards / panels */
.card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.card-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat-hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* Tables */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; font-size: 13px; }
th { background: var(--bg-3); color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; position: sticky; top: 0; }
td { border-top: 1px solid var(--border-soft); }
tr:hover td { background: rgba(255,255,255,0.02); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
}
.badge.invoice { background: rgba(91,140,255,0.15); color: var(--accent); }
.badge.receipt { background: rgba(52,211,153,0.15); color: var(--success); }
.badge.delivery { background: rgba(251,191,36,0.15); color: var(--warning); }
.badge.quotation { background: rgba(167,139,250,0.15); color: #a78bfa; }
.badge.purchaseorder { background: rgba(244,114,182,0.15); color: #f472b6; }
.badge.creditnote { background: rgba(251,146,60,0.15); color: #fb923c; }
.badge.proforma { background: rgba(34,211,238,0.15); color: #22d3ee; }
.badge.paid { background: rgba(52,211,153,0.15); color: var(--success); }
.badge.unpaid { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge.partial { background: rgba(251,191,36,0.15); color: var(--warning); }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
.form-group.third { grid-column: span 1; }
label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
input, textarea, select {
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text); padding: 9px 11px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13px; outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
.form-section { margin-top: 18px; }
.form-section-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border-soft); }

/* Items table */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th, .items-table td { padding: 6px 4px; }
.items-table th { font-size: 11px; }
.items-table input { padding: 6px 8px; font-size: 12px; }
.items-table .col-desc { width: 40%; }
.items-table .col-qty { width: 10%; }
.items-table .col-price { width: 15%; }
.items-table .col-tax { width: 12%; }
.items-table .col-amount { width: 13%; text-align: right; }
.items-table .col-action { width: 10%; text-align: center; }
.items-table td.amount { text-align: right; font-weight: 500; }

.totals-box {
  margin-top: 16px; padding: 14px; background: var(--bg-3);
  border-radius: var(--radius-sm); border: 1px solid var(--border-soft);
  max-width: 360px; margin-left: auto;
}
.totals-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.totals-row.total { font-weight: 700; font-size: 15px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; color: var(--accent); }
.totals-row input { width: 120px; padding: 4px 8px; text-align: right; }

/* Empty state */
.empty {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty h3 { font-size: 15px; color: var(--text); margin-bottom: 6px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: none; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); width: 90%; max-width: 460px;
  padding: 20px; box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: var(--bg-3); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); font-size: 13px;
  transform: translateY(100px); opacity: 0; transition: all .25s;
  pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* Template variants for doc-preview */
.doc-preview.tpl-modern { --tpl-accent: #5b8cff; --tpl-header-bg: #f4f6fa; }
.doc-preview.tpl-minimal { --tpl-accent: #1a1a1a; --tpl-header-bg: transparent; font-family: 'Inter', sans-serif; }
.doc-preview.tpl-classic { --tpl-accent: #2c3e50; --tpl-header-bg: #eef1f5; font-family: 'Georgia', serif; }
.doc-preview.tpl-bold { --tpl-accent: #111; --tpl-header-bg: #111; color: #111; }
.doc-preview.tpl-bold .doc-title { color: #fff; }
.doc-preview.tpl-bold .doc-brand { color: #fff; }
.doc-preview.tpl-bold .doc-header { background: #111; padding: 24px; margin: -40px -40px 30px; color: #fff; }
.doc-preview.tpl-bold .doc-brand-sub { color: #ccc; }
.doc-preview.tpl-bold .doc-meta { color: #ccc; }
.doc-preview.tpl-bold .doc-table th { background: #111; color: #fff; }
.doc-preview.tpl-bold .doc-totals-row.total { color: #111; border-color: #111; }

/* Additional professional templates */
.doc-preview.tpl-executive { --tpl-accent: #1f3864; font-family: 'Georgia', serif; }
.doc-preview.tpl-executive .doc-title { color: #1f3864; letter-spacing: 2px; }
.doc-preview.tpl-executive .doc-header { border-bottom: 3px double #1f3864; padding-bottom: 16px; }
.doc-preview.tpl-executive .doc-table th { background: #1f3864; color: #fff; }

.doc-preview.tpl-corporate { --tpl-accent: #0e7490; font-family: 'Inter', sans-serif; }
.doc-preview.tpl-corporate .doc-title { color: #0e7490; font-weight: 800; }
.doc-preview.tpl-corporate .doc-header { background: linear-gradient(90deg, #0e7490, #155e75); padding: 20px; margin: -40px -40px 30px; color: #fff; border-radius: 4px 4px 0 0; }
.doc-preview.tpl-corporate .doc-brand { color: #fff; }
.doc-preview.tpl-corporate .doc-brand-sub { color: #d1f0f7; }
.doc-preview.tpl-corporate .doc-meta { color: #d1f0f7; }
.doc-preview.tpl-corporate .doc-title { color: #fff; }
.doc-preview.tpl-corporate .doc-table th { background: #0e7490; color: #fff; }
.doc-preview.tpl-corporate .doc-totals-row.total { color: #0e7490; }

.doc-preview.tpl-elegant { --tpl-accent: #7c3aed; font-family: 'Inter', sans-serif; }
.doc-preview.tpl-elegant .doc-title { color: #7c3aed; font-weight: 300; letter-spacing: 4px; text-transform: uppercase; }
.doc-preview.tpl-elegant .doc-header { border-bottom: 1px solid #e5e7eb; padding-bottom: 20px; }
.doc-preview.tpl-elegant .doc-table th { background: transparent; color: #7c3aed; border-bottom: 2px solid #7c3aed; }
.doc-preview.tpl-elegant .doc-totals { border-top: 1px solid #e5e7eb; padding-top: 12px; }
.doc-preview.tpl-elegant .doc-totals-row.total { color: #7c3aed; }

.doc-preview.tpl-sleek { --tpl-accent: #0f172a; font-family: 'Inter', sans-serif; }
.doc-preview.tpl-sleek .doc-title { color: #0f172a; font-weight: 900; }
.doc-preview.tpl-sleek .doc-table th { background: #f1f5f9; color: #0f172a; border-bottom: 2px solid #0f172a; }
.doc-preview.tpl-sleek .doc-totals-row.total { background: #0f172a; color: #fff; padding: 8px 12px; border-radius: 4px; }

.doc-preview.tpl-minimal .doc-table th { background: transparent; border-bottom: 1px solid #ccc; }
.doc-preview.tpl-minimal .doc-title { color: #1a1a1a; }
.doc-preview.tpl-classic .doc-title { color: #2c3e50; }
.doc-preview.tpl-classic .doc-table { border: 1px solid #ccc; }
.doc-preview.tpl-classic .doc-table th { background: #eef1f5; }

.doc-preview .doc-title { color: var(--tpl-accent, #5b8cff); }

/* Preview / print document */
.doc-preview {
  background: white; color: #1a1a1a; padding: 40px;
  max-width: 780px; margin: 0 auto; border-radius: 4px;
  box-shadow: var(--shadow); font-family: 'Inter', sans-serif;
}
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; }
.doc-brand { font-size: 22px; font-weight: 700; color: #1a1a1a; }
.doc-brand-sub { font-size: 11px; color: #666; margin-top: 2px; }
.doc-title { font-size: 26px; font-weight: 700; color: #5b8cff; text-align: right; }
.doc-meta { text-align: right; font-size: 11px; color: #666; margin-top: 4px; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.doc-party-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; color: #888; margin-bottom: 4px; font-weight: 600; }
.doc-party-name { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.doc-party-line { font-size: 12px; color: #555; line-height: 1.4; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.doc-table th { background: #f4f6fa; color: #555; padding: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 2px solid #e2e6ee; }
.doc-table td { padding: 8px; font-size: 12px; border-bottom: 1px solid #eee; }
.doc-table td.right, .doc-table th.right { text-align: right; }
.doc-totals { margin-left: auto; width: 260px; }
.doc-totals-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; }
.doc-totals-row.total { font-weight: 700; font-size: 14px; border-top: 2px solid #1a1a1a; padding-top: 8px; margin-top: 4px; color: #5b8cff; }
.doc-notes { margin-top: 24px; padding-top: 16px; border-top: 1px solid #eee; }
.doc-notes h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: #888; margin-bottom: 4px; }
.doc-notes p { font-size: 11px; color: #555; line-height: 1.5; }
.doc-sig { margin-top: 40px; display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.doc-sig-line { border-top: 1px solid #999; padding-top: 6px; font-size: 11px; color: #666; }

/* Settings form */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { width: 64px; }
  .logo-text, .logo-sub, .nav-item span, .nav-section { display: none; }
  .nav-item { justify-content: center; }
  .form-grid, .settings-grid { grid-template-columns: 1fr; }
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* Mobile bottom nav */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-2); border-top: 1px solid var(--border);
  padding: 6px 4px; z-index: 50;
  overflow-x: auto; gap: 2px; justify-content: flex-start;
}
.mobile-nav-item { flex: 0 0 auto; min-width: 60px; }
.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; color: var(--text-muted); cursor: pointer; font-size: 10px;
  border-radius: 6px;
}
.mobile-nav-item svg { width: 20px; height: 20px; }
.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item:hover { background: var(--bg-3); }

@media (max-width: 768px) {
  .mobile-nav { display: flex; }
  .sidebar { display: none; }
  .main { padding-bottom: 64px; }
  .content { padding: 14px; }
  .topbar { padding: 0 14px; height: 54px; }
  .topbar-title { font-size: 16px; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .doc-preview { padding: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .items-table .col-desc { width: 34%; }
  .items-table .col-qty { width: 12%; }
  .items-table .col-price { width: 18%; }
  .items-table .col-tax { width: 14%; }
  .items-table .col-amount { width: 16%; }
  .items-table .col-action { width: 6%; }
  .totals-box { max-width: 100%; }
  .modal { width: 95%; }
}

/* Print */
@media print {
  body { background: white; overflow: visible; }
  .app { display: block; }
  .sidebar, .topbar, .no-print { display: none !important; }
  .content { padding: 0; overflow: visible; }
  .doc-preview { box-shadow: none; max-width: 100%; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a3f4d; }

.hidden { display: none !important; }
.fade-in { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Search bar */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 10px; width: 240px;
}
.search-bar input { background: transparent; border: none; padding: 2px; flex: 1; }
.search-bar svg { width: 14px; height: 14px; color: var(--text-dim); }

/* filter chips */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  padding: 5px 11px; border-radius: 999px; font-size: 12px;
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* action row */
.actions-cell { display: flex; gap: 4px; }