/* =====================================================================
   CLO AI — house style (ports the AI Factory CRM dark-glass system into
   framework-free CSS). Self-contained, no CDN, no build step.
   ===================================================================== */

:root {
  /* --- AI Factory dark palette (HSL triplets, used via hsl()) --- */
  --background: 0 0% 7%;
  --foreground: 30 5% 96%;
  --card: 0 0% 10%;
  --muted: 0 0% 15%;
  --muted-foreground: 0 0% 58%;
  --primary: 6 63% 46%; /* #bf4829 */
  --primary-fg: 0 0% 100%;
  --border: 0 0% 16%;

  --status-pending: 46 85% 50%;
  --status-success: 156 54% 42%;
  --status-danger: 0 68% 52%;
  --status-info: 210 62% 52%;
  --status-neutral: 0 0% 52%;

  --glass-border: 0 0% 100% / 0.08;
  --glass-shadow:
    0 4px 24px -2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.2);
  --glass-shadow-lg:
    0 12px 40px -4px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.2);
  --glass-glow: 0 0 0 1px rgba(255, 255, 255, 0.04);

  --radius: 0.75rem;

  /* spacing scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 64px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sidebar-w: 248px;

  --font:
    "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: var(--font);
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.55;
}
h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: hsl(var(--foreground));
}
a {
  color: hsl(var(--primary) / 0.92);
  text-decoration: none;
}
a:hover {
  color: hsl(var(--primary));
}
button {
  font-family: inherit;
  cursor: pointer;
}
:focus-visible {
  outline: 2px solid hsl(var(--primary) / 0.4);
  outline-offset: 2px;
  border-radius: inherit;
}

/* --- mesh background --- */
.mesh-gradient {
  background:
    radial-gradient(
      ellipse at 12% 82%,
      hsla(6, 63%, 46%, 0.09) 0%,
      transparent 48%
    ),
    radial-gradient(
      ellipse at 88% 18%,
      hsla(6, 50%, 40%, 0.06) 0%,
      transparent 48%
    ),
    radial-gradient(
      ellipse at 50% 50%,
      hsla(0, 0%, 15%, 0.3) 0%,
      transparent 55%
    ),
    radial-gradient(
      ellipse at 78% 78%,
      hsla(6, 63%, 46%, 0.04) 0%,
      transparent 38%
    ),
    hsl(0, 0%, 7%);
  min-height: 100vh;
}

/* ===================== GLASS SYSTEM ===================== */
.glass {
  background: hsla(0, 0%, 12%, 0.62);
  backdrop-filter: blur(24px) saturate(1.25);
  -webkit-backdrop-filter: blur(24px) saturate(1.25);
  border: 1px solid hsla(var(--glass-border));
  box-shadow: var(--glass-shadow), var(--glass-glow);
}
.glass-strong {
  background: hsla(0, 0%, 11%, 0.84);
  backdrop-filter: blur(32px) saturate(1.35);
  -webkit-backdrop-filter: blur(32px) saturate(1.35);
  border: 1px solid hsla(0, 0%, 100%, 0.12);
  box-shadow: var(--glass-shadow-lg), var(--glass-glow);
}
.glass-sidebar {
  background: hsla(0, 0%, 8%, 0.9);
  backdrop-filter: blur(36px) saturate(1.45);
  -webkit-backdrop-filter: blur(36px) saturate(1.45);
  border-right: 1px solid hsla(0, 0%, 100%, 0.06);
}
.glass-header {
  background: hsla(0, 0%, 10%, 0.78);
  backdrop-filter: blur(24px) saturate(1.25);
  -webkit-backdrop-filter: blur(24px) saturate(1.25);
  border-bottom: 1px solid hsla(0, 0%, 100%, 0.06);
}
.glass-inset {
  background: hsla(0, 0%, 12%, 0.5);
  border: 1px solid hsla(0, 0%, 100%, 0.05);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* ===================== BRAND ===================== */
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 11px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: hsl(var(--primary-fg));
  background: linear-gradient(135deg, hsl(6, 63%, 50%), hsl(6, 63%, 38%));
  box-shadow:
    0 4px 14px hsl(var(--primary) / 0.35),
    inset 0 1px 0 hsla(0, 0%, 100%, 0.18);
}
.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-sub {
  font-size: 11.5px;
  color: hsl(var(--muted-foreground));
  letter-spacing: 0.01em;
}

/* ===================== APP SHELL LAYOUT ===================== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: var(--s5) var(--s4);
  z-index: 40;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 0 var(--s2) var(--s5);
}
.brand-text {
  min-width: 0;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 10px var(--s3);
  border-radius: 10px;
  color: hsl(var(--muted-foreground));
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  transition:
    background 0.18s var(--ease),
    color 0.18s var(--ease);
}
.nav-item:hover {
  background: hsla(0, 0%, 100%, 0.045);
  color: hsl(var(--foreground));
}
.nav-item.active {
  background: hsl(var(--primary) / 0.14);
  color: hsl(var(--foreground));
  box-shadow: inset 2px 0 0 hsl(var(--primary));
}
.nav-item .ico {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  opacity: 0.9;
}
.nav-item.active .ico {
  color: hsl(var(--primary));
  opacity: 1;
}

.sidebar-foot {
  padding-top: var(--s4);
  border-top: 1px solid hsla(0, 0%, 100%, 0.06);
}
.brain-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 100px;
  background: hsla(0, 0%, 100%, 0.05);
  color: hsl(var(--muted-foreground));
  width: 100%;
}
.brain-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: hsl(var(--status-neutral));
  flex: 0 0 8px;
}
.brain-pill.live .dot {
  background: hsl(var(--status-success));
  box-shadow: 0 0 8px hsl(var(--status-success) / 0.7);
}
.brain-pill.stub .dot {
  background: hsl(var(--status-pending));
}
.brain-pill.error .dot {
  background: hsl(var(--status-danger));
}
.sidebar-meta {
  font-size: 10.5px;
  color: hsl(var(--muted-foreground) / 0.7);
  margin-top: var(--s2);
  padding-left: 2px;
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s4) var(--s6);
}
.topbar-title {
  flex: 1;
  min-width: 0;
}
.topbar-title h1 {
  font-size: 20px;
}
.page-sub {
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  margin-top: 2px;
}
.hamburger {
  display: none;
  padding: 8px;
}

.view {
  padding: var(--s6);
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  animation: fade-in 0.35s var(--ease);
}
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.bottombar {
  display: none;
}
.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

/* ===================== CARDS / GRID ===================== */
.card {
  background: hsla(0, 0%, 12%, 0.62);
  backdrop-filter: blur(24px) saturate(1.25);
  -webkit-backdrop-filter: blur(24px) saturate(1.25);
  border: 1px solid hsla(var(--glass-border));
  box-shadow: var(--glass-shadow), var(--glass-glow);
  border-radius: calc(var(--radius) + 4px);
  padding: var(--s5);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s4);
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
}
.card-eyebrow {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: hsl(var(--primary));
  font-weight: 700;
}

.grid {
  display: grid;
  gap: var(--s5);
}
.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}
.span-2 {
  grid-column: span 2;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s5);
}
.section-gap {
  margin-top: var(--s6);
}

/* stat tile */
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}
.stat-label {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.stat-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: hsl(var(--foreground));
}
.stat-value.sm {
  font-size: 22px;
}
.stat-foot {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}

/* ===================== BUTTONS / INPUTS ===================== */
.btn-primary {
  padding: 10px 18px;
  border-radius: 12px;
  border: 0;
  font-size: 14px;
  font-weight: 600;
  background: hsl(var(--primary));
  color: hsl(var(--primary-fg));
  box-shadow:
    0 2px 8px hsl(var(--primary) / 0.25),
    0 1px 2px rgba(0, 0, 0, 0.15);
  transition:
    transform 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px hsl(var(--primary) / 0.38);
}
.btn-primary:active {
  transform: none;
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-glass {
  padding: 9px 16px;
  border-radius: 12px;
  background: hsla(0, 0%, 15%, 0.5);
  border: 1px solid hsla(0, 0%, 100%, 0.08);
  color: hsl(var(--foreground));
  font-size: 14px;
  font-weight: 500;
  transition:
    background 0.18s var(--ease),
    border-color 0.18s var(--ease);
}
.btn-glass:hover {
  background: hsla(0, 0%, 18%, 0.66);
  border-color: hsla(0, 0%, 100%, 0.13);
}
.btn-ghost {
  padding: 8px 12px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: hsl(var(--muted-foreground));
  font-size: 14px;
  font-weight: 500;
  transition:
    background 0.18s,
    color 0.18s;
}
.btn-ghost:hover {
  background: hsla(0, 0%, 100%, 0.05);
  color: hsl(var(--foreground));
}
.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}
.btn-row {
  display: flex;
  gap: var(--s3);
  flex-wrap: wrap;
  align-items: center;
}

.glass-input,
textarea.glass-input,
select.glass-input {
  width: 100%;
  border-radius: 12px;
  padding: 11px 14px;
  min-height: 44px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  background: hsla(0, 0%, 15%, 0.6);
  color: hsl(var(--foreground));
  border: 1px solid hsla(0, 0%, 100%, 0.08);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
  transition:
    background 0.18s,
    border-color 0.18s;
}
textarea.glass-input {
  resize: vertical;
  min-height: 120px;
}
.glass-input::placeholder {
  color: hsl(var(--muted-foreground) / 0.55);
}
.glass-input:hover {
  background: hsla(0, 0%, 18%, 0.7);
}
.glass-input:focus {
  outline: none;
  border-color: hsl(var(--primary) / 0.4);
  background: hsla(0, 0%, 18%, 0.82);
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.16);
}
select.glass-input {
  color-scheme: dark;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  margin: 0 0 6px 2px;
}
.field {
  margin-bottom: var(--s4);
}

/* ===================== STATUS CHIPS / BADGES ===================== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  background: hsla(0, 0%, 100%, 0.07);
  color: hsl(var(--muted-foreground));
  border: 1px solid hsla(0, 0%, 100%, 0.06);
}
.chip.pending {
  background: hsl(var(--status-pending) / 0.16);
  color: hsl(46 90% 66%);
  border-color: hsl(var(--status-pending) / 0.3);
}
.chip.success {
  background: hsl(var(--status-success) / 0.16);
  color: hsl(156 54% 60%);
  border-color: hsl(var(--status-success) / 0.3);
}
.chip.danger {
  background: hsl(var(--status-danger) / 0.16);
  color: hsl(0 80% 70%);
  border-color: hsl(var(--status-danger) / 0.3);
}
.chip.info {
  background: hsl(var(--status-info) / 0.16);
  color: hsl(210 70% 68%);
  border-color: hsl(var(--status-info) / 0.3);
}
.chip.primary {
  background: hsl(var(--primary) / 0.16);
  color: hsl(6 70% 66%);
  border-color: hsl(var(--primary) / 0.3);
}

.engine-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 100px;
  background: hsla(0, 0%, 100%, 0.06);
  color: hsl(var(--muted-foreground));
  border: 1px solid hsla(0, 0%, 100%, 0.08);
}
.engine-badge.stub {
  color: hsl(46 90% 66%);
  border-color: hsl(var(--status-pending) / 0.3);
}
.engine-badge.claude {
  color: hsl(156 54% 60%);
  border-color: hsl(var(--status-success) / 0.3);
}
.engine-badge.error {
  color: hsl(0 80% 70%);
  border-color: hsl(var(--status-danger) / 0.3);
}

/* source-quality flags (Library) */
.flag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 7px;
}
.flag.primary {
  background: hsl(var(--status-success) / 0.15);
  color: hsl(156 54% 62%);
}
.flag.mirror {
  background: hsl(var(--status-pending) / 0.15);
  color: hsl(46 90% 66%);
}
.flag.secondary {
  background: hsl(var(--status-pending) / 0.15);
  color: hsl(38 90% 64%);
}
.flag.mixed {
  background: hsl(var(--status-info) / 0.15);
  color: hsl(210 70% 68%);
}
.flag.unknown {
  background: hsla(0, 0%, 100%, 0.06);
  color: hsl(var(--muted-foreground));
}

.confirm-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: var(--s4);
  background: hsl(var(--status-pending) / 0.1);
  border: 1px solid hsl(var(--status-pending) / 0.28);
  font-size: 13px;
  color: hsl(46 80% 76%);
}
.confirm-banner .ico {
  flex: 0 0 18px;
  margin-top: 1px;
}

/* ===================== LISTS / ROWS ===================== */
.row-list {
  display: flex;
  flex-direction: column;
}
.row {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: 14px 4px;
  border-bottom: 1px solid hsla(0, 0%, 100%, 0.06);
  transition: background 0.15s;
}
.row:last-child {
  border-bottom: 0;
}
.row:hover {
  background: hsla(0, 0%, 100%, 0.03);
}
.row.clickable {
  cursor: pointer;
  border-radius: 10px;
  padding-left: 12px;
  padding-right: 12px;
}
.row-main {
  flex: 1;
  min-width: 0;
}
.row-title {
  font-weight: 600;
  font-size: 14.5px;
}
.row-sub {
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  margin-top: 2px;
}
.row-aside {
  text-align: right;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.due-pill {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 13px;
}
.due-pill.soon {
  color: hsl(0 80% 70%);
}
.due-pill.warn {
  color: hsl(46 90% 66%);
}
.due-pill.ok {
  color: hsl(156 54% 60%);
}

/* deadline ring marker */
.radar-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 11px 0;
  border-bottom: 1px solid hsla(0, 0%, 100%, 0.06);
}
.radar-row:last-child {
  border-bottom: 0;
}
.radar-mark {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
}

/* ===================== CHAT ===================== */
.chat-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 168px);
  min-height: 420px;
}
.chat-controls {
  display: flex;
  gap: var(--s3);
  align-items: center;
  margin-bottom: var(--s4);
  flex-wrap: wrap;
}
.chat-controls select {
  max-width: 240px;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  padding: var(--s2) var(--s1) var(--s4);
}
.msg {
  max-width: 86%;
  padding: 14px 16px;
  border-radius: 16px;
  font-size: 14.5px;
}
.msg.user {
  align-self: flex-end;
  background: hsl(var(--primary) / 0.18);
  border: 1px solid hsl(var(--primary) / 0.28);
  border-bottom-right-radius: 5px;
}
.msg.assistant {
  align-self: flex-start;
  background: hsla(0, 0%, 15%, 0.55);
  border: 1px solid hsla(0, 0%, 100%, 0.07);
  border-bottom-left-radius: 5px;
}
.msg-role {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  opacity: 0.6;
  margin-bottom: 6px;
}
.chat-input-bar {
  display: flex;
  gap: var(--s3);
  align-items: flex-end;
  padding-top: var(--s4);
  border-top: 1px solid hsla(0, 0%, 100%, 0.06);
}
.chat-input-bar textarea {
  min-height: 48px;
  max-height: 160px;
}
.typing {
  display: inline-flex;
  gap: 4px;
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: hsl(var(--muted-foreground));
  animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

/* ===================== MARKDOWN RENDER ===================== */
.md {
  font-size: 14.5px;
  line-height: 1.62;
  word-wrap: break-word;
}
.md > :first-child {
  margin-top: 0;
}
.md > :last-child {
  margin-bottom: 0;
}
.md h1 {
  font-size: 20px;
  margin: 22px 0 10px;
  color: hsl(var(--foreground));
}
.md h2 {
  font-size: 17px;
  margin: 20px 0 9px;
  color: hsl(var(--foreground));
}
.md h3 {
  font-size: 15px;
  margin: 16px 0 7px;
  color: hsl(var(--foreground));
}
.md p {
  margin: 9px 0;
}
.md strong {
  font-weight: 700;
  color: hsl(var(--foreground));
}
.md em {
  font-style: italic;
}
.md ul,
.md ol {
  margin: 9px 0;
  padding-left: 22px;
}
.md li {
  margin: 4px 0;
}
.md a {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.md code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: hsla(0, 0%, 100%, 0.07);
  padding: 2px 6px;
  border-radius: 6px;
}
.md pre {
  background: hsl(0 0% 6%);
  border: 1px solid hsla(0, 0%, 100%, 0.07);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
  margin: 12px 0;
}
.md pre code {
  background: none;
  padding: 0;
}
.md blockquote {
  margin: 12px 0;
  padding: 6px 14px;
  border-left: 3px solid hsl(var(--primary) / 0.5);
  color: hsl(var(--muted-foreground));
  background: hsla(0, 0%, 100%, 0.03);
  border-radius: 0 8px 8px 0;
}
.md hr {
  border: 0;
  border-top: 1px solid hsla(0, 0%, 100%, 0.1);
  margin: 18px 0;
}
.md table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}
.md th,
.md td {
  border: 1px solid hsla(0, 0%, 100%, 0.1);
  padding: 7px 11px;
  text-align: left;
  vertical-align: top;
}
.md th {
  background: hsla(0, 0%, 100%, 0.05);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground));
}
.md .risk {
  font-size: 1.05em;
}

/* ===================== MISC ===================== */
.muted {
  color: hsl(var(--muted-foreground));
}
.small {
  font-size: 12.5px;
}
.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}
.empty {
  text-align: center;
  padding: var(--s7) var(--s4);
  color: hsl(var(--muted-foreground));
}
.empty .ico {
  width: 40px;
  height: 40px;
  margin: 0 auto var(--s3);
  opacity: 0.35;
}
.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid hsla(0, 0%, 100%, 0.15);
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.center-pad {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s7);
  color: hsl(var(--muted-foreground));
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.skeleton {
  border-radius: 12px;
  background: linear-gradient(
    90deg,
    hsla(0, 0%, 15%, 0.4),
    hsla(0, 0%, 22%, 0.6),
    hsla(0, 0%, 15%, 0.4)
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}
@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.disclaimer {
  display: flex;
  gap: var(--s3);
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: 12px;
  margin-top: var(--s4);
  background: hsl(var(--status-pending) / 0.1);
  border: 1px solid hsl(var(--status-pending) / 0.3);
  font-size: 13px;
  line-height: 1.5;
  color: hsl(46 80% 78%);
}
.disclaimer .ico {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin-top: 1px;
}

.tax-result {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.tax-headline {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  flex-wrap: wrap;
}
.tax-amount {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: hsl(var(--foreground));
}
.tax-cur {
  font-size: 16px;
  color: hsl(var(--muted-foreground));
  font-weight: 600;
}

.lib-tabs {
  display: flex;
  gap: var(--s2);
  flex-wrap: wrap;
  margin-bottom: var(--s5);
}
.lib-tab {
  padding: 8px 16px;
  border-radius: 100px;
  border: 1px solid hsla(0, 0%, 100%, 0.08);
  background: hsla(0, 0%, 15%, 0.4);
  color: hsl(var(--muted-foreground));
  font-size: 13px;
  font-weight: 600;
}
.lib-tab.active {
  background: hsl(var(--primary) / 0.16);
  color: hsl(var(--foreground));
  border-color: hsl(var(--primary) / 0.4);
}

.doc-view {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--s5);
  align-items: start;
}
.doc-list {
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}
.doc-list .row.clickable.active {
  background: hsl(var(--primary) / 0.14);
  box-shadow: inset 2px 0 0 hsl(var(--primary));
}

/* ===================== TOAST ===================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 100;
  padding: 12px 20px;
  border-radius: 12px;
  background: hsla(0, 0%, 12%, 0.92);
  border: 1px solid hsla(0, 0%, 100%, 0.12);
  box-shadow: var(--glass-shadow-lg);
  font-size: 13.5px;
  font-weight: 500;
  backdrop-filter: blur(20px);
  opacity: 0;
  transition:
    opacity 0.25s,
    transform 0.25s;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.ok {
  border-color: hsl(var(--status-success) / 0.4);
}
.toast.err {
  border-color: hsl(var(--status-danger) / 0.4);
}

/* ===================== LOGIN ===================== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
}
.login-card {
  width: 100%;
  max-width: 380px;
  border-radius: 20px;
  padding: var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s3);
}
.login-hint {
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  margin: 0 0 var(--s2);
}
.login-error {
  font-size: 13px;
  color: hsl(0 80% 72%);
  background: hsl(var(--status-danger) / 0.12);
  border: 1px solid hsl(var(--status-danger) / 0.3);
  padding: 8px 12px;
  border-radius: 10px;
}
.login-submit {
  margin-top: var(--s2);
}
.login-foot {
  font-size: 11px;
  color: hsl(var(--muted-foreground) / 0.7);
  text-align: center;
  margin-top: var(--s2);
}

/* ===================== MODAL / POPUP ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s5);
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: modal-fade 0.22s var(--ease);
}
@keyframes modal-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.modal {
  width: 100%;
  max-width: 820px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  background: hsla(0, 0%, 11%, 0.92);
  backdrop-filter: blur(34px) saturate(1.35);
  -webkit-backdrop-filter: blur(34px) saturate(1.35);
  border: 1px solid hsla(0, 0%, 100%, 0.12);
  box-shadow: var(--glass-shadow-lg), var(--glass-glow);
  animation: modal-rise 0.26s var(--ease);
  overflow: hidden;
}
@keyframes modal-rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s5) var(--s5) var(--s4);
  border-bottom: 1px solid hsla(0, 0%, 100%, 0.07);
}
.modal-head h2 {
  font-size: 18px;
}
.modal-head .small {
  margin-top: 4px;
}
.modal-head-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex: 0 0 auto;
}
.modal-body {
  padding: var(--s5);
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
}
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  border: 1px solid hsla(0, 0%, 100%, 0.08);
  background: hsla(0, 0%, 15%, 0.5);
  color: hsl(var(--muted-foreground));
  font-size: 18px;
  line-height: 1;
  transition:
    background 0.18s var(--ease),
    color 0.18s var(--ease),
    transform 0.12s var(--ease);
}
.modal-close:hover {
  background: hsla(0, 0%, 20%, 0.7);
  color: hsl(var(--foreground));
}
.modal-close:active {
  transform: scale(0.92);
}

/* ===================== REFINED GLASS BUTTON (Library search etc.) ===================== */
.btn-glass-sm {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  min-height: 42px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 600;
  flex: 0 0 auto;
  color: hsl(var(--foreground));
  background: hsla(0, 0%, 16%, 0.55);
  border: 1px solid hsla(0, 0%, 100%, 0.09);
  box-shadow: inset 0 1px 0 hsla(0, 0%, 100%, 0.04);
  transition:
    background 0.18s var(--ease),
    border-color 0.18s var(--ease),
    transform 0.1s var(--ease);
}
.btn-glass-sm .ico {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}
.btn-glass-sm:hover {
  background: hsla(0, 0%, 20%, 0.7);
  border-color: hsl(var(--primary) / 0.4);
}
.btn-glass-sm:active {
  transform: scale(0.95);
  background: hsl(var(--primary) / 0.18);
  border-color: hsl(var(--primary) / 0.5);
}
.btn-glass-sm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===================== CHAT HISTORY DRAWER ===================== */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 248px);
  min-height: 360px;
}
.chat-history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 86vw;
  z-index: 120;
  display: flex;
  flex-direction: column;
  background: hsla(0, 0%, 9%, 0.94);
  backdrop-filter: blur(34px) saturate(1.4);
  -webkit-backdrop-filter: blur(34px) saturate(1.4);
  border-left: 1px solid hsla(0, 0%, 100%, 0.1);
  box-shadow: var(--glass-shadow-lg);
  transform: translateX(100%);
  transition: transform 0.3s var(--ease);
}
.chat-history-drawer.open {
  transform: translateX(0);
}
.chat-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s5) var(--s4) var(--s4);
  border-bottom: 1px solid hsla(0, 0%, 100%, 0.07);
}
.chat-history-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--s2);
}
.chat-history-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 11px 12px;
  border-radius: 10px;
  transition: background 0.15s var(--ease);
}
.chat-history-item:hover {
  background: hsla(0, 0%, 100%, 0.05);
}
.chat-history-item.active {
  background: hsl(var(--primary) / 0.14);
  box-shadow: inset 2px 0 0 hsl(var(--primary));
}
.chat-history-title {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-history-meta {
  font-size: 11.5px;
  color: hsl(var(--muted-foreground));
  margin-top: 3px;
}

/* ===================== PROFILE ===================== */
.profile-head {
  display: flex;
  align-items: center;
  gap: var(--s4);
}
.profile-avatar {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: hsl(var(--primary-fg));
  background: linear-gradient(135deg, hsl(6, 63%, 50%), hsl(6, 63%, 38%));
  box-shadow:
    0 4px 14px hsl(var(--primary) / 0.35),
    inset 0 1px 0 hsla(0, 0%, 100%, 0.18);
}
.profile-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.profile-mail {
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  margin-top: 2px;
}
.inline-note {
  font-size: 12.5px;
  padding: 9px 12px;
  border-radius: 10px;
  margin-top: var(--s3);
  line-height: 1.45;
}
.inline-note.warn {
  background: hsl(var(--status-pending) / 0.1);
  border: 1px solid hsl(var(--status-pending) / 0.28);
  color: hsl(46 80% 78%);
}
.inline-note.ok {
  background: hsl(var(--status-success) / 0.1);
  border: 1px solid hsl(var(--status-success) / 0.28);
  color: hsl(156 54% 66%);
}

/* ===================== TAX PREP ===================== */
.tax-step-label {
  margin: var(--s5) 0 var(--s3);
  font-size: 12.5px;
}

/* dropzone */
.tax-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: var(--s6) var(--s4);
  border-radius: 14px;
  border: 1.5px dashed hsla(0, 0%, 100%, 0.16);
  background: hsla(0, 0%, 100%, 0.025);
  cursor: pointer;
  transition:
    border-color 0.18s var(--ease),
    background 0.18s var(--ease),
    transform 0.18s var(--ease);
}
.dropzone:hover {
  border-color: hsl(var(--primary) / 0.5);
  background: hsl(var(--primary) / 0.06);
}
.dropzone.drag {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.1);
  transform: scale(1.005);
}
.dropzone-ico {
  width: 28px;
  height: 28px;
  color: hsl(var(--primary) / 0.85);
}
.dropzone-main {
  font-weight: 600;
  font-size: 14.5px;
}

/* file chips */
.file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s3);
}
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px 6px 10px;
  border-radius: 100px;
  background: hsl(var(--primary) / 0.12);
  border: 1px solid hsl(var(--primary) / 0.28);
  font-size: 12.5px;
  font-weight: 600;
  max-width: 100%;
}
.file-chip .chip-ico {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  color: hsl(var(--primary) / 0.9);
}
.file-chip .chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: hsla(0, 0%, 100%, 0.08);
  color: hsl(var(--foreground));
  flex: 0 0 18px;
}
.chip-x .ico {
  width: 11px;
  height: 11px;
}
.chip-x:hover {
  background: hsl(var(--status-danger) / 0.4);
}

/* review banner */
.review-banner {
  display: flex;
  gap: var(--s3);
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: var(--s4);
  background: hsl(var(--status-pending) / 0.12);
  border: 1px solid hsl(var(--status-pending) / 0.36);
  font-size: 13px;
  line-height: 1.5;
  color: hsl(46 80% 80%);
}
.review-banner .ico {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin-top: 1px;
}

/* totals bar */
.totals-bar {
  padding: var(--s4);
  border-radius: 14px;
  background: hsla(0, 0%, 100%, 0.03);
  border: 1px solid hsla(0, 0%, 100%, 0.06);
  margin-bottom: var(--s4);
}
.totals-bar .stat-value.sm {
  font-size: 19px;
}

/* ledger table */
.ledger-scroll {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid hsla(0, 0%, 100%, 0.07);
}
.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 720px;
}
.ledger-table thead th {
  text-align: left;
  padding: 10px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: hsl(var(--muted-foreground));
  background: hsla(0, 0%, 100%, 0.03);
  border-bottom: 1px solid hsla(0, 0%, 100%, 0.08);
}
.ledger-table th.num,
.ledger-table td.num {
  text-align: right;
}
.ledger-table th.rowx,
.ledger-table td.rowx {
  width: 38px;
  text-align: center;
}
.ledger-row td {
  padding: 5px 8px;
  border-bottom: 1px solid hsla(0, 0%, 100%, 0.05);
  vertical-align: middle;
}
.ledger-row:hover td {
  background: hsla(0, 0%, 100%, 0.02);
}
.ledger-row.low-conf {
  background: hsl(var(--status-pending) / 0.07);
  box-shadow: inset 3px 0 0 hsl(var(--status-pending));
}
.ledger-row.low-conf:hover td {
  background: hsl(var(--status-pending) / 0.1);
}
.cell-input {
  width: 100%;
  min-width: 90px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: hsl(var(--foreground));
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  transition:
    border-color 0.15s var(--ease),
    background 0.15s var(--ease);
}
.cell-input:hover {
  border-color: hsla(0, 0%, 100%, 0.1);
}
.cell-input:focus {
  outline: none;
  border-color: hsl(var(--primary) / 0.6);
  background: hsla(0, 0%, 0%, 0.25);
}
.cell-input.num {
  text-align: right;
  min-width: 96px;
}
.cell-input.cat {
  min-width: 110px;
}
.conf-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.conf-dot.low {
  background: hsl(var(--status-pending));
}
.conf-dot.error {
  background: hsl(var(--status-danger));
}
.dir-toggle {
  border: 1px solid transparent;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 11px;
  white-space: nowrap;
  transition:
    background 0.15s var(--ease),
    border-color 0.15s var(--ease);
}
.dir-toggle.in {
  background: hsl(var(--status-success) / 0.16);
  border-color: hsl(var(--status-success) / 0.4);
  color: hsl(156 54% 70%);
}
.dir-toggle.out {
  background: hsl(var(--status-danger) / 0.14);
  border-color: hsl(var(--status-danger) / 0.35);
  color: hsl(0 70% 74%);
}
.dir-toggle:hover {
  filter: brightness(1.18);
}
.ledger-table td.src {
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: hsl(var(--muted-foreground));
}
.row-del .ico {
  width: 14px;
  height: 14px;
}
.row-del:hover {
  background: hsl(var(--status-danger) / 0.18);
  color: hsl(0 70% 74%);
}

/* options switches */
.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s3);
  margin: var(--s3) 0 var(--s4);
}
.switch-field {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 12px;
  background: hsla(0, 0%, 100%, 0.025);
  border: 1px solid hsla(0, 0%, 100%, 0.07);
  cursor: pointer;
}
.switch-field input {
  margin-top: 2px;
  flex: 0 0 16px;
}
.switch-title {
  font-weight: 600;
  font-size: 13.5px;
}

/* result computation cards */
.prep-cards {
  margin-top: var(--s2);
}
.prep-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 3px solid hsl(var(--primary) / 0.55);
}
.prep-card.vat {
  border-top-color: hsl(var(--status-info) / 0.6);
}
.prep-card.company {
  border-top-color: hsl(var(--status-success) / 0.6);
}
.prep-headline {
  margin-top: 2px;
}
.prep-amount {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: hsl(var(--foreground));
}
.prep-sub {
  margin-bottom: var(--s2);
}
.prep-rows {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  margin: 0;
  padding: var(--s3) 0 0;
  border-top: 1px solid hsla(0, 0%, 100%, 0.07);
  font-size: 13px;
}
.prep-rows dt {
  color: hsl(var(--muted-foreground));
}
.prep-rows dd {
  margin: 0;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.prep-basis {
  margin-top: var(--s3);
  line-height: 1.45;
}

/* VAT flags card */
.flag-card {
  border: 1px solid hsl(var(--status-pending) / 0.3);
}
.flag-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  line-height: 1.5;
  color: hsl(46 60% 84%);
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-3 {
    grid-template-columns: 1fr 1fr;
  }
  .doc-view {
    grid-template-columns: 1fr;
  }
  .doc-list {
    max-height: 280px;
  }
}
@media (max-width: 720px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease);
    box-shadow: var(--glass-shadow-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main {
    margin-left: 0;
  }
  .hamburger {
    display: inline-flex;
  }
  .view {
    padding: var(--s4);
    padding-bottom: 96px;
  }
  .topbar {
    padding: var(--s3) var(--s4);
  }
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
  .chat-wrap {
    height: calc(100vh - 230px);
  }
  .chat-shell {
    height: calc(100dvh - 188px);
    min-height: 0;
  }
  .modal-overlay {
    padding: 0;
    align-items: stretch;
  }
  .modal {
    max-width: 100%;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
  }
  .modal-head,
  .modal-body {
    padding-left: var(--s4);
    padding-right: var(--s4);
  }

  .bottombar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 36;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .bottom-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: transparent;
    border: 0;
    color: hsl(var(--muted-foreground));
    font-size: 9.5px;
    font-weight: 600;
    padding: 6px 8px;
    border-radius: 10px;
    flex: 1;
  }
  .bottom-item .ico {
    width: 20px;
    height: 20px;
  }
  .bottom-item.active {
    color: hsl(var(--primary));
  }
  .msg {
    max-width: 92%;
  }
  .glass-input {
    font-size: 16px;
  } /* avoid iOS zoom */

  /* tax-prep mobile: stack ledger rows as cards, stack option switches */
  .toggle-row {
    grid-template-columns: 1fr;
  }
  .ledger-scroll {
    overflow-x: visible;
    border: 0;
    border-radius: 0;
  }
  .ledger-table {
    min-width: 0;
    display: block;
  }
  .ledger-table thead {
    display: none;
  }
  .ledger-table tbody,
  .ledger-table tr {
    display: block;
  }
  .ledger-row {
    margin-bottom: var(--s3);
    border-radius: 12px;
    border: 1px solid hsla(0, 0%, 100%, 0.08);
    background: hsla(0, 0%, 100%, 0.025);
    padding: 6px 4px;
  }
  .ledger-row.low-conf {
    border-color: hsl(var(--status-pending) / 0.45);
  }
  .ledger-row td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid hsla(0, 0%, 100%, 0.05);
    padding: 8px 10px;
  }
  .ledger-row td:last-child {
    border-bottom: 0;
  }
  .ledger-row td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
    color: hsl(var(--muted-foreground));
    flex: 0 0 auto;
  }
  .ledger-table td.num {
    text-align: right;
  }
  .cell-input {
    min-width: 0;
    max-width: 60%;
  }
  .ledger-table td.src {
    max-width: 60%;
  }
  .ledger-table td.rowx {
    width: auto;
    justify-content: flex-end;
  }
  .ledger-table td.rowx::before {
    content: "";
  }
  .prep-amount {
    font-size: 24px;
  }
}
@media (max-width: 460px) {
  .bottom-item .blabel {
    display: none;
  }
  .tax-amount {
    font-size: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ===================== REVIEW & SIGN ===================== */
.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.accent-card {
  border-color: hsl(var(--primary) / 0.28);
  box-shadow: 0 0 0 1px hsl(var(--primary) / 0.12) inset;
}
.doc-body {
  max-height: 420px;
  overflow: auto;
  padding-right: 6px;
}

/* validity banner */
.validity-banner {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: 12px 14px;
  border-radius: 12px;
  margin-top: var(--s4);
  font-size: 13px;
  line-height: 1.5;
}
.validity-banner .ico {
  flex: 0 0 18px;
  margin-top: 1px;
}
.validity-banner.ok {
  background: hsla(0, 0%, 100%, 0.04);
  border: 1px solid hsla(0, 0%, 100%, 0.08);
  color: hsl(var(--muted-foreground));
}
.validity-banner.warn {
  background: hsl(var(--status-pending) / 0.1);
  border: 1px solid hsl(var(--status-pending) / 0.32);
  color: hsl(42 82% 76%);
}
.validity-title {
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.01em;
  margin-bottom: 2px;
}
.validity-banner.warn .validity-title {
  color: hsl(44 90% 70%);
}
.validity-sum {
  opacity: 0.92;
}

/* fill note */
.fill-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: hsl(var(--primary) / 0.08);
  border: 1px solid hsl(var(--primary) / 0.22);
  color: hsl(8 60% 78%);
  font-size: 12.5px;
  line-height: 1.5;
  margin-bottom: var(--s4);
}
.fill-note .ico {
  flex: 0 0 16px;
  margin-top: 1px;
}
.glass-input.prefilled {
  border-color: hsl(var(--status-success) / 0.4);
  background: hsl(var(--status-success) / 0.06);
}

/* signed rows */
.signed-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: var(--s4);
}
.signed-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  background: hsl(var(--status-success) / 0.07);
  border: 1px solid hsl(var(--status-success) / 0.22);
}
.sig-check {
  flex: 0 0 24px;
  height: 24px;
  display: grid;
  place-items: center;
  color: hsl(156 54% 60%);
}
.sig-check .ico {
  width: 18px;
  height: 18px;
}

/* sign panel */
.sign-panel {
  padding: 14px;
  border-radius: 12px;
  background: hsla(0, 0%, 100%, 0.03);
  border: 1px solid hsla(0, 0%, 100%, 0.07);
  margin-top: var(--s3);
}
.sign-panel + .sign-panel {
  margin-top: var(--s4);
}
.sign-panel-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  color: hsl(var(--foreground));
}

/* segmented method toggle */
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 100px;
  background: hsla(0, 0%, 100%, 0.05);
  border: 1px solid hsla(0, 0%, 100%, 0.08);
  gap: 2px;
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 18px;
  border-radius: 100px;
  cursor: pointer;
  transition:
    background 0.16s,
    color 0.16s;
}
.seg-btn.active {
  background: hsl(var(--primary));
  color: hsl(var(--primary-fg));
  box-shadow: 0 2px 8px hsl(var(--primary) / 0.35);
}

/* signature method boxes */
.sig-method-box {
  margin-top: 12px;
}
.sig-typed-input {
  margin-bottom: 10px;
}
.sig-preview-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: hsl(var(--muted-foreground) / 0.8);
  margin-bottom: 4px;
}
.sig-script {
  min-height: 56px;
  display: flex;
  align-items: center;
  padding: 4px 14px;
  border-radius: 10px;
  background: hsla(0, 0%, 100%, 0.04);
  border: 1px dashed hsla(0, 0%, 100%, 0.14);
  font-family: "Snell Roundhand", "Brush Script MT", "Segoe Script", cursive;
  font-size: 30px;
  line-height: 1.1;
  color: #f4ede9;
  overflow-x: auto;
  white-space: nowrap;
}

/* signature pad (drawn) */
.sig-pad {
  border-radius: 10px;
}
.sig-pad-canvas-wrap {
  border-radius: 10px;
  background: hsla(0, 0%, 100%, 0.05);
  border: 1px dashed hsla(0, 0%, 100%, 0.18);
  overflow: hidden;
}
.sig-canvas {
  display: block;
  width: 100%;
  height: 160px;
  touch-action: none;
  cursor: crosshair;
}
.sig-pad-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

/* signed summary / verification */
.signed-card {
  border-color: hsl(var(--status-success) / 0.3);
}
.verify-box {
  padding: 14px;
  border-radius: 12px;
  background: hsl(var(--status-success) / 0.07);
  border: 1px solid hsl(var(--status-success) / 0.25);
  margin-bottom: var(--s4);
}
.verify-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: hsl(156 54% 62%);
  margin-bottom: 8px;
}
.verify-label .ico {
  width: 15px;
  height: 15px;
}
.verify-hash {
  display: block;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
  color: hsl(150 40% 78%);
  background: hsla(0, 0%, 0%, 0.25);
  padding: 9px 11px;
  border-radius: 8px;
}

@media (max-width: 720px) {
  .sig-script {
    font-size: 26px;
  }
  .doc-body {
    max-height: 300px;
  }
  /* stack the modal header so action buttons don't overlap the title on phones */
  .modal-head {
    flex-direction: column;
    align-items: stretch;
    gap: var(--s3);
  }
  .modal-head-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .modal-head-actions .btn-glass-sm {
    flex: 1 1 auto;
    justify-content: center;
  }
  .modal-head-actions .modal-close {
    flex: 0 0 42px;
  }
}

/* ===================================================================
   Sign a PDF — placement canvas, draggable marks, signature library
   Marks are positioned in PERCENT of the stage so the preview scale,
   window size and DPR never change where the stamp actually lands.
   =================================================================== */

.pdfsign-toolbar,
.pdfsign-spots,
.pdfsign-props {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
}
.pdfsign-toolbar select.glass-input {
  max-width: 220px;
}
.pdfsign-props {
  padding: var(--s2) var(--s3);
  border-radius: 10px;
  background: hsla(0, 0%, 100%, 0.03);
  border: 1px solid hsla(var(--glass-border));
  min-height: 46px;
}
.pdfsign-props .glass-input {
  max-width: 260px;
}
.pdfsign-props .pdfsign-num {
  max-width: 76px;
}
.pdfsign-props input[type="range"] {
  accent-color: hsl(var(--primary));
  max-width: 180px;
}

.pdfsign-card {
  padding: var(--s3);
}
.pdfsign-stage {
  position: relative;
  width: 100%;
  margin: 0 auto;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--glass-shadow-lg);
  /* aspect-ratio is set per page from pages_meta so layout is stable
     before the preview image arrives — no jump, no reflow. */
}
.pdfsign-page {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
.pdfsign-layer {
  position: absolute;
  inset: 0;
}

.pdfsign-mark {
  position: absolute;
  cursor: grab;
  touch-action: none; /* required: otherwise a touch-drag scrolls the page instead */
  border: 1.5px dashed transparent;
  border-radius: 4px;
  line-height: 1;
  transition: border-color 0.12s ease;
}
.pdfsign-mark:hover {
  border-color: hsla(var(--primary) / 0.5);
}
.pdfsign-mark.sel {
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsla(var(--primary) / 0.18);
  cursor: grabbing;
}
.pdfsign-mark.k-signature img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}
.pdfsign-text {
  display: inline-block;
  white-space: pre;
  color: #0d0d33;
  pointer-events: none;
}
.pdfsign-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: hsl(var(--primary));
  border: 2px solid #fff;
  cursor: ew-resize;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.pdfsign-mark.sel .pdfsign-handle,
.pdfsign-mark:hover .pdfsign-handle {
  opacity: 1;
}

.pdfsign-pager {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding-top: var(--s3);
  flex-wrap: wrap;
}

/* --- signature library */
.sigcard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--s3);
}
.sigcard {
  position: relative;
  border-radius: 10px;
  border: 1px solid hsla(var(--glass-border));
  background: repeating-conic-gradient(
      hsla(0, 0%, 100%, 0.05) 0% 25%,
      transparent 0% 50%
    )
    50% / 14px 14px; /* checkerboard: makes the removed background visible */
  padding: var(--s2);
  overflow: hidden;
}
.sigcard-img {
  display: block;
  width: 100%;
  height: 72px;
  object-fit: contain;
}
.sigcard-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  margin-top: var(--s2);
}
.sigcard-tag {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  background: hsla(0, 0%, 0%, 0.45);
  padding: 2px 6px;
  border-radius: 999px;
}
.siglib-add {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3);
  margin-top: var(--s3);
  padding-top: var(--s3);
  border-top: 1px solid hsla(var(--glass-border));
}
.siglib-add .glass-input {
  max-width: 240px;
}

.dropzone.busy {
  opacity: 0.55;
  pointer-events: none;
}
.dropzone.over {
  border-color: hsl(var(--primary));
  background: hsla(var(--primary) / 0.07);
}

@media (max-width: 640px) {
  .pdfsign-props .glass-input,
  .siglib-add .glass-input,
  .pdfsign-toolbar select.glass-input {
    max-width: 100%;
    flex: 1 1 100%;
  }
  .pdfsign-handle {
    width: 20px;
    height: 20px;
    opacity: 1;
  } /* fat-finger target on touch */
}

/* Checkbox + label row for the PDF signing surfaces.
   NOTE: do NOT reuse .sig-check here — that is a 24x24 green checkmark BADGE
   (flex: 0 0 24px), which squeezes a label into a narrow teal column. */
.pdfsign-check {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  cursor: pointer;
  color: hsl(var(--muted-foreground));
  line-height: 1.4;
}
.pdfsign-check input[type="checkbox"] {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: hsl(var(--primary));
  cursor: pointer;
}
.pdfsign-check:hover {
  color: hsl(var(--foreground));
}
.sign-panel .pdfsign-check {
  margin: var(--s3) 0;
}
.siglib-add .pdfsign-check {
  flex: 1 1 260px;
}

/* Icons inside buttons/links had NO size rule (only .btn-glass-sm .ico existed), so any
   icon(...) placed in a .btn-ghost / .btn-primary rendered at its natural box — the
   existing Documents detail view shipped a ~180px "back" arrow because of this.
   One default fixes every button in the app, current and future. */
.btn-primary .ico,
.btn-ghost .ico,
.btn-glass .ico,
.btn-sm .ico {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
}

/* Align icon + label in buttons that actually contain an icon. Scoped with :has() so
   text-only buttons keep their existing inline box (no regression anywhere else). */
.btn-primary:has(.ico),
.btn-ghost:has(.ico),
.btn-glass:has(.ico),
.btn-sm:has(.ico) {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
