/* Workspace shell */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: var(--header-h); flex: none; display: flex; align-items: center; gap: 10px;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 60;
}
.topbar .brand {
  display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.03em;
  font-size: 16px; color: var(--primary-900); padding-right: 8px; white-space: nowrap;
}
.topbar .brand .mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--primary-900); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; letter-spacing: -.02em;
}
.topbar .brand em { font-style: normal; color: var(--primary-500); }
.biz-switch {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 9px; padding: 4px 9px 4px 5px; min-width: 0; max-width: 280px; height: 38px;
}
.biz-switch:hover { background: var(--primary-50); border-color: var(--primary-100); }
.biz-switch .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.biz-switch svg { width: 14px; height: 14px; color: var(--text-faint); flex: none; }
.topbar .page-crumb { font-size: 13px; color: var(--text-muted); padding-left: 4px; }
.topbar .spacer { flex: 1; }
.topbar .top-actions { display: flex; align-items: center; gap: 4px; }
.offline-pill { display: none; align-items: center; gap: 6px; font-size: 11px; color: var(--warning); background: var(--warning-bg); border-radius: 999px; padding: 3px 9px; }
body.is-offline .offline-pill { display: inline-flex; }

.shell-body { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px 10px 18px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto; z-index: 50;
}
.sidebar .group-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em; font-weight: 650;
  color: var(--text-faint); padding: 14px 10px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-muted); position: relative; text-decoration: none;
}
.nav-item:hover { background: var(--primary-50); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-50); color: var(--primary-800); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--primary-700);
}
.nav-item svg { width: 16px; height: 16px; flex: none; color: var(--text-faint); }
.nav-item.active svg { color: var(--primary-700); }
.nav-item .count { margin-left: auto; font-size: 10.5px; font-weight: 650; background: var(--danger-bg); color: var(--danger); padding: 1px 6px; border-radius: 999px; }
.sidebar .sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.content {
  flex: 1; min-width: 0; padding: 22px 26px 44px; max-width: 1480px; width: 100%;
  margin: 0 auto;
}
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 200px; }
.page-head h1 { font-size: 20px; }
.page-head .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 3px; }
.page-head .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-head { display: flex; align-items: center; gap: 12px; margin: 24px 0 12px; }
.section-head h2 { font-size: 14px; }
.section-head .link { margin-left: auto; font-size: 12px; }

/* Sidebar rail / mobile */
body.rail .sidebar { width: var(--sidebar-rail); }
body.rail .sidebar .nav-item span, body.rail .sidebar .group-label,
body.rail .sidebar .sidebar-foot .label, body.rail .sidebar .nav-item .count { display: none; }
body.rail .sidebar .nav-item { justify-content: center; padding: 9px; }
body.rail .sidebar .nav-item.active::before { left: -10px; }
body.rail .content { max-width: none; }

/* Mobile nav toggle button visibility */
[data-action="toggle-nav"] { display: none; }
@media (max-width: 900px) {
  [data-action="toggle-nav"] { display: inline-flex; }
}

/* Home shell */
.home-topbar { border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 60; }
.home-topbar .inner { max-width: 1280px; margin: 0 auto; height: var(--header-h); display: flex; align-items: center; gap: 12px; padding: 0 24px; }
.home-wrap { max-width: 1280px; margin: 0 auto; padding: 26px 24px 60px; }
.home-head { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.home-head h1 { font-size: 24px; letter-spacing: -.03em; }
.home-head .search-input { width: 300px; max-width: 100%; }

.biz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 16px; }
.biz-card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
  transition: .15s ease; min-height: 200px;
}
.biz-card:hover { border-color: var(--primary-500); box-shadow: 0 6px 22px rgba(18, 58, 125, .1); transform: translateY(-1px); }
.biz-card .top { display: flex; gap: 11px; align-items: flex-start; }
.biz-card .logo {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px; flex: none;
}
.biz-card .name { font-size: 14.5px; font-weight: 650; line-height: 1.3; }
.biz-card .meta { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.biz-card .mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; border-top: 1px solid var(--border); padding-top: 11px; }
.biz-card .mini-stats .lbl { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; }
.biz-card .mini-stats .val { font-family: var(--font-mono); font-size: 12px; font-weight: 600; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.biz-card .foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.biz-card .foot .last { font-size: 11px; color: var(--text-faint); margin-left: auto; text-align: right; }
.biz-card.add {
  border-style: dashed; border-color: var(--border-strong); background: var(--surface-2);
  align-items: center; justify-content: center; text-align: center; color: var(--text-muted); gap: 8px;
}
.biz-card.add:hover { border-color: var(--primary-500); color: var(--primary-700); background: var(--primary-50); }
.biz-card.add .plus { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-100); color: var(--primary-700); display: flex; align-items: center; justify-content: center; }
.biz-card.add .plus svg { width: 18px; height: 18px; }
.biz-card .kebab { position: absolute; top: 10px; right: 8px; }

/* Login */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.auth-art {
  background: linear-gradient(150deg, var(--primary-900) 0%, var(--primary-800) 52%, var(--primary-600) 100%);
  color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-art::after {
  content: ""; position: absolute; width: 460px; height: 460px; border-radius: 50%;
  background: radial-gradient(circle, rgba(42,98,192,.55), transparent 65%); right: -120px; bottom: -120px;
}
.auth-art .brand { font-size: 20px; font-weight: 700; letter-spacing: -.03em; }
.auth-art h1 { font-size: 34px; line-height: 1.15; letter-spacing: -.035em; max-width: 420px; margin-top: 40px; }
.auth-art p { color: #C9D6EC; font-size: 14px; max-width: 400px; margin-top: 14px; }
.auth-art ul { margin-top: 28px; display: flex; flex-direction: column; gap: 10px; font-size: 13px; color: #DCE6F6; }
.auth-art li { display: flex; gap: 9px; align-items: center; }
.auth-art li svg { width: 15px; height: 15px; color: #8FB3E8; }
.auth-art .foot { font-size: 11.5px; color: #8FA7C9; position: relative; z-index: 1; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 32px; background: var(--surface); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 20px; letter-spacing: -.02em; }
.auth-card .sub { color: var(--text-muted); font-size: 13px; margin-top: 5px; margin-bottom: 22px; }
.auth-alt { text-align: center; font-size: 12.5px; color: var(--text-muted); margin-top: 18px; }

/* Business workspace page patterns */
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.paper {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 36px 40px; box-shadow: 0 2px 18px rgba(15,23,42,.06); color: #111827;
}
.paper .paper-head { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 22px; border-bottom: 1px solid #E9EDF4; }
.paper .paper-brand { display: flex; gap: 12px; align-items: flex-start; }
.paper .paper-brand .logo { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; }
.paper .paper-brand h1 { font-size: 19px; margin: 0; letter-spacing: -.02em; }
.paper .paper-brand .det { font-size: 11.5px; color: #64748B; line-height: 1.55; margin-top: 4px; }
.paper .paper-title { text-align: right; }
.paper .paper-title .big { font-size: 22px; font-weight: 700; letter-spacing: .04em; color: var(--primary-800); }
.paper .paper-title .num { font-family: var(--font-mono); font-size: 12px; margin-top: 3px; }
.paper .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 22px 0; }
.paper .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: #94A3B8; font-weight: 650; margin-bottom: 5px; }
.paper .items { width: 100%; font-size: 12px; margin-top: 6px; }
.paper .items th { text-align: left; padding: 8px 8px; border-bottom: 1px solid #E9EDF4; color: #64748B; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.paper .items td { padding: 9px 8px; border-bottom: 1px solid #F1F4F9; vertical-align: top; }
.paper .items .r { text-align: right; font-family: var(--font-mono); }
.paper .totals { margin-left: auto; width: 260px; margin-top: 14px; font-size: 12.5px; }
.paper .totals .row { display: flex; justify-content: space-between; padding: 5px 0; }
.paper .totals .row.total { border-top: 2px solid var(--primary-800); margin-top: 5px; padding-top: 9px; font-size: 15px; font-weight: 700; }
.paper .totals .row .v { font-family: var(--font-mono); }
.paper .paper-notes { margin-top: 26px; padding-top: 16px; border-top: 1px solid #E9EDF4; font-size: 11.5px; color: #475569; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.paper .paper-notes h4 { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: #94A3B8; margin: 0 0 5px; }
.paper .watermark { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 76px; font-weight: 800; color: rgba(198,46,62,.08); transform: rotate(-22deg); pointer-events: none; letter-spacing: .1em; }
.paper-wrap { position: relative; }
.paper-table-wrap { overflow-x: auto; }

/* Report sheets */
.report-sheet { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 20px; box-shadow: var(--shadow); }
.report-sheet h2 { font-size: 15px; }
.report-sheet .report-head { display: flex; justify-content: space-between; gap: 14px; padding-bottom: 12px; margin-bottom: 6px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.report-sheet .report-meta { font-size: 11.5px; color: var(--text-muted); }
.aging-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; margin-top: 12px; }
.aging-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
.aging-box .lbl { font-size: 10.5px; color: var(--text-muted); }
.aging-box .val { font-family: var(--font-mono); font-weight: 600; margin-top: 3px; font-size: 13px; }

/* Command palette */
.palette-backdrop { position: fixed; inset: 0; z-index: 150; background: rgba(10,31,68,.34); display: flex; justify-content: center; padding-top: 12vh; }
.palette {
  width: 100%; max-width: 560px; max-height: 60vh; background: var(--surface); border-radius: 12px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; animation: pop-in .14s ease;
}
.palette .search-input { padding: 12px; border-bottom: 1px solid var(--border); }
.palette .search-input svg { left: 24px; }
.palette .search-input .input { height: 40px; padding-left: 36px; border: 0; box-shadow: none; font-size: 14px; }
.palette .results { overflow-y: auto; padding: 6px; }
.palette .p-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; font-size: 13px; width: 100%; border: 0; background: none; text-align: left; }
.palette .p-item:hover, .palette .p-item.sel { background: var(--primary-50); }
.palette .p-item svg { width: 15px; height: 15px; color: var(--text-faint); }
.palette .p-item .group { margin-left: auto; font-size: 10.5px; color: var(--text-faint); }
.palette .p-empty { padding: 24px; text-align: center; font-size: 12.5px; color: var(--text-muted); }

@media (max-width: 1100px) {
  .two-col, .invoice-layout { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: var(--header-h); bottom: 0; z-index: 70;
    transform: translateX(-100%); transition: transform .18s ease; width: 264px !important;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.rail .sidebar .nav-item span, body.rail .sidebar .group-label, body.rail .sidebar .sidebar-foot .label { display: inline; }
  body.rail .sidebar .nav-item { justify-content: flex-start; padding: 8px 10px; }
  .content { padding: 18px 16px 40px; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 680px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar .brand { padding-right: 2px; font-size: 14px; }
  .topbar .brand .mark { width: 24px; height: 24px; }
  .biz-switch { max-width: 160px; }
  .topbar .page-crumb { display: none; }
  .form-grid, .form-grid-3, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .home-head h1 { font-size: 20px; }
  .biz-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .modal-backdrop { padding: 10px; align-items: flex-end; }
  .modal { max-height: calc(100vh - 20px); border-radius: 14px 14px 0 0; }
  .paper { padding: 20px; }
  .paper .paper-head { flex-direction: column; }
  .paper .parties { grid-template-columns: 1fr; }
  .aging-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .home-topbar .inner { padding: 0 14px; }
  .home-wrap { padding: 18px 14px 40px; }
  .home-head .search-input { width: 100%; }
  .toolbar .search-input { width: 100%; }
  .table thead th:nth-child(n+6):not(.keep), .table tbody td:nth-child(n+6):not(.keep) { display: none; }
  .toast-region { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

/* Mobile table: horizontal scroll with sticky first column */
@media (max-width: 900px) {
  .table-wrap { 
    overflow-x: auto; 
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
  }
  .table-wrap::-webkit-scrollbar { height: 8px; }
  .table-wrap::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
  .table { min-width: 700px; }
  .table thead th:first-child,
  .table tbody td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--surface-2);
  }
  .table thead th { background: var(--surface-2); }
}

/* Mobile stat cards: 2-col grid */
@media (max-width: 680px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* Mobile biz cards: single column */
@media (max-width: 680px) {
  .biz-grid { grid-template-columns: 1fr; }
  .biz-card { min-height: auto; }
}

/* Mobile filter bar: stack fields */
@media (max-width: 680px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .field { min-width: 0; width: 100%; }
}

/* Mobile toolbar: full-width search */
@media (max-width: 680px) {
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar .search-input { width: 100%; }
  .toolbar > * { width: 100%; justify-content: flex-end; }
}

/* Mobile page head actions */
@media (max-width: 680px) {
  .page-head .actions { width: 100%; justify-content: flex-end; }
}

/* Mobile modal: full screen bottom sheet */
@media (max-width: 680px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-height: calc(100vh - 20px); border-radius: 14px 14px 0 0; max-width: 100%; margin: 0; }
  .modal.lg, .modal.xl { max-width: 100%; }
  .modal-header { padding: 14px 16px 8px; }
  .modal-body { padding: 8px 16px 16px; }
  .modal-footer { padding: 12px 16px; }
}

/* Mobile slideover: full screen */
@media (max-width: 680px) {
  .slideover-backdrop { justify-content: flex-end; }
  .slideover { max-width: 100%; width: 100%; height: 100%; border-radius: 14px 14px 0 0; }
  .slideover-header { padding: 14px 16px; }
  .slideover-body { padding: 12px 16px; }
  .slideover-footer { padding: 12px 16px; }
}

/* Mobile dropdown menus: position at bottom on small screens */
@media (max-width: 480px) {
  .menu.right { right: 0; left: auto; top: calc(100% + 6px); max-width: calc(100vw - 24px); }
  .menu.left { left: 0; right: auto; top: calc(100% + 6px); max-width: calc(100vw - 24px); }
}

/* Mobile KPI strip: scroll horizontally */
@media (max-width: 680px) {
  .kpi-strip { overflow-x: auto; padding-bottom: 8px; gap: 16px; }
  .kpi-strip .kpi { min-width: 140px; flex: 0 0 auto; }
}

/* Mobile aging grid: 2 columns */
@media (max-width: 680px) {
  .aging-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* Mobile chart containers */
@media (max-width: 680px) {
  .bar-chart { height: 120px; }
  .donut { width: 100px; height: 100px; }
}

/* Ensure touch targets are large enough */
@media (max-width: 680px) {
  .btn, .btn-icon { min-height: 40px; }
  .btn-icon { width: 40px; }
  .input, .select, .textarea { min-height: 40px; }
  .nav-item { padding: 12px 14px; }
}
