:root {
  --primary: #172554;
  --primary-soft: #1e3a8a;
  --secondary: #2563eb;
  --accent: #f59e0b;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --success: #16a34a;
  --danger: #dc2626;
  --muted: #64748b;
  --border: #e2e8f0;
  --sidebar-w: 268px;
  --sidebar-collapsed: 84px;
  --topbar-h: 68px;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body.app-body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 100% -10%, #e8eefc 0%, var(--bg) 45%);
  color: #0f172a;
  min-height: 100vh;
}

a { color: var(--secondary); text-decoration: none; }
a:hover { color: var(--primary); }

/* Sidebar */
.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary) 0%, #0f1b3d 100%);
  color: #fff;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: width .25s ease, transform .25s ease;
  box-shadow: 8px 0 30px rgba(15, 23, 42, .15);
}
.app-sidebar.collapsed { width: var(--sidebar-collapsed); }
.app-sidebar.collapsed .brand-title,
.app-sidebar.collapsed .brand-sub,
.app-sidebar.collapsed .sidebar-link span,
.app-sidebar.collapsed .sidebar-user-meta { display: none; }
.app-sidebar.collapsed .sidebar-brand { justify-content: center; }
.app-sidebar.collapsed .sidebar-link { justify-content: center; padding-inline: 0; }
.app-sidebar.collapsed .brand-logo { margin: 0; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: relative;
}
.brand-logo {
  width: 40px; height: 40px; object-fit: contain; border-radius: 10px;
  background: rgba(255,255,255,.1); padding: 4px;
}
.brand-title { font-weight: 800; letter-spacing: .04em; font-size: 1.15rem; line-height: 1; }
.brand-sub { font-size: .7rem; opacity: .7; margin-top: 3px; }
.sidebar-collapse-btn {
  margin-left: auto;
  background: rgba(255,255,255,.08);
  border: 0; color: #fff; width: 32px; height: 32px;
  border-radius: 8px; align-items: center; justify-content: center;
}
.sidebar-nav { padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; overflow: auto; }
.sidebar-link {
  display: flex; align-items: center; gap: 12px;
  color: rgba(255,255,255,.78); padding: 12px 14px; border-radius: 12px;
  font-weight: 600; font-size: .92rem; transition: .2s;
}
.sidebar-link i { font-size: 1.15rem; width: 22px; text-align: center; }
.sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-link.active {
  background: var(--secondary);
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, .35);
}
.sidebar-link.danger { color: #fecaca; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding: 8px; }
.sidebar-user-meta { display: flex; flex-direction: column; font-size: .8rem; }
.sidebar-user-meta small { opacity: .65; }

.avatar {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--secondary), var(--accent));
  display: grid; place-items: center; font-weight: 800; color: #fff;
}
.avatar.sm { width: 34px; height: 34px; border-radius: 10px; font-size: .85rem; }

.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; display: none;
}
.sidebar-backdrop.show { display: block; }

/* Main */
.app-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin-left .25s ease;
}
.app-main.expanded { margin-left: var(--sidebar-collapsed); }

.app-topbar {
  height: var(--topbar-h);
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; position: sticky; top: 0; z-index: 1020; gap: 16px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.page-heading { font-size: 1.05rem; font-weight: 800; margin: 0; }
.breadcrumb { font-size: .85rem; }
.breadcrumb a { color: var(--muted); }
.breadcrumb-item.active { color: var(--primary); font-weight: 600; }

.btn-icon {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); display: inline-flex; align-items: center; justify-content: center;
}
.profile-btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 4px 10px 4px 4px; font-weight: 600;
}

.global-search {
  position: relative; width: min(360px, 42vw);
}
.global-search i {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted);
}
.global-search .form-control {
  padding-left: 38px; border-radius: 12px; border-color: var(--border); height: 42px;
  background: #f8fafc;
}
.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); max-height: 360px; overflow: auto; z-index: 50;
}
.search-item {
  display: block; padding: 12px 14px; border-bottom: 1px solid #f1f5f9; color: inherit;
}
.search-item:hover { background: #f8fafc; }
.search-item small { color: var(--muted); }

.notif-dot {
  position: absolute; top: 8px; right: 8px; width: 8px; height: 8px;
  background: var(--danger); border-radius: 50%;
}
.notif-menu { width: 320px; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); }
.notif-header { padding: 12px 14px; font-weight: 700; border-bottom: 1px solid var(--border); }
.notif-list { max-height: 320px; overflow: auto; }
.notif-item { padding: 12px 14px; border-bottom: 1px solid #f1f5f9; }
.notif-item.unread { background: #eff6ff; }

.app-content { padding: 24px; flex: 1; }
.app-footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 24px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border);
}

/* Cards & surfaces */
.surface {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(15,23,42,.08); }
.stat-card .label { color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.stat-card .value { font-size: 1.45rem; font-weight: 800; margin-top: 6px; color: var(--primary); }
.stat-card .icon {
  position: absolute; right: 16px; top: 16px; width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.2rem;
}
.stat-card.revenue .icon { background: #dbeafe; color: var(--secondary); }
.stat-card.invoiced .icon { background: #e0e7ff; color: #4338ca; }
.stat-card.payments .icon { background: #dcfce7; color: var(--success); }
.stat-card.outstanding .icon { background: #fee2e2; color: var(--danger); }
.stat-card.expenses .icon { background: #ffedd5; color: #ea580c; }
.stat-card.profit .icon { background: #fef3c7; color: #b45309; }

.section-title { font-weight: 800; color: var(--primary); margin-bottom: 4px; }
.section-sub { color: var(--muted); font-size: .9rem; margin-bottom: 18px; }

.btn-primary {
  --bs-btn-bg: var(--secondary);
  --bs-btn-border-color: var(--secondary);
  --bs-btn-hover-bg: #1d4ed8;
  --bs-btn-hover-border-color: #1d4ed8;
  border-radius: 11px; font-weight: 700;
}
.btn-outline-primary {
  --bs-btn-color: var(--secondary);
  --bs-btn-border-color: var(--secondary);
  --bs-btn-hover-bg: var(--secondary);
  --bs-btn-hover-border-color: var(--secondary);
  border-radius: 11px; font-weight: 700;
}
.btn-accent {
  background: var(--accent); border-color: var(--accent); color: #111; font-weight: 700; border-radius: 11px;
}
.btn-accent:hover { background: #d97706; border-color: #d97706; color: #111; }
.btn-soft {
  background: #eef2ff; color: var(--primary); border: 0; font-weight: 700; border-radius: 11px;
}

.table-wrap { overflow: auto; }
.table thead th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: #f8fafc; border-bottom-width: 1px;
}
.table td { vertical-align: middle; }
.badge-status {
  display: inline-flex; align-items: center; padding: .35rem .65rem;
  border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase;
}
.badge-paid { background: #dcfce7; color: #166534; }
.badge-unpaid { background: #fee2e2; color: #991b1b; }
.badge-partial { background: #ffedd5; color: #9a3412; }
.badge-overdue { background: #fecaca; color: #7f1d1d; }
.badge-draft { background: #e2e8f0; color: #334155; }
.badge-cancelled { background: #f1f5f9; color: #64748b; }
.badge-quotation { background: #fef3c7; color: #92400e; }
.badge-invoice { background: #dbeafe; color: #1e40af; }

.filter-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-pills .btn {
  border-radius: 999px; font-weight: 700; font-size: .8rem; border-color: var(--border);
}
.filter-pills .btn.active {
  background: var(--primary); border-color: var(--primary); color: #fff;
}

.form-label { font-weight: 700; font-size: .85rem; color: #334155; }
.form-control, .form-select {
  border-radius: 11px; border-color: var(--border); padding: .65rem .9rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 .2rem rgba(37,99,235,.12);
}

.modal-content { border: 0; border-radius: 18px; box-shadow: var(--shadow); }
.modal-header { border-bottom-color: var(--border); }
.modal-footer { border-top-color: var(--border); }

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(800px 400px at 10% 10%, rgba(37,99,235,.18), transparent 60%),
    radial-gradient(700px 400px at 90% 90%, rgba(245,158,11,.16), transparent 55%),
    var(--bg);
}
.login-card {
  width: min(440px, 100%); background: var(--surface); border-radius: 22px;
  padding: 36px 32px; box-shadow: 0 20px 50px rgba(15,23,42,.1); border: 1px solid var(--border);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand img { width: 72px; height: 72px; object-fit: contain; margin-bottom: 12px; }
.login-brand h1 { font-size: 1.5rem; font-weight: 800; color: var(--primary); margin: 0; }
.login-brand p { color: var(--muted); margin: 6px 0 0; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state i { font-size: 2.4rem; opacity: .4; }

.item-table input { min-width: 80px; }
.item-table .desc-input { min-width: 180px; }

/* Document preview */
.doc-preview-dialog { max-width: 1100px; }
.doc-preview-shell { background: #eef3f5; }
.doc-preview-toolbar .btn.active,
.doc-preview-toolbar .btn.btn-secondary { background: #087F8C; border-color: #087F8C; color: #fff; }
.doc-preview-stage {
  background: linear-gradient(160deg, #dce8eb 0%, #eef2f6 45%, #f7f5f0 100%);
  border-radius: 16px;
  padding: 20px;
  min-height: 70vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.doc-preview-frame {
  position: relative;
  width: 100%;
  max-width: 820px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(23, 37, 84, .14);
  overflow: hidden;
  transition: max-width .25s ease, width .25s ease;
}
.doc-preview-stage[data-view="mobile"] .doc-preview-frame { max-width: 420px; }
.doc-preview-stage[data-view="print"] .doc-preview-frame { max-width: 820px; }
.doc-preview-frame iframe {
  width: 100%;
  height: min(78vh, 920px);
  border: 0;
  background: #525659;
}
.doc-preview-loading {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(255,255,255,.88);
  color: #172554; font-weight: 600;
}

/* ========== Mobile-first responsive system ========== */
:root {
  --bottom-nav-h: 64px;
  --sticky-actions-h: 72px;
  --touch-min: 44px;
}

html { -webkit-text-size-adjust: 100%; }
.app-body { overflow-x: hidden; max-width: 100vw; }
.app-content, .surface, .item-line, .table-wrap { max-width: 100%; }
.row > [class*="col"] { min-width: 0; }

.btn-icon, .sidebar-link { min-height: var(--touch-min); }
.btn:not(.btn-sm) { min-height: var(--touch-min); }
.form-control, .form-select {
  min-height: var(--touch-min);
  font-size: 16px; /* avoid iOS zoom */
}

/* Bottom navigation */
.app-bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 1030;
  justify-content: space-around;
  align-items: stretch;
}
.app-bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 700;
  text-decoration: none;
  min-height: var(--bottom-nav-h);
}
.app-bottom-nav a i { font-size: 1.25rem; }
.app-bottom-nav a.active { color: var(--secondary); }
.app-bottom-nav a:active { background: #f1f5f9; }

/* Sticky primary actions (document builder) */
.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 12px;
  margin: 16px -8px -8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  box-shadow: 0 -8px 24px rgba(15,23,42,.06);
}
.sticky-totals-bar {
  display: none;
  position: sticky;
  bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  z-index: 25;
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -6px 20px rgba(15,23,42,.18);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sticky-totals-bar .grand { font-size: 1.15rem; font-weight: 800; }
.sticky-totals-bar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sticky-totals-bar .btn { min-height: 40px; }

/* Item line cards (invoice/quotation builder) — mobile-first */
.item-lines { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.item-line {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.item-line-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.item-line-label {
  font-size: .75rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.item-line-toolbar .btn-remove {
  flex: 0 0 auto;
  min-height: 36px;
  padding: .25rem .65rem;
  white-space: nowrap;
}
.item-line-desc,
.item-line-nums > div { min-width: 0; }
.item-line .field-label {
  display: block; font-size: .72rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px;
}
.item-line-nums {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.item-line .desc-input,
.item-line input[type="number"] {
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100%;
}
.item-line-free {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 0;
  font-weight: 700;
  font-size: .9rem;
  color: #334155;
}
.item-line-free .form-check-input {
  width: 1.2rem;
  height: 1.2rem;
  margin: 0;
  flex-shrink: 0;
}
.item-line .line-total-wrap {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 8px; border-top: 1px dashed var(--border);
}
.item-lines-desktop-head { display: none; }

/* Responsive card tables */
.table-cards thead { /* desktop default */ }
@media (max-width: 767.98px) {
  .table-cards thead { display: none; }
  .table-cards,
  .table-cards tbody,
  .table-cards tr,
  .table-cards td { display: block; width: 100%; }
  .table-cards tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 12px;
    padding: 12px 14px;
    box-shadow: var(--shadow);
  }
  .table-cards tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    border: 0 !important;
    padding: 6px 0 !important;
    text-align: right !important;
  }
  .table-cards tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    text-align: left;
    flex: 0 0 42%;
  }
  .table-cards tbody td.text-end { text-align: right !important; }
  .table-cards tbody td:last-child {
    padding-top: 10px !important;
    border-top: 1px dashed var(--border) !important;
    margin-top: 4px;
  }
  .table-wrap.surface { background: transparent; border: 0; box-shadow: none; }
}

/* Mobile list cards (explicit) */
.mobile-card-list { display: none; flex-direction: column; gap: 10px; }
.mobile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.mobile-card .mc-title { font-weight: 800; color: var(--primary); }
.mobile-card .mc-meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.mobile-card .mc-row { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; align-items: center; }
.mobile-card .mc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.touch-action {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--touch-min); min-height: var(--touch-min);
  border-radius: 12px; border: 1px solid var(--border); background: #fff;
  color: var(--primary); font-weight: 700; padding: 0 12px; gap: 6px;
}
.touch-action.wa { color: #128C7E; border-color: #b2dfdb; background: #e8f5f3; }
.touch-action.call { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }

/* Charts */
.chart-box { position: relative; width: 100%; min-height: 180px; }
.chart-box canvas { max-width: 100% !important; height: auto !important; }

/* Search expand on small phones */
.global-search.collapsed-mobile .form-control { display: none; }
.global-search.collapsed-mobile { width: auto; }
.search-toggle { display: none; }

/* Page header actions stack */
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Portal mobile */
.portal-shell { padding-bottom: 24px; }
.portal-line-card {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff;
}
.portal-sticky-actions {
  position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--border);
  padding: 12px; display: flex; gap: 8px; flex-wrap: wrap; z-index: 10;
}

/* Document preview on phones: full-screen feel, PDF stays A4 inside iframe */
@media (max-width: 767.98px) {
  .doc-preview-dialog {
    margin: 0;
    max-width: 100%;
    height: 100%;
  }
  .doc-preview-dialog .modal-content {
    height: 100%;
    border-radius: 0;
  }
  .doc-preview-stage {
    padding: 8px;
    min-height: 60vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .doc-preview-stage[data-view="mobile"] .doc-preview-frame,
  .doc-preview-stage[data-view="desktop"] .doc-preview-frame {
    max-width: 100%;
  }
  .doc-preview-frame iframe {
    height: min(70vh, 820px);
    /* A4 PDF not distorted — letterbox inside dark bg */
  }
  .doc-preview-toolbar { gap: 8px !important; }
  .doc-preview-toolbar .ms-auto { margin-left: 0 !important; width: 100%; }
  .doc-preview-toolbar .ms-auto .btn { flex: 1; }
}

/* Breakpoints */
@media (max-width: 480px) {
  :root { --topbar-h: 58px; }
  .app-topbar { padding: 0 10px; gap: 8px; }
  .app-content { padding: 12px 12px calc(16px + var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
  .app-footer { display: none; }
  .page-heading { font-size: .95rem; max-width: 46vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 1.15rem; }
  .stat-card .icon { width: 34px; height: 34px; font-size: 1rem; }
  .global-search { display: none; }
  .global-search.is-open {
    display: block; position: absolute; left: 10px; right: 10px; top: calc(var(--topbar-h) + 6px);
    width: auto; z-index: 1030;
  }
  .search-toggle { display: inline-flex; }
  .notif-menu { width: min(92vw, 320px); }
  .login-card { padding: 28px 20px; }
  .filter-pills .btn { font-size: .75rem; padding: .35rem .7rem; }
}

@media (min-width: 481px) and (max-width: 767.98px) {
  .app-content { padding: 16px 16px calc(18px + var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
  .app-footer { display: none; }
  .global-search { width: min(200px, 36vw); }
}

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-105%); width: min(86vw, 300px); }
  .app-sidebar.open { transform: translateX(0); }
  .app-main, .app-main.expanded { margin-left: 0; }
  .app-bottom-nav { display: flex; }
  .app-content { padding-bottom: calc(20px + var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
  .sticky-totals-bar { display: flex; }
  .builder-actions-desktop { display: none !important; }
  .item-table { display: none !important; }
  #itemsTableWrap { border: 0; background: transparent; box-shadow: none; }
  .section-title { font-size: 1.25rem; }
  .surface { border-radius: 12px; }
  .modal-dialog { margin: .5rem; }
  .modal-dialog-scrollable .modal-content { max-height: calc(100vh - 1rem); }
}

@media (max-width: 380px) {
  .item-line-nums { grid-template-columns: 1fr 1fr; }
  .item-line-nums > div:last-child { grid-column: 1 / -1; }
}

@media (min-width: 992px) {
  .app-bottom-nav { display: none !important; }
  .sticky-totals-bar { display: none !important; }
  .builder-actions-desktop { display: flex !important; }
  .item-lines {
    padding: 0;
    gap: 0;
  }
  .item-line {
    display: grid;
    grid-template-columns: minmax(0, 2.4fr) minmax(0, 3.2fr) auto;
    grid-template-areas:
      "toolbar toolbar toolbar"
      "desc nums free"
      "total total total";
    align-items: end;
    gap: 10px 12px;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 12px;
  }
  .item-line-toolbar { grid-area: toolbar; }
  .item-line-desc { grid-area: desc; }
  .item-line-nums { grid-area: nums; }
  .item-line-free { grid-area: free; align-self: center; }
  .item-line .line-total-wrap { grid-area: total; }
  .mobile-card-list { display: none !important; }
  .desktop-table-only { display: block; }
}

@media (min-width: 1441px) {
  .app-content { max-width: 1400px; }
  .stat-card .value { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  .stat-card:hover { transform: none; }
}

/* Loading indicator */
.snap-loading {
  display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600;
}
.snap-loading::before {
  content: ""; width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--secondary); border-radius: 50%;
  animation: snap-spin .7s linear infinite;
}
@keyframes snap-spin { to { transform: rotate(360deg); } }
