@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

:root {
  --ink: #1a1a2e;
  --ink-light: #4a4a6a;
  --paper: #faf9f6;
  --paper-warm: #f0ede6;
  --ledger: #e8e3d8;
  --rule: #d4cfc4;
  --accent: #c17f3a;
  --accent-light: #e8a85a;
  --accent-pale: #fdf3e3;
  --green: #2d6a4f;
  --green-light: #d8f3dc;
  --red: #9b2226;
  --red-light: #ffe0e0;
  --blue: #1d4e89;
  --blue-light: #dbeafe;
  --shadow: 0 2px 12px rgba(26,26,46,0.08);
  --shadow-lg: 0 8px 32px rgba(26,26,46,0.12);
  --radius: 4px;
  --font-display: 'Playfair Display', serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --font-body: 'IBM Plex Sans', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── HEADER ── */
#app-header {
  background: var(--ink);
  color: var(--paper);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 3px solid var(--accent);
}
#app-header .brand {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--paper);
}
#app-header .brand span { color: var(--accent-light); }
.header-actions { display: flex; gap: 8px; }
.header-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--paper);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: background 0.2s;
}
.header-btn:hover { background: rgba(255,255,255,0.2); }
.header-btn.accent { background: var(--accent); border-color: var(--accent); }
.header-btn.accent:hover { background: var(--accent-light); }

/* ── LAYOUT ── */
#app-body { display: flex; flex: 1; min-height: 0; }

/* ── SIDEBAR ── */
#sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,0.05);
}
.nav-section { padding: 16px 0 8px; }
.nav-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-light);
  padding: 0 16px 6px;
  font-family: var(--font-mono);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 0.85rem;
  color: rgba(250,249,246,0.75);
  transition: all 0.15s;
  border-left: 3px solid transparent;
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: var(--paper); }
.nav-item.active {
  background: rgba(193,127,58,0.15);
  color: var(--accent-light);
  border-left-color: var(--accent);
}
.nav-icon { font-size: 0.95rem; width: 18px; text-align: center; }

/* ── MAIN ── */
#main { flex: 1; overflow-y: auto; padding: 24px; }

/* ── PANELS ── */
.panel { display: none; }
.panel.active { display: block; }

.page-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}
.page-subtitle {
  color: var(--ink-light);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

/* ── CARDS ── */
.card {
  background: #fff;
  border: 1px solid var(--ledger);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--ledger);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}
.card-body { padding: 20px; }

/* ── FORMS ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1/-1; }
label { font-size: 0.78rem; font-weight: 600; color: var(--ink-light); letter-spacing: 0.04em; text-transform: uppercase; }
input, select, textarea {
  font-family: var(--font-body);
  font-size: 0.88rem;
  padding: 8px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(193,127,58,0.12);
}
textarea { resize: vertical; min-height: 60px; }

/* ── BUTTONS ── */
.btn {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); }
.btn-secondary { background: var(--ink); color: var(--paper); }
.btn-secondary:hover { background: var(--ink-light); }
.btn-ghost { background: transparent; border: 1px solid var(--rule); color: var(--ink); }
.btn-ghost:hover { background: var(--paper-warm); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-success { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 0.75rem; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
thead tr { background: var(--ink); color: var(--paper); }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
thead th.num { text-align: right; }
tbody tr { border-bottom: 1px solid var(--ledger); transition: background 0.1s; }
tbody tr:hover { background: var(--accent-pale); }
tbody td { padding: 9px 14px; vertical-align: middle; }
tbody td.num { text-align: right; font-family: var(--font-mono); font-size: 0.82rem; }
tbody td.mono { font-family: var(--font-mono); font-size: 0.82rem; }
tfoot tr { background: var(--paper-warm); font-weight: 600; border-top: 2px solid var(--rule); }
tfoot td { padding: 10px 14px; font-family: var(--font-mono); }
tfoot td.num { text-align: right; }

.amount-dr { color: var(--blue); }
.amount-cr { color: var(--red); }
.amount-pos { color: var(--green); }
.amount-neg { color: var(--red); }

/* ── BADGES ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-mono);
}
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-gold { background: var(--accent-pale); color: var(--accent); }

/* ── LINE ITEMS ── */
.line-items-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 0.84rem; }
.line-items-table th {
  background: var(--paper-warm);
  padding: 7px 10px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-light);
  border-bottom: 1px solid var(--rule);
}
.line-items-table td { padding: 6px 8px; border-bottom: 1px solid var(--ledger); }
.line-items-table input, .line-items-table select { padding: 5px 8px; }
.line-total { font-family: var(--font-mono); text-align: right; }

/* ── MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26,26,46,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  background: var(--ink);
  color: var(--paper);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.modal-title { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--paper); cursor: pointer; font-size: 1.2rem; opacity: 0.7; }
.modal-close:hover { opacity: 1; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--ledger); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* ── TOOLBAR ── */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar-spacer { flex: 1; }

/* ── DASHBOARD STATS ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: #fff;
  border: 1px solid var(--ledger);
  border-radius: var(--radius);
  padding: 16px 20px;
  border-top: 3px solid var(--accent);
  box-shadow: var(--shadow);
}
.stat-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-light); margin-bottom: 8px; }
.stat-value { font-family: var(--font-mono); font-size: 1.4rem; font-weight: 500; color: var(--ink); }
.stat-card.green { border-top-color: var(--green); }
.stat-card.red { border-top-color: var(--red); }
.stat-card.blue { border-top-color: var(--blue); }

/* ── REPORTS ── */
.report-container { background: #fff; border: 1px solid var(--ledger); border-radius: var(--radius); box-shadow: var(--shadow); }
.report-header { text-align: center; padding: 24px 32px 12px; border-bottom: 2px solid var(--ink); }
.report-company { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; }
.report-title { font-size: 1rem; font-weight: 600; margin: 4px 0; text-transform: uppercase; letter-spacing: 0.06em; }
.report-period { font-size: 0.85rem; color: var(--ink-light); }
.report-body { padding: 20px 32px 32px; }
.report-section-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  padding: 5px 10px;
  margin: 16px 0 4px;
}
.report-row { display: flex; justify-content: space-between; padding: 4px 10px; font-size: 0.88rem; border-bottom: 1px solid var(--ledger); }
.report-row:nth-child(even) { background: var(--paper-warm); }
.report-row.total { font-weight: 700; border-bottom: 2px solid var(--ink); background: var(--ledger); }
.report-row.subtotal { font-weight: 600; background: var(--paper-warm); border-bottom: 1px solid var(--ink); }
.report-row.grand-total { font-weight: 700; font-size: 0.95rem; background: var(--ink); color: var(--paper); margin-top: 4px; }
.report-num { font-family: var(--font-mono); font-size: 0.85rem; }

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast-msg {
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 0.84rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--accent);
  animation: slideIn 0.3s ease;
  pointer-events: auto;
}
.toast-msg.success { border-left-color: var(--green); }
.toast-msg.error { border-left-color: var(--red); }
@keyframes slideIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform:none; } }

/* ── MISC ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--ink-light); }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; }
.sep { border: none; border-top: 1px solid var(--ledger); margin: 16px 0; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.mt-1 { margin-top: 6px; }
.font-mono { font-family: var(--font-mono); }
.text-sm { font-size: 0.82rem; }
.text-muted { color: var(--ink-light); }
.print-only { display: none; }
/* ── IMPORT MODAL ── */
.import-mode-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 2px solid var(--ledger);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #fff;
}
.import-mode-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-pale);
}
.import-mode-card input[type=radio] { margin-top: 3px; accent-color: var(--accent); flex-shrink: 0; }
.import-mode-title { font-weight: 600; font-size: 0.88rem; margin-bottom: 3px; }
.import-mode-desc { font-size: 0.80rem; color: var(--ink-light); line-height: 1.5; }
.import-stat { display: inline-flex; align-items: center; gap: 5px; margin-right: 16px; }
.import-stat-count { font-family: var(--font-mono); font-weight: 600; color: var(--accent); }

@media print {
  #sidebar, #app-header, .toolbar, .btn, .header-actions { display: none !important; }
  .panel { display: none !important; }
  .print-only { display: block; }
  .panel.active { display: block !important; }
  .report-container { border: none; box-shadow: none; }
}
</style>

<style>
/* Journal entry display */
.je-lines { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.je-lines th { background: var(--paper-warm); padding: 5px 10px; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-light); }
.je-lines td { padding: 5px 10px; border-bottom: 1px solid var(--ledger); }
.je-lines td.num { text-align: right; font-family: var(--font-mono); }

/* Account tree */
.account-group { margin-bottom: 4px; }
.account-group-name { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-light); padding: 6px 0 2px; border-bottom: 1px solid var(--rule); margin-bottom: 4px; }
.account-item { display: flex; align-items: center; padding: 6px 8px; border-radius: var(--radius); cursor: pointer; gap: 8px; }
.account-item:hover { background: var(--accent-pale); }
.account-item.sub { padding-left: 24px; }
.account-code { font-family: var(--font-mono); font-size: 0.75rem; color: var(--ink-light); width: 50px; flex-shrink: 0; }
.account-name { font-size: 0.85rem; flex: 1; }
.account-type { font-size: 0.7rem; }

/* Filter row */
.filter-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.filter-row .form-group { margin-bottom: 0; }

/* Tab nav */
.tab-nav { display: flex; border-bottom: 2px solid var(--ledger); margin-bottom: 20px; }
.tab-btn { padding: 8px 18px; background: none; border: none; cursor: pointer; font-family: var(--font-body); font-size: 0.84rem; font-weight: 500; color: var(--ink-light); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s; }
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── PAGINATION ── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--ledger);
  background: var(--paper-warm);
  border-radius: 0 0 var(--radius) var(--radius);
  flex-wrap: wrap;
  gap: 8px;
}
.pagination-info {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-light);
}
.pagination-controls { display: flex; align-items: center; gap: 4px; }
.pg-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pg-btn:hover:not(:disabled) { background: var(--accent-pale); border-color: var(--accent); color: var(--accent); }
.pg-btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.pg-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.pg-ellipsis { padding: 0 4px; color: var(--ink-light); font-size: 0.8rem; line-height: 32px; }
.page-size-select {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 4px 8px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
