:root {
  color-scheme: light;
  --bg: #f8f9fb;
  --bg-soft: #ffffff;
  --ink: #18181b;
  --muted: #667085;
  --muted-2: #98a2b3;
  --line: #eaecf0;
  --line-strong: #d0d5dd;
  --panel: #ffffff;
  --primary: #860000;
  --primary-2: #a81212;
  --primary-dark: #690000;
  --primary-soft: #fff5f5;
  --gold: #b89145;
  --gold-soft: #fffbf0;
  --danger: #b91c1c;
  --success: #13795b;
  --shadow: 0 18px 55px rgba(16, 24, 40, 0.10);
  --shadow-soft: 0 10px 28px rgba(16, 24, 40, 0.07);
  --radius: 8px;
  font-family: "Aptos", "Segoe UI", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 4%, rgba(134, 0, 0, 0.07), transparent 28rem),
    linear-gradient(135deg, #fff 0%, var(--bg) 52%, #f4f6f8 100%);
  color: var(--ink);
  display: grid;
  grid-template-columns: 282px 1fr;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(134, 0, 0, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(134, 0, 0, 0.018) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 100vh;
  padding: 22px 18px;
  overflow-y: auto;
  color: var(--ink);
  background:
    linear-gradient(180deg, #ffffff 0%, #f7f8fa 52%, #f2f4f7 100%);
  border-right: 1px solid var(--line);
  box-shadow: 14px 0 34px rgba(16, 24, 40, 0.07);
  display: flex;
  flex-direction: column;
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(134, 0, 0, 0.035), transparent 35%),
    radial-gradient(circle at 100% 0%, rgba(134, 0, 0, 0.06), transparent 18rem);
}

.brand {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: linear-gradient(135deg, #ffffff 0%, #fffafa 54%, #ffe9e9 100%);
  color: var(--primary-dark);
  font-weight: 900;
  border-radius: var(--radius);
  box-shadow: 0 10px 22px rgba(16, 24, 40, 0.10), inset 0 0 0 1px rgba(134, 0, 0, 0.09);
}

.brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: 0;
}

.brand small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
  font-size: 12px;
}

nav {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  align-content: start;
}

.nav-section,
.nav-subsection {
  display: grid;
  gap: 6px;
}

.nav-section-toggle {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: #667085;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  border-radius: var(--radius);
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.nav-section-toggle:hover {
  background: #f2f4f7;
  color: var(--primary-dark);
}

.nav-section-toggle.sub {
  margin-left: 8px;
  padding-left: 12px;
  color: #667085;
}

.nav-section-toggle span { line-height: 1; }
.nav-chevron { transition: transform 180ms ease; }

.nav-section-items {
  display: grid;
  gap: 6px;
  overflow: hidden;
  animation: reveal 180ms ease both;
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.nav-subsection { margin-top: 4px; }
.nav-subsection .nav-item { margin-left: 18px; }
.nav-subsection-nested { margin-left: 12px; }
.nav-subsection-nested .nav-item { margin-left: 28px; }

.nav-section.collapsed > .nav-section-items,
.nav-subsection.collapsed > .nav-section-items {
  display: none;
}

.nav-section.collapsed > .nav-section-toggle .nav-chevron,
.nav-subsection.collapsed > .nav-section-toggle .nav-chevron {
  transform: rotate(-90deg);
}

.nav-section > span {
  color: #667085;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
  padding: 0 12px;
}

.nav-item {
  position: relative;
  min-height: 42px;
  border: 1px solid transparent;
  background: transparent;
  color: #344054;
  text-align: left;
  padding: 11px 13px 11px 42px;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.nav-item::before {
  content: "•";
  position: absolute;
  left: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  color: #98a2b3;
  transform: translateY(-50%);
  font-size: 20px;
  line-height: 1;
}

.nav-item[data-view="dashboard"]::before { content: "⌂"; font-size: 15px; }
.nav-item[data-view="invoice"]::before { content: "+"; font-size: 18px; }
.nav-item[data-view="query-invoice"]::before { content: "?"; font-size: 14px; }
.nav-item[data-view="products"]::before { content: "#"; font-size: 14px; }
.nav-item[data-view="customers"]::before { content: "@"; font-size: 14px; }
.nav-item[data-view="warehouses"]::before { content: "□"; font-size: 15px; }
.nav-item[data-view="reports"]::before { content: "▥"; font-size: 14px; }
.nav-item[data-view="ai-assistant"]::before { content: "*"; font-size: 18px; }

.nav-item.active,
.nav-item:hover {
  background: #f2f4f7;
  border-color: #eaecf0;
  color: var(--primary-dark);
  transform: translateX(2px);
}

.nav-item.active {
  background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
  color: var(--primary-dark);
  border-color: rgba(134, 0, 0, 0.14);
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
}

.app {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  padding: 18px 20px;
  background: rgba(255,255,255,0.82);
  border: 1px solid rgba(216, 198, 192, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
}

h1, h2, h3, h4, p { margin-top: 0; }
h1 {
  margin-bottom: 4px;
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.05;
  color: var(--primary-dark);
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  margin-bottom: 14px;
  color: var(--ink);
  letter-spacing: 0;
}

h3, h4 { color: var(--ink); letter-spacing: 0; }
.topbar p, .hint { color: var(--muted); margin-bottom: 0; line-height: 1.45; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.topbar-clock {
  display: grid;
  gap: 1px;
  min-height: 40px;
  align-content: center;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 5px 16px rgba(16, 24, 40, 0.05);
}

.topbar-clock small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
  text-transform: capitalize;
}

.topbar-clock strong {
  color: var(--primary-dark);
  font-size: 14px;
  line-height: 1.1;
  letter-spacing: 0;
}

.pill {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 750;
  color: var(--muted);
  box-shadow: 0 5px 16px rgba(16, 24, 40, 0.05);
}

.pill.ok {
  color: var(--success);
  border-color: rgba(19, 121, 91, 0.25);
  background: #f0fbf7;
}

.pill.error {
  color: var(--danger);
  border-color: #f3c1c1;
  background: #fff4f4;
}

.view { display: none; }
.view.active {
  display: block;
  margin-bottom: 18px;
  animation: pageIn 220ms ease both;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.view.active::before { content: attr(id); display: none; }
.hidden { display: none; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 18% 16%, rgba(134, 0, 0, 0.12), transparent 24rem),
    linear-gradient(135deg, #ffffff 0%, #f8f9fb 48%, #fff4f4 100%);
}

.login-screen::before {
  content: "";
  position: absolute;
  inset: 12% 8% auto auto;
  width: min(34vw, 360px);
  aspect-ratio: 1;
  border: 1px solid rgba(134, 0, 0, 0.10);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(134, 0, 0, 0.08), transparent 62%);
}

.login-screen.hidden { display: none; }

.login-shell {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  gap: 22px;
  align-items: stretch;
}

.login-copy {
  display: grid;
  align-content: center;
  gap: 14px;
  min-height: 440px;
  padding: 34px;
  border: 1px solid rgba(234, 236, 240, 0.92);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.84), rgba(255, 245, 245, 0.66)),
    radial-gradient(circle at 18% 18%, rgba(134, 0, 0, 0.08), transparent 16rem);
  box-shadow: 0 20px 60px rgba(16, 24, 40, 0.10);
  backdrop-filter: blur(14px);
}

.login-kicker {
  width: fit-content;
  color: var(--primary-dark);
  background: #fff5f5;
  border: 1px solid rgba(134, 0, 0, 0.12);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 850;
}

.login-copy h2 {
  max-width: 520px;
  margin: 0;
  color: #2b2f38;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
}

.login-copy p {
  max-width: 460px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.login-trust {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.login-trust span {
  color: #344054;
  background: #fff;
  border: 1px solid #eaecf0;
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 750;
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.05);
}

.login-panel {
  position: relative;
  width: 100%;
  display: grid;
  gap: 15px;
  align-content: center;
  padding: 30px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(234, 236, 240, 0.95);
  border-radius: var(--radius);
  box-shadow: 0 28px 80px rgba(16, 24, 40, 0.16);
  backdrop-filter: blur(18px);
}

.login-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  border-top: 4px solid var(--gold);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 12px;
}

.login-brand small { color: var(--muted); }
.login-panel label { margin-bottom: 0; }
.login-panel input { width: 100%; margin-top: 6px; }

.login-panel .primary {
  min-height: 46px;
  margin-top: 4px;
}

.login-panel .hint.error {
  color: #b42318;
  background: #fff1f0;
  border: 1px solid #fecdca;
  border-radius: var(--radius);
  padding: 10px 11px;
}

.app-loading {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(247, 245, 243, 0.78);
  backdrop-filter: blur(7px);
}

.app-loading.hidden { display: none; }

.app-loading-panel {
  width: min(380px, 100%);
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.app-loading-panel strong { font-size: 17px; color: var(--primary-dark); }
.app-loading-panel small { color: var(--muted); }
.app-loading-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid #ead9d9;
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

.app.is-loading,
.sidebar.is-loading {
  pointer-events: none;
  user-select: none;
}

.workspace-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: -4px 0 18px;
}

.workspace-tab {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  padding: 8px 11px;
  box-shadow: 0 5px 18px rgba(16, 24, 40, 0.05);
}

.workspace-tab.active {
  color: var(--primary-dark);
  border-color: rgba(134, 0, 0, 0.25);
  background: var(--primary-soft);
}

.tab-close {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 850;
}

.tab-close:hover { background: #f2f4f7; color: var(--ink); }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr); align-items: start; }

.invoice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.invoice-context {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(150px, 0.75fr) minmax(150px, 0.75fr) minmax(190px, 0.8fr);
  gap: 12px;
  align-items: end;
}

.invoice-context label { margin-bottom: 0; }

.next-consecutive {
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #fff 0%, var(--gold-soft) 100%);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 2px;
  box-shadow: inset 4px 0 0 var(--gold);
}

.next-consecutive small { color: var(--muted); font-size: 12px; }
.next-consecutive strong { color: var(--primary-dark); font-size: 19px; line-height: 1.1; }
.next-consecutive span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

.invoice-main { display: grid; gap: 14px; }

.panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(216, 198, 192, 0.9);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.compact-panel { padding: 16px; }

.placeholder-panel {
  min-height: 180px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.compact-grid { display: grid; gap: 11px; }
.compact-grid.hidden { display: none; }
.compact-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.compact-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.compact-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.subpanel {
  border: 1px solid var(--line);
  background: rgba(251, 250, 248, 0.92);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.subpanel h2 { font-size: 16px; margin-bottom: 12px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.sticky {
  position: sticky;
  top: 20px;
  border-top: 4px solid var(--primary);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.dashboard-filters { margin-bottom: 14px; }
.dashboard-filters label { margin-bottom: 0; }

.metrics article {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #fff 0%, #fff8f6 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

.metrics article::after {
  content: "";
  position: absolute;
  inset: auto 14px 0 auto;
  width: 58px;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  border-radius: 999px 999px 0 0;
}

.metrics small { color: var(--muted); display: block; font-weight: 750; }
.metrics strong { font-size: 24px; margin-top: 8px; display: block; color: var(--primary-dark); }

.ai-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 18px;
  align-items: start;
}

.ai-panel {
  min-height: 560px;
  display: grid;
  grid-template-rows: auto auto auto minmax(280px, 1fr) auto;
  gap: 12px;
}

.ai-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) 150px 150px 150px;
  gap: 10px;
  align-items: end;
  justify-content: start;
}

.ai-filters label { margin-bottom: 0; }
.ai-filters select,
.ai-filters input { min-height: 40px; padding: 9px 11px; }

.ai-scope-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.ai-scope-row label { margin-bottom: 0; color: var(--ink); font-weight: 750; }
.ai-scope-row .hint { font-size: 12px; }

.ai-messages {
  min-height: 300px;
  max-height: 52vh;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--bg-soft), #fff);
}

.ai-message {
  max-width: min(760px, 92%);
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 8px 22px rgba(16, 24, 40, 0.05);
}

.ai-message.user {
  justify-self: end;
  background: var(--primary-soft);
  border-color: rgba(134, 0, 0, 0.2);
}

.ai-message strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--primary-dark);
}

.ai-message p { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }

.ai-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.ai-chat-form textarea { min-height: 58px; margin: 0; }
.ai-suggestions { display: grid; gap: 10px; }
.ai-suggestions button { text-align: left; min-height: 44px; }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 9px 11px;
  font: inherit;
  color: var(--ink);
  background: linear-gradient(180deg, #fff, #fffdfc);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea { min-height: 86px; resize: vertical; }
.compact-panel textarea { min-height: 64px; }

input:hover,
select:hover,
textarea:hover {
  border-color: rgba(134, 0, 0, 0.35);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(134, 0, 0, 0.11);
  background: #fff;
}

button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, #fff, #fbf7f5);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(16, 24, 40, 0.05);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(134, 0, 0, 0.3);
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.10);
}

.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 12px 26px rgba(134, 0, 0, 0.22);
}

.primary:hover {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  border-color: var(--primary-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
  transform: none;
}

.wide { width: 100%; }

.submit-with-spinner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 999px;
  display: none;
  animation: spin 0.75s linear infinite;
}

.is-loading .button-spinner { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

.check {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
}

.check input {
  width: 17px;
  min-height: 17px;
  accent-color: var(--primary);
}

.line-editor {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(160px, 1.1fr) minmax(130px, 0.9fr) 80px 90px minmax(130px, 0.9fr) 90px 90px auto;
  gap: 10px;
  align-items: end;
}

.line-editor label { margin-bottom: 0; }
.lines { display: grid; gap: 8px; margin-top: 12px; }

.line {
  display: grid;
  grid-template-columns: 1fr 110px auto auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(16, 24, 40, 0.05);
}

.line small,
.list small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

.line-price { margin: 0; font-size: 11px; color: var(--muted); }
.line-price input { margin-top: 2px; }
.line button { color: var(--danger); }

.totals {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  margin-bottom: 18px;
}

.global-discount {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px 84px;
  gap: 8px;
  margin-bottom: 10px;
}

.global-discount.hidden { display: none; }
.global-discount label { margin-bottom: 0; }
.totals strong:last-child { color: var(--primary-dark); font-size: 23px; }

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
}

th {
  color: var(--primary-dark);
  font-size: 12px;
  text-transform: uppercase;
  background: #fff8f7;
  font-weight: 850;
}

tbody tr {
  transition: background 140ms ease;
}

tbody tr:hover {
  background: #fff7f4;
}

td small {
  color: var(--muted);
  display: block;
  margin-top: 4px;
  max-width: 260px;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.actions button,
.actions a {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.actions a {
  color: var(--primary-dark);
  font-weight: 800;
  text-decoration: none;
}

.inline-help {
  width: 22px;
  min-height: 22px;
  margin-left: 4px;
  padding: 0;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
}

.query-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.query-bar label { margin-bottom: 0; }
.query-result { margin-top: 14px; }

.query-header {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.query-header div,
.query-totals span {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 10px;
  min-width: 0;
}

.query-header small {
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.query-header strong {
  display: block;
  overflow-wrap: anywhere;
}

.query-totals {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.query-totals strong { display: block; margin-top: 4px; }

.list {
  display: grid;
  gap: 8px;
}

.list.compact { gap: 8px; margin-bottom: 12px; }
.company-picker { margin-bottom: 14px; }

.company-selector {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.company-selector label { margin-bottom: 0; }

.compact-panel .list {
  max-height: calc(100vh - 230px);
  overflow: auto;
  padding-right: 2px;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.list-item:hover {
  border-color: rgba(134, 0, 0, 0.25);
  transform: translateY(-1px);
}

.list-item.selected {
  border-color: rgba(134, 0, 0, 0.35);
  background: var(--primary-soft);
}

.activity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.maintenance-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.inline-form {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 0;
}

.activity-manager {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 12px;
  background: var(--bg-soft);
}

.activity-manager .list.compact { max-height: 132px; }

.status-box {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 10px;
  margin: 8px 0 12px;
  display: grid;
  gap: 4px;
}

.status-box span { color: var(--primary-dark); font-weight: 800; }
.status-box small { color: var(--muted); }

.section-title {
  margin: 16px 0 8px;
  color: var(--primary-dark);
  font-size: 15px;
}

.provider-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.provider-section-head h3 {
  margin: 0 0 3px;
  color: var(--primary-dark);
  font-size: 15px;
}

.provider-section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.provider-certificate-box {
  display: grid;
  gap: 10px;
  margin: 10px 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf9;
}

.provider-certificate-box button {
  width: fit-content;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: linear-gradient(135deg, #260303, var(--primary-dark));
  color: white;
  padding: 13px 15px;
  border-radius: var(--radius);
  opacity: 0;
  transform: translateY(10px);
  transition: 0.2s ease;
  max-width: 360px;
  box-shadow: 0 18px 45px rgba(70, 0, 0, 0.28);
  z-index: 30;
}

.toast.show { opacity: 1; transform: translateY(0); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 20, 20, 0.42);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
  backdrop-filter: blur(5px);
}

.modal-backdrop.hidden { display: none; }

.modal {
  width: min(440px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 28px 80px rgba(60, 0, 0, 0.32);
}

.modal h2 { margin-bottom: 8px; color: var(--primary-dark); }
.modal p { color: var(--muted); line-height: 1.45; }

.modal-kicker {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 10px;
  padding: 5px 8px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.provider-modal {
  display: grid;
  gap: 12px;
}

.provider-modal label {
  margin-top: 4px;
}

.provider-modal small {
  color: var(--muted);
}

#provider-unlock-hint.error {
  color: var(--danger);
  font-weight: 750;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.danger-button {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.report-card {
  --report-accent: var(--primary);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 250px;
  background: linear-gradient(145deg, #fff 0%, #fffafa 100%);
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.report-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--gold));
}

.report-card::after {
  content: "▥";
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 900;
}

.report-card:hover {
  transform: translateY(-2px);
  border-color: rgba(134, 0, 0, 0.25);
  box-shadow: var(--shadow);
}

.report-card h4 {
  margin: 0 42px 8px 0;
  color: var(--primary-dark);
  font-size: 15px;
  line-height: 1.25;
  font-weight: 850;
}

.report-card p {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 16px 0;
  line-height: 1.45;
  min-height: 34px;
}

.report-card input,
.report-card select {
  margin-bottom: 10px;
}

.report-card button {
  width: 100%;
  margin-top: auto;
}

.reports-results {
  background: rgba(255, 255, 255, 0.92);
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  margin-top: 20px;
}

.reports-results pre {
  background: #1b1111;
  color: #fff7ef;
  padding: 15px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 11px;
  line-height: 1.45;
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid #3b2020;
  margin: 0;
}

.report-loading {
  display: none;
  text-align: center;
  color: var(--primary-dark);
  padding: 20px;
}

.report-error {
  background: #fff1f1;
  color: #7f1d1d;
  padding: 12px;
  border-radius: var(--radius);
  margin-top: 10px;
  border: 1px solid #f4caca;
}

.report-success {
  background: #f0fbf7;
  color: #0f684d;
  padding: 12px;
  border-radius: var(--radius);
  margin-top: 10px;
  border: 1px solid #bae7d5;
}

@media (max-width: 1100px) {
  body { grid-template-columns: 246px 1fr; }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .line-editor { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  body::before { opacity: 0.55; }
  .sidebar {
    position: relative;
    min-height: auto;
    padding: 14px;
  }
  .brand { margin-bottom: 14px; }
  nav {
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    overflow-x: auto;
    align-items: start;
    padding-bottom: 4px;
  }
  .app { padding: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .grid.two,
  .metrics,
  .line-editor,
  .inline-form,
  .invoice-layout,
  .invoice-context,
  .ai-layout,
  .ai-filters,
  .ai-chat-form,
  .query-bar,
  .query-header,
  .query-totals,
  .company-selector,
  .compact-grid.two,
  .compact-grid.three,
  .compact-grid.four,
  .global-discount {
    grid-template-columns: 1fr;
  }
  .sticky { position: static; }
  .login-shell {
    grid-template-columns: 1fr;
    max-width: 480px;
  }
  .login-copy {
    min-height: auto;
    padding: 22px;
  }
  .login-copy h2 {
    font-size: 28px;
  }
}

@media (max-width: 560px) {
  .app { padding: 12px; }
  .topbar,
  .panel,
  .login-panel {
    padding: 16px;
  }
  .login-copy {
    display: none;
  }
  nav { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .topbar-actions { justify-content: flex-start; }
  .metrics article { padding: 15px; }
  .line { grid-template-columns: 1fr; }
  .actions { align-items: stretch; }
  .actions button,
  .actions a {
    width: 100%;
    text-align: center;
  }
}
