/* AppSite Books - General Ledger & Chart of Accounts */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ed;
  --text: #1a2332;
  --text-muted: #6b7a8f;
  --primary: #0f766e;
  --primary-hover: #0d6460;
  --primary-light: #edf7f6;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --radius: 8px;
  --sidebar-w: 220px;
}

html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 20px;
}
/* Landing page — allow scroll */
body.landing { height: auto; overflow: auto; min-height: 100dvh; }

#app, .app { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#appsiteTopNav, #appsite-topnav, .appsite-topnav, .appsite-topnav-shell, header.appsite-topnav, .tl-topnav, .topnav-module {
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  z-index: 1000;
}

/* ── Topbar (new pattern) ── */

/* ── Topbar ── */
header.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: nowrap; flex-shrink: 0; overflow: visible; position: relative; }
header.topbar h1 { font-size: 15px; font-weight: 700; white-space: nowrap; flex-shrink: 0; }
header.topbar .actions { display: flex; flex-wrap: nowrap; gap: 4px; align-items: center; min-width: 0; overflow: hidden; flex: 1; justify-content: flex-end; }
header.topbar .actions input[type="search"], header.topbar .actions select { font-size: 11px; padding: 2px 6px; height: 26px; min-width: 80px; max-width: 130px; }
header.topbar .actions button, header.topbar .actions .btn { font-size: 11px; padding: 0 8px; height: 26px; white-space: nowrap; flex-shrink: 0; }

/* ── Layout pattern — managed by appsite-module-layout.js ── */
/* ── Layout grid ──────────────────────────────────────────────────────────── */
.workspace { display: flex; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns .2s ease;
}
.layout.sidebar-collapsed { grid-template-columns: 36px minmax(0, 1fr); }
.order-list {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius,8px);
}
.order-list-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.order-editor { min-width: 0; min-height: 0; overflow: auto; }

/* Sidebar collapsed: hide content except toggle + rail label */
.layout.sidebar-collapsed .order-list > :not(.sidebar-toggle-btn):not(.sidebar-rail-label) { display: none !important; }
.sidebar-rail-label { display: none; }
.layout.sidebar-collapsed .sidebar-rail-label {
  display: block;
  position: absolute;
  inset: 48px 0 auto 0;
  transform: rotate(-90deg) translateX(-100%);
  transform-origin: left top;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
  width: max-content;
  margin-left: 10px;
}

/* Toggle chevron — always visible, positioned by app.js */
.sidebar-toggle-btn {
  position: fixed;
  z-index: 200;
  width: 24px;
  height: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-muted);
}
.sidebar-toggle-btn:hover { background: var(--bg); }
.order-item { padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.order-item:hover { background: var(--bg); }
.order-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.order-item:last-child { border-bottom: 0; }
.order-editor { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius,8px); display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }
.wo-header-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.wo-header-left { display: flex; align-items: center; gap: 10px; }
.wo-header-left h2 { font-size: 16px; font-weight: 700; }
.wo-status-chip { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--text-muted,#6b7280); background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 2px 9px; }
.wo-header-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.btn-primary-action { background: var(--primary); border: 1px solid var(--primary); color: #fff; font-weight: 600; padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; min-height: 32px; }
.wo-tabs { display: flex; gap: 2px; padding: 8px 20px 0; background: var(--surface); border-bottom: 2px solid var(--border); position: sticky; top: 57px; z-index: 9; flex-wrap: wrap; }
.wo-tab { padding: 7px 14px; border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0; background: transparent; font: inherit; font-size: 12px; font-weight: 600; color: var(--text-muted,#6b7280); cursor: pointer; white-space: nowrap; }
.wo-tab.active { background: var(--surface); border-color: var(--border); color: var(--primary); margin-bottom: -2px; padding-bottom: 9px; }
.wo-tab-panel { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px; }
.wo-form { display: flex; flex-direction: column; }
.wo-row { display: flex; gap: 12px; }
.wo-row.four-col { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }

/* App layout */
.app-layout { display: flex; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; }
.sidebar-header { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.sidebar-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.sidebar-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 0; }
.account-group { margin-bottom: 4px; }
.account-group-label { padding: 6px 16px 2px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); display: flex; align-items: center; justify-content: space-between; }
.account-group-total { font-size: 10px; font-weight: 600; color: var(--text); }
.workspace-toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.workspace-title { font-size: 15px; font-weight: 700; flex: 1; }
.workspace-subtitle { font-size: 12px; color: var(--text-muted); }
.workspace-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 20px; }
.sidebar-action-btn { margin: 8px 12px; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 12px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer; width: calc(100% - 24px); }
.sidebar-action-btn:hover { background: var(--primary-hover); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-header { padding: 12px 16px 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { font-size: 13px; font-weight: 700; color: var(--text); }
.card-body { padding: 0; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.summary-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin-bottom: 4px; }
.summary-value { font-size: 20px; font-weight: 700; color: var(--text); }
.summary-value.positive { color: var(--success); }
.summary-value.negative { color: var(--danger); }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 9px 14px; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); background: var(--bg); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }
.data-table tr.entry-total td { font-weight: 700; background: var(--bg); border-top: 2px solid var(--border); }
.table-wrap { width: 100%; overflow-x: auto; }
.amount-credit, .summary-value.positive { color: var(--success); }
.amount-negative, .summary-value.negative { color: var(--danger); }

button { font-family: inherit; cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600; border: 1px solid transparent; transition: background 0.15s, opacity 0.15s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-surface { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-surface:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; padding: 5px 8px; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.icon-btn { width: 30px; height: 30px; border-radius: 6px; border: 1px solid transparent; background: transparent; color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--bg); color: var(--text); }

.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
label.field, .field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.field-input, input[type="text"], input[type="number"], input[type="date"], select, textarea { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; color: var(--text); background: var(--surface); outline: none; transition: border-color 0.15s; }
.field-input:focus, input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 60px; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding-top: 12px; }
.entry-lines { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.entry-line-row { display: grid; grid-template-columns: 1fr 140px 140px 28px; gap: 6px; align-items: center; }
.entry-line-row select, .entry-line-row input { padding: 6px 8px; font-size: 12px; }
.entry-remove-btn { background: none; border: none; color: var(--text-muted); font-size: 16px; line-height: 1; padding: 2px; border-radius: 4px; cursor: pointer; }
.entry-remove-btn:hover { color: var(--danger); background: var(--danger-light); }
.balance-indicator { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 4px; display: inline-block; }
.balance-indicator.balanced { background: #dcfce7; color: var(--success); }
.balance-indicator.unbalanced { background: var(--danger-light); color: var(--danger); }
.account-type-tag { display: inline-block; padding: 2px 7px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.tag-asset { background: #dbeafe; color: #1d4ed8; }
.tag-liability { background: #fce7f3; color: #9d174d; }
.tag-equity { background: #ede9fe; color: #6d28d9; }
.tag-revenue { background: #dcfce7; color: #166534; }
.tag-expense { background: #fef9c3; color: #92400e; }

.empty-state, .loading-state { padding: 42px 20px; text-align: center; color: var(--text-muted); }
.empty-state-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.hidden, [hidden] { display: none !important; }

.modal-backdrop { position: fixed; inset: 0; z-index: 2000; background: rgba(15, 23, 42, 0.38); display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.active, .modal-backdrop.open, .modal-backdrop.show { display: flex; }
.modal { display: none; position: fixed; inset: 0; z-index: 2001; align-items: center; justify-content: center; padding: 20px; background: rgba(15, 23, 42, 0.38); }
.modal.active, .modal.open, .modal.show, .modal[aria-hidden="false"] { display: flex; }
.modal-card, .dialog, .modal-content { width: min(720px, 100%); max-height: calc(100dvh - 40px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 18px 50px rgba(15,23,42,0.22); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 700; color: var(--text); }
.modal-close { border: none; background: transparent; color: var(--text-muted); font-size: 18px; line-height: 1; padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 3000; padding: 10px 14px; border-radius: 8px; background: var(--text); color: #fff; box-shadow: var(--shadow); font-size: 13px; }

@media (max-width: 760px) {
  html, body { overflow: auto; }
  body { min-height: 100vh; }
  .workspace { overflow: visible; padding: 8px; }
  .layout, .layout.sidebar-collapsed { grid-template-columns: 1fr !important; grid-template-rows: auto 1fr; }
  .order-list { max-height: 220px; }
  .layout.accounts-hidden .order-list { display: none; }
  #accountsListToggle { display: none !important; }
  #mobileAccountsToggle { display: inline-flex !important; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .form-grid.two, .form-grid.three, .entry-line-row { grid-template-columns: 1fr; }
  header.topbar .actions { gap: 6px; }
}

.mobile-menu-btn { display: none !important; }

/* Mobile menu panel */
.mobile-menu-panel {
  position: absolute; top: 100%; right: 0; z-index: 500;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  min-width: 200px; padding: 6px 0; display: flex; flex-direction: column;
}
.mobile-menu-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 16px; font: inherit; font-size: 13px; font-weight: 500;
  background: none; border: none; cursor: pointer; color: var(--text);
}
.mobile-menu-item:hover { background: var(--soft, #f5f7fa); }
.mobile-menu-primary { color: var(--primary); font-weight: 600; }
.mobile-menu-divider { margin: 4px 0; border: none; border-top: 1px solid var(--border); }

/* Narrow layout — triggered by JS ResizeObserver adding .narrow to body */
body.narrow .workspace { overflow: visible; padding: 8px; }
body.narrow .layout, body.narrow .layout.sidebar-collapsed { grid-template-columns: 1fr !important; grid-template-rows: auto 1fr; }
body.narrow .order-list { max-height: 220px; }
body.narrow .layout.accounts-hidden .order-list { display: none; }
body.narrow #accountsListToggle { display: none !important; }
body.narrow #topbarActions { display: none !important; }
body.narrow .mobile-menu-btn { display: inline-flex !important; }
body.narrow .summary-grid { grid-template-columns: 1fr 1fr; }
body.narrow .form-grid.two, body.narrow .form-grid.three, body.narrow .entry-line-row { grid-template-columns: 1fr; }

/* ── Landing page ── */
.sso-banner { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1000; }
.sso-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--border); }
.sso-name { font-weight: 600; font-size: 14px; }
.sso-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.btn-link { color: var(--primary); font-size: 13px; font-weight: 600; text-decoration: none; }
.btn-sm { font-size: 12px; padding: 4px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; cursor: pointer; }
.eyebrow { margin: 0 0 2px; color: var(--primary); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.landing-wrap { max-width: 900px; margin: 0 auto; padding: 48px 24px 32px; }
.landing-hero { text-align: center; margin-bottom: 40px; }
.landing-hero h1 { font-size: 40px; font-weight: 800; margin: 0 0 10px; }
.landing-sub { color: var(--text-muted); font-size: 16px; margin-top: 6px; max-width: 520px; margin-left: auto; margin-right: auto; }
.landing-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 24px; justify-content: center; }
.btn-signin { display: inline-block; padding: 10px 28px; background: var(--primary); color: #fff; border-radius: 8px; font-size: 15px; font-weight: 700; text-decoration: none; }
.btn-signin:hover { background: var(--primary-hover); }
.btn-hub { display: inline-block; padding: 10px 20px; background: transparent; color: var(--text-muted); border-radius: 8px; font-size: 14px; font-weight: 600; text-decoration: none; border: 1px solid var(--border); }
.btn-hub:hover { border-color: var(--primary); color: var(--primary); }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 32px; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px 18px; }
.feature-card svg { width: 26px; height: 26px; stroke: var(--primary); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; display: block; margin-bottom: 12px; }
.feature-card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 700; }
.feature-card p { margin: 0; color: var(--text-muted); font-size: 13px; }
.landing-footer { text-align: center; padding: 24px 16px; font-size: 12px; color: var(--text-muted); }
.landing-footer a { color: inherit; text-decoration: underline; }

