/* ==========================================================================
   HIGH-DENSITY DESIGN SYSTEM — "World-Class Productivity Tool"
   Inspired by Linear, Raycast, Superhuman
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. DESIGN TOKENS
   -------------------------------------------------------------------------- */
:root {
  /* Spacing — compact scale */
  --hd-space-0: 0px;
  --hd-space-1: 2px;
  --hd-space-2: 4px;
  --hd-space-3: 6px;
  --hd-space-4: 8px;
  --hd-space-5: 10px;
  --hd-space-6: 12px;
  --hd-space-8: 16px;
  --hd-space-10: 20px;
  --hd-space-12: 24px;
  --hd-space-16: 32px;

  /* Typography */
  --hd-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --hd-font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', 'Roboto Mono', monospace;

  --hd-text-2xs: 0.6875rem;   /* 11px */
  --hd-text-xs: 0.75rem;      /* 12px — secondary data */
  --hd-text-sm: 0.8125rem;    /* 13px — primary table data */
  --hd-text-base: 0.875rem;   /* 14px — body */
  --hd-text-md: 0.9375rem;    /* 15px */
  --hd-text-lg: 1rem;         /* 16px */
  --hd-text-xl: 1.125rem;     /* 18px */
  --hd-text-2xl: 1.25rem;     /* 20px */
  --hd-text-3xl: 1.5rem;      /* 24px */

  --hd-leading-tight: 1.3;
  --hd-leading-normal: 1.5;

  /* Borders (Apple HIG aligned) */
  --hd-border-light: var(--system-gray5, #e2e8f0);
  --hd-border-subtle: var(--system-gray6, #f1f5f9);
  --hd-border-default: var(--system-gray4, #d1d1d6);
  --hd-radius-sm: var(--radius-small, 6px);
  --hd-radius-md: var(--radius-medium, 10px);
  --hd-radius-lg: var(--radius-large, 12px);
  --hd-radius-xl: var(--radius-extra-large, 16px);

  /* Shadows (Apple HIG aligned) */
  --hd-shadow-xs: var(--shadow-1, 0 1px 3px rgba(0,0,0,0.1));
  --hd-shadow-sm: var(--shadow-2, 0 1px 6px rgba(0,0,0,0.1));
  --hd-shadow-md: var(--shadow-3, 0 4px 12px rgba(0,0,0,0.15));
  --hd-shadow-overlay: var(--shadow-4, 0 8px 24px rgba(0,0,0,0.15));

  /* Status colors (Apple HIG system colors) */
  --hd-status-paid: var(--system-green, #30D158);
  --hd-status-sent: var(--system-blue, #007AFF);
  --hd-status-pending: var(--system-orange, #FF9500);
  --hd-status-overdue: var(--system-red, #FF3B30);
  --hd-status-draft: var(--system-gray, #8E8E93);

  /* Text colors */
  --hd-text-primary: #0f172a;      /* slate-900 */
  --hd-text-secondary: #334155;    /* slate-700 */
  --hd-text-muted: #64748b;        /* slate-500 */

  /* Command palette */
  --hd-backdrop: rgba(0,0,0,0.5);
}

/* Dark mode tokens */
html.dark {
  --hd-text-primary: #f1f5f9;      /* slate-100 */
  --hd-text-secondary: #cbd5e1;    /* slate-300 */
  --hd-text-muted: #94a3b8;        /* slate-400 */
  --hd-border-light: rgba(255,255,255,0.08);
  --hd-border-subtle: rgba(255,255,255,0.04);
  --hd-shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
  --hd-shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --hd-shadow-md: 0 2px 8px rgba(0,0,0,0.4);
  --hd-shadow-overlay: 0 8px 32px rgba(0,0,0,0.5);
  --hd-backdrop: rgba(0,0,0,0.7);
}


/* --------------------------------------------------------------------------
   1. COMPACT AESTHETIC — Density > Whitespace
   -------------------------------------------------------------------------- */

/* Cards: 30% reduced padding */
.hd-card {
  background: white;
  border: 1px solid var(--hd-border-light);
  border-radius: var(--hd-radius-lg);
  padding: var(--hd-space-10);  /* 20px vs previous 28-32px */
  box-shadow: var(--hd-shadow-xs);
  transition: border-color 150ms ease;
}
.hd-card:hover {
  border-color: #cbd5e1; /* slate-300 */
}
html.dark .hd-card {
  background: #1e1e1e;
  border-color: rgba(255,255,255,0.08);
}
html.dark .hd-card:hover {
  border-color: rgba(255,255,255,0.14);
}

/* Stat card — compact version */
.hd-stat-card {
  padding: var(--hd-space-8) var(--hd-space-10); /* 16px 20px */
  background: white;
  border: 1px solid var(--hd-border-light);
  border-radius: var(--hd-radius-lg);
  box-shadow: none;
  transition: border-color 150ms ease;
}
.hd-stat-card:hover {
  border-color: #94a3b8; /* slate-400 */
}
html.dark .hd-stat-card {
  background: #1e1e1e;
  border-color: rgba(255,255,255,0.08);
}
.hd-stat-card .hd-stat-label {
  font-size: var(--hd-text-xs);
  font-weight: 600;
  color: #334155;    /* slate-700 — no squinting on stat labels */
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--hd-space-2);
}
html.dark .hd-stat-card .hd-stat-label {
  color: #94a3b8;    /* slate-400 — sufficient contrast on dark */
}
.hd-stat-card .hd-stat-value {
  font-family: var(--hd-font-mono);
  font-size: var(--hd-text-2xl);
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.02em;
}
html.dark .hd-stat-card .hd-stat-value {
  color: #f1f5f9;
}

/* --------------------------------------------------------------------------
   2. HIGH-DENSITY TABLE COMPONENT
   -------------------------------------------------------------------------- */
.hd-table-wrapper {
  background: white;
  border: 1px solid var(--hd-border-light);
  border-radius: var(--hd-radius-lg);
  overflow: hidden;
  box-shadow: none;
}
html.dark .hd-table-wrapper {
  background: #1e1e1e;
  border-color: rgba(255,255,255,0.08);
}

.hd-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--hd-space-6) var(--hd-space-10);
  border-bottom: 1px solid var(--hd-border-light);
}
.hd-table-header h3 {
  font-size: var(--hd-text-sm);
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.01em;
}
html.dark .hd-table-header h3 {
  color: #f1f5f9;
}

/* Filter tabs — compact, no background */
.hd-filter-tabs {
  display: flex;
  gap: 2px;
  background: #f8fafc;
  border-radius: var(--hd-radius-md);
  padding: 2px;
}
html.dark .hd-filter-tabs {
  background: rgba(255,255,255,0.05);
}

.hd-filter-tab {
  padding: var(--hd-space-2) var(--hd-space-4);
  font-size: var(--hd-text-xs);
  font-weight: 500;
  color: #64748b;
  border-radius: var(--hd-radius-sm);
  cursor: pointer;
  transition: all 100ms ease;
  border: none;
  background: transparent;
  white-space: nowrap;
}
.hd-filter-tab:hover {
  color: #0f172a;
  background: white;
  box-shadow: var(--hd-shadow-xs);
}
html.dark .hd-filter-tab:hover {
  color: #f1f5f9;
  background: rgba(255,255,255,0.08);
}
.hd-filter-tab.active {
  color: #0f172a;
  background: white;
  box-shadow: var(--hd-shadow-sm);
}
html.dark .hd-filter-tab.active {
  color: #f1f5f9;
  background: rgba(255,255,255,0.1);
}

/* Table base */
.hd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--hd-text-sm); /* 13px primary */
  line-height: var(--hd-leading-tight);
}

.hd-table thead th {
  padding: var(--hd-space-3) var(--hd-space-6); /* 6px 12px — ultra compact header */
  text-align: left;
  font-size: var(--hd-text-xs);               /* 12px */
  font-weight: 600;
  color: #334155;    /* slate-700 — readable table headers */
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--hd-border-light);
  background: #fafbfc;
  user-select: none;
}
html.dark .hd-table thead th {
  background: rgba(255,255,255,0.02);
  color: #cbd5e1;    /* slate-300 — readable in dark mode */
  border-color: rgba(255,255,255,0.06);
}

.hd-table tbody td {
  padding: var(--hd-space-3) var(--hd-space-6); /* 6px 12px — 30%+ reduced from 16px */
  vertical-align: middle;
  border-bottom: 1px solid var(--hd-border-subtle);
  color: #0f172a;    /* slate-900 — full contrast data */
  font-size: var(--hd-text-sm);                /* 13px */
}
html.dark .hd-table tbody td {
  color: #e2e8f0;    /* slate-200 — high contrast in dark */
  border-color: rgba(255,255,255,0.04);
}

.hd-table tbody tr {
  transition: background 80ms ease;
}
.hd-table tbody tr:hover {
  background: #f8fafc;
}
html.dark .hd-table tbody tr:hover {
  background: rgba(255,255,255,0.03);
}

/* Table cell variants */
.hd-table .cell-primary {
  font-weight: 500;
  color: #0f172a;
}
html.dark .hd-table .cell-primary {
  color: #f1f5f9;
}
.hd-table .cell-secondary {
  font-size: var(--hd-text-xs);  /* 12px */
  color: #94a3b8;
}
.hd-table .cell-mono {
  font-family: var(--hd-font-mono);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hd-table .cell-link {
  color: var(--system-blue, #007AFF);
  font-weight: 500;
  font-family: var(--hd-font-mono);
  font-size: var(--hd-text-xs);
  cursor: pointer;
  text-decoration: none;
}
.hd-table .cell-link:hover {
  color: #1d4ed8;
  text-decoration: underline;
}

/* Row actions — icon-only, appear on hover */
.hd-row-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0.4;
  transition: opacity 100ms ease;
}
.hd-table tbody tr:hover .hd-row-actions {
  opacity: 1;
}
.hd-row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--hd-radius-sm);
  color: #64748b;
  transition: all 80ms ease;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.hd-row-action:hover {
  background: #f1f5f9;
  color: #0f172a;
}
html.dark .hd-row-action:hover {
  background: rgba(255,255,255,0.08);
  color: #f1f5f9;
}
.hd-row-action svg {
  width: 14px;
  height: 14px;
}


/* --------------------------------------------------------------------------
   3. STATUS BADGES — Dot + Text (replace pill shape)
   -------------------------------------------------------------------------- */
.hd-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--hd-text-xs);
  font-weight: 500;
  white-space: nowrap;
}
.hd-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Paid */
.hd-status-paid {
  color: #16a34a;
}
.hd-status-paid::before {
  background: var(--system-green, #30D158);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}
html.dark .hd-status-paid {
  color: #4ade80;
}

/* Sent */
.hd-status-sent {
  color: #2563eb;
}
.hd-status-sent::before {
  background: var(--system-blue, #007AFF);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
html.dark .hd-status-sent {
  color: #60a5fa;
}

/* Draft / Pending */
.hd-status-draft,
.hd-status-pending {
  color: #d97706;
}
.hd-status-draft::before,
.hd-status-pending::before {
  background: var(--system-orange, #FF9500);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}
html.dark .hd-status-draft,
html.dark .hd-status-pending {
  color: #fbbf24;
}

/* Overdue */
.hd-status-overdue {
  color: #dc2626;
}
.hd-status-overdue::before {
  background: var(--system-red, #FF3B30);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}
html.dark .hd-status-overdue {
  color: #f87171;
}

/* Accepted */
.hd-status-accepted {
  color: #16a34a;
}
.hd-status-accepted::before {
  background: var(--system-green, #30D158);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

/* Expired */
.hd-status-expired {
  color: #64748b;
}
.hd-status-expired::before {
  background: #94a3b8;
  box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.2);
}


/* --------------------------------------------------------------------------
   4. MONOSPACE NUMBERS — Precision Typography
   -------------------------------------------------------------------------- */
.font-mono-nums,
.hd-mono {
  font-family: var(--hd-font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}


/* --------------------------------------------------------------------------
   5. COMPACT ACTIONS — Subtle, labeled (no "big buttons")
   -------------------------------------------------------------------------- */
.hd-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--hd-space-2) var(--hd-space-4);
  font-size: var(--hd-text-xs);
  font-weight: 500;
  color: #64748b;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--hd-radius-md);
  cursor: pointer;
  transition: all 100ms ease;
  text-decoration: none;
  white-space: nowrap;
}
.hd-action:hover {
  color: #0f172a;
  background: #f1f5f9;
  border-color: var(--hd-border-light);
}
html.dark .hd-action:hover {
  color: #f1f5f9;
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
}
.hd-action svg {
  width: 14px;
  height: 14px;
}

/* Primary action — subtle blue */
.hd-action-primary {
  color: var(--system-blue, #007AFF);
  background: rgba(59, 130, 246, 0.06);
  border-color: rgba(59, 130, 246, 0.15);
}
.hd-action-primary:hover {
  color: #1d4ed8;
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.3);
}

/* Kbd hint inside actions */
.hd-action .hd-kbd {
  font-family: var(--hd-font-mono);
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(0,0,0,0.06);
  color: #94a3b8;
  border: 1px solid rgba(0,0,0,0.08);
  line-height: 1.4;
}
html.dark .hd-action .hd-kbd {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: #64748b;
}


/* --------------------------------------------------------------------------
   6. COMMAND PALETTE (Cmd+K)
   -------------------------------------------------------------------------- */
.hd-command-overlay {
  position: fixed;
  inset: 0;
  background: var(--hd-backdrop);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
  opacity: 0;
  visibility: hidden;
  transition: opacity 120ms ease, visibility 120ms ease;
}
.hd-command-overlay.active {
  opacity: 1;
  visibility: visible;
}

.hd-command-palette {
  width: 100%;
  max-width: 560px;
  background: white;
  border: 1px solid var(--hd-border-light);
  border-radius: var(--hd-radius-xl);
  box-shadow: var(--hd-shadow-overlay);
  overflow: hidden;
  transform: scale(0.98) translateY(-8px);
  transition: transform 150ms cubic-bezier(0.16, 1, 0.3, 1);
}
.hd-command-overlay.active .hd-command-palette {
  transform: scale(1) translateY(0);
}
html.dark .hd-command-palette {
  background: #1a1a1a;
  border-color: rgba(255,255,255,0.1);
}

.hd-command-input-wrapper {
  display: flex;
  align-items: center;
  padding: var(--hd-space-6) var(--hd-space-8);
  border-bottom: 1px solid var(--hd-border-light);
  gap: var(--hd-space-4);
}
.hd-command-input-wrapper svg {
  width: 18px;
  height: 18px;
  color: #94a3b8;
  flex-shrink: 0;
}
.hd-command-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--hd-text-base);
  font-family: var(--hd-font-sans);
  color: #0f172a;
  caret-color: var(--system-blue, #007AFF);
}
html.dark .hd-command-input {
  color: #f1f5f9;
}
.hd-command-input::placeholder {
  color: #94a3b8;
}

.hd-command-results {
  max-height: 320px;
  overflow-y: auto;
  padding: var(--hd-space-2) 0;
}

.hd-command-group-label {
  padding: var(--hd-space-3) var(--hd-space-8);
  font-size: var(--hd-text-2xs);
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hd-command-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--hd-space-3) var(--hd-space-8);
  cursor: pointer;
  transition: background 60ms ease;
}
.hd-command-item:hover,
.hd-command-item.selected {
  background: #f1f5f9;
}
html.dark .hd-command-item:hover,
html.dark .hd-command-item.selected {
  background: rgba(255,255,255,0.05);
}

.hd-command-item-left {
  display: flex;
  align-items: center;
  gap: var(--hd-space-4);
}
.hd-command-item-left svg {
  width: 16px;
  height: 16px;
  color: #64748b;
}
.hd-command-item-label {
  font-size: var(--hd-text-sm);
  font-weight: 500;
  color: #334155;
}
html.dark .hd-command-item-label {
  color: #e2e8f0;
}
.hd-command-item-desc {
  font-size: var(--hd-text-xs);
  color: #94a3b8;
  margin-left: 4px;
}

.hd-command-item-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hd-command-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--hd-space-3) var(--hd-space-8);
  border-top: 1px solid var(--hd-border-light);
  font-size: var(--hd-text-2xs);
  color: #94a3b8;
}
.hd-command-footer-hints {
  display: flex;
  gap: var(--hd-space-6);
}
.hd-command-footer-hint {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Keyboard key badge */
.hd-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 4px;
  font-family: var(--hd-font-mono);
  font-size: 10px;
  font-weight: 500;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 3px;
  line-height: 1;
}
html.dark .hd-kbd {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: #94a3b8;
}


/* --------------------------------------------------------------------------
   7. WYSIWYG INVOICE EDITOR — Document-first layout
   -------------------------------------------------------------------------- */
.hd-editor-container {
  display: flex;
  gap: var(--hd-space-10);
  min-height: calc(100vh - 140px);
}

/* The "paper" — main editing area */
.hd-invoice-paper {
  flex: 1;
  max-width: 800px;
  margin: 0 auto;
  background: white;
  border: 1px solid var(--hd-border-light);
  border-radius: var(--hd-radius-lg);
  box-shadow: var(--hd-shadow-sm);
  padding: 48px 56px;
  min-height: 1000px;
  position: relative;
  font-family: var(--hd-font-sans);
}
html.dark .hd-invoice-paper {
  background: #1e1e1e;
  border-color: rgba(255,255,255,0.08);
}

/* Invoice paper header — editable company info */
.hd-paper-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--hd-border-light);
}
.hd-paper-logo {
  max-height: 48px;
  width: auto;
}
.hd-paper-title {
  font-size: var(--hd-text-3xl);
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.03em;
  text-transform: uppercase;
}
html.dark .hd-paper-title {
  color: #f1f5f9;
}

/* Inline-editable fields on the paper */
.hd-paper-field {
  border: 1px solid transparent;
  border-radius: var(--hd-radius-sm);
  padding: 2px 4px;
  margin: -2px -4px;
  transition: border-color 120ms ease, background 120ms ease;
  outline: none;
  min-width: 60px;
}
.hd-paper-field:hover {
  border-color: var(--hd-border-light);
  background: #fafbfc;
}
html.dark .hd-paper-field:hover {
  background: rgba(255,255,255,0.03);
}
.hd-paper-field:focus {
  border-color: var(--system-blue, #007AFF);
  background: rgba(59, 130, 246, 0.04);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* Meta grid (Invoice #, Date, Due date) */
.hd-paper-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--hd-space-2) var(--hd-space-8);
  font-size: var(--hd-text-sm);
  margin-bottom: 32px;
}
.hd-paper-meta-label {
  color: #94a3b8;
  font-weight: 500;
  font-size: var(--hd-text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 4px;
}
.hd-paper-meta-value {
  font-family: var(--hd-font-mono);
  color: #0f172a;
  font-variant-numeric: tabular-nums;
}
html.dark .hd-paper-meta-value {
  color: #f1f5f9;
}

/* Bill to / Ship to blocks */
.hd-paper-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--hd-space-16);
  margin-bottom: 32px;
}
.hd-paper-party-label {
  font-size: var(--hd-text-2xs);
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--hd-space-3);
}
.hd-paper-party-name {
  font-size: var(--hd-text-base);
  font-weight: 600;
  color: #0f172a;
  margin-bottom: var(--hd-space-1);
}
html.dark .hd-paper-party-name {
  color: #f1f5f9;
}
.hd-paper-party-detail {
  font-size: var(--hd-text-xs);
  color: #64748b;
  line-height: var(--hd-leading-normal);
}

/* Line items table on paper */
.hd-paper-items {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--hd-text-sm);
  margin-bottom: 32px;
}
.hd-paper-items thead th {
  text-align: left;
  padding: var(--hd-space-3) var(--hd-space-4);
  font-size: var(--hd-text-2xs);
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid #e2e8f0;
}
html.dark .hd-paper-items thead th {
  border-color: rgba(255,255,255,0.1);
}
.hd-paper-items thead th:last-child {
  text-align: right;
}

.hd-paper-items tbody td {
  padding: var(--hd-space-4);
  border-bottom: 1px solid var(--hd-border-subtle);
  vertical-align: top;
}
.hd-paper-items tbody td:last-child {
  text-align: right;
  font-family: var(--hd-font-mono);
  font-variant-numeric: tabular-nums;
}
.hd-paper-items tbody td input[type="text"],
.hd-paper-items tbody td input[type="number"] {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--hd-radius-sm);
  padding: 2px 4px;
  width: 100%;
  outline: none;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  transition: border-color 100ms ease;
}
.hd-paper-items tbody td input:hover {
  border-color: var(--hd-border-light);
}
.hd-paper-items tbody td input:focus {
  border-color: var(--system-blue, #007AFF);
  background: rgba(59, 130, 246, 0.04);
}
.hd-paper-items tbody td .hd-item-qty,
.hd-paper-items tbody td .hd-item-rate,
.hd-paper-items tbody td .hd-item-amount {
  font-family: var(--hd-font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Add item row */
.hd-add-item-row {
  padding: var(--hd-space-4);
}
.hd-add-item-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--hd-space-2) var(--hd-space-4);
  font-size: var(--hd-text-xs);
  font-weight: 500;
  color: var(--system-blue, #007AFF);
  background: transparent;
  border: 1px dashed #bfdbfe;
  border-radius: var(--hd-radius-md);
  cursor: pointer;
  transition: all 100ms ease;
}
.hd-add-item-btn:hover {
  background: rgba(59, 130, 246, 0.04);
  border-color: #93c5fd;
}
.hd-add-item-btn svg {
  width: 14px;
  height: 14px;
}

/* Totals section on paper */
.hd-paper-totals {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}
.hd-paper-totals-grid {
  width: 240px;
}
.hd-paper-totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--hd-space-2) 0;
  font-size: var(--hd-text-sm);
}
.hd-paper-totals-row .hd-totals-label {
  color: #64748b;
  font-weight: 500;
}
.hd-paper-totals-row .hd-totals-value {
  font-family: var(--hd-font-mono);
  font-variant-numeric: tabular-nums;
  color: #0f172a;
  font-weight: 500;
}
html.dark .hd-paper-totals-row .hd-totals-value {
  color: #f1f5f9;
}
.hd-paper-totals-row.hd-total-final {
  border-top: 2px solid #0f172a;
  padding-top: var(--hd-space-3);
  margin-top: var(--hd-space-2);
}
html.dark .hd-paper-totals-row.hd-total-final {
  border-color: #f1f5f9;
}
.hd-paper-totals-row.hd-total-final .hd-totals-label {
  font-size: var(--hd-text-sm);
  font-weight: 700;
  color: #0f172a;
}
html.dark .hd-paper-totals-row.hd-total-final .hd-totals-label {
  color: #f1f5f9;
}
.hd-paper-totals-row.hd-total-final .hd-totals-value {
  font-size: var(--hd-text-lg);
  font-weight: 700;
}

/* Notes section */
.hd-paper-notes {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--hd-border-subtle);
}
.hd-paper-notes-label {
  font-size: var(--hd-text-2xs);
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--hd-space-3);
}
.hd-paper-notes textarea {
  width: 100%;
  border: none;
  background: transparent;
  font-size: var(--hd-text-sm);
  color: #64748b;
  resize: none;
  outline: none;
  line-height: var(--hd-leading-normal);
}
html.dark .hd-paper-notes textarea {
  color: #94a3b8;
}


/* --------------------------------------------------------------------------
   8. EDITOR SIDE PANEL
   -------------------------------------------------------------------------- */
.hd-editor-sidebar {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 100px;
  align-self: flex-start;
}

.hd-sidebar-section {
  background: white;
  border: 1px solid var(--hd-border-light);
  border-radius: var(--hd-radius-lg);
  padding: var(--hd-space-8);
  margin-bottom: var(--hd-space-6);
}
html.dark .hd-sidebar-section {
  background: #1e1e1e;
  border-color: rgba(255,255,255,0.08);
}

.hd-sidebar-title {
  font-size: var(--hd-text-2xs);
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--hd-space-4);
}

.hd-sidebar-field-group {
  margin-bottom: var(--hd-space-4);
}
.hd-sidebar-label {
  display: block;
  font-size: var(--hd-text-xs);
  font-weight: 600;
  color: #334155;  /* slate-700 — readable label */
  margin-bottom: var(--hd-space-1);
}
html.dark .hd-sidebar-label {
  color: #cbd5e1;  /* slate-300 in dark */
}
.hd-sidebar-input {
  width: 100%;
  padding: var(--hd-space-2) var(--hd-space-4);
  font-size: var(--hd-text-sm);
  font-family: var(--hd-font-sans);
  color: #0f172a;
  background: #fafbfc;
  border: 1px solid var(--hd-border-light);
  border-radius: var(--hd-radius-md);
  outline: none;
  transition: border-color 100ms ease;
}
html.dark .hd-sidebar-input {
  background: rgba(255,255,255,0.04);
  color: #f1f5f9;
  border-color: rgba(255,255,255,0.08);
}
.hd-sidebar-input:focus {
  border-color: var(--system-blue, #007AFF);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}


/* --------------------------------------------------------------------------
   9. COMPACT HEADER / TOOLBAR
   -------------------------------------------------------------------------- */
.hd-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--hd-space-4) var(--hd-space-10);
  background: white;
  border-bottom: 1px solid var(--hd-border-light);
  min-height: 48px; /* compact header */
}
html.dark .hd-toolbar {
  background: #1a1a1a;
  border-color: rgba(255,255,255,0.06);
}

.hd-toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--hd-space-6);
}
.hd-toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--hd-space-2);
}

/* Breadcrumb in toolbar */
.hd-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--hd-space-2);
  font-size: var(--hd-text-xs);
  color: #94a3b8;
}
.hd-breadcrumb a {
  color: #94a3b8;
  text-decoration: none;
  transition: color 80ms ease;
}
.hd-breadcrumb a:hover {
  color: #0f172a;
}
html.dark .hd-breadcrumb a:hover {
  color: #f1f5f9;
}
.hd-breadcrumb-current {
  color: #0f172a;
  font-weight: 500;
}
html.dark .hd-breadcrumb-current {
  color: #f1f5f9;
}
.hd-breadcrumb-sep {
  color: #cbd5e1;
}


/* --------------------------------------------------------------------------
   10. UTILITY CLASSES
   -------------------------------------------------------------------------- */
/* Quick action row — list of inline shortcuts */
.hd-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--hd-space-3);
  padding: var(--hd-space-4) 0;
}

/* Section divider */
.hd-divider {
  border: none;
  border-top: 1px solid var(--hd-border-light);
  margin: var(--hd-space-8) 0;
}

/* Page title — high density */
.hd-page-title {
  font-size: var(--hd-text-xl);
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.02em;
}
html.dark .hd-page-title {
  color: #f1f5f9;
}

.hd-page-subtitle {
  font-size: var(--hd-text-xs);
  color: #64748b;
  margin-top: 2px;
}

/* Empty state — minimal */
.hd-empty-state {
  text-align: center;
  padding: var(--hd-space-16) var(--hd-space-8);
  color: #94a3b8;
}
.hd-empty-state svg {
  width: 32px;
  height: 32px;
  margin: 0 auto var(--hd-space-4);
  color: #cbd5e1;
}
.hd-empty-state p {
  font-size: var(--hd-text-sm);
}


/* --------------------------------------------------------------------------
   11. RESPONSIVE ADJUSTMENTS
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .hd-editor-container {
    flex-direction: column;
  }
  .hd-editor-sidebar {
    width: 100%;
    position: static;
  }
  .hd-invoice-paper {
    padding: 24px 20px;
  }
  .hd-paper-parties {
    grid-template-columns: 1fr;
  }
  .hd-command-palette {
    max-width: calc(100vw - 32px);
  }
}
