/* ==========================================================================
 * GCC / SOFT SAUDA ERP — DESIGN SYSTEM
 * Uses system-native sans & monospace font stacks (no render-blocking CDN fonts)
 * Ultra-compact zero-padding configuration for legacy & small-res monitors
 * ========================================================================== */

/* ── Light Theme (Default Root) ── */
:root,
[data-theme="light"] {
  --background: #fcfdfa;
  --foreground: #2c3327;
  --card: #ffffff;
  --card-foreground: #2c3327;
  --popover: #ffffff;
  --popover-foreground: #2c3327;
  --primary: #3d5a2d;
  --primary-foreground: #f1f5ef;
  --secondary: #6a7c5c;
  --secondary-foreground: #ffffff;
  --muted: #f0f2ed;
  --muted-foreground: #5c6356;
  --accent: #e9ece5;
  --accent-foreground: #3d5a2d;
  --destructive: #9e3a2c;
  --destructive-foreground: #ffffff;
  --border: #dce1d8;
  --input: #dce1d8;
  --ring: #3d5a2d;
  --chart-1: #4a6741;
  --chart-2: #c2843e;
  --chart-3: #6b8e23;
  --chart-4: #a3b18a;
  --chart-5: #d4a373;
  --sidebar: #f4f6f2;
  --sidebar-foreground: #2c3327;
  --sidebar-primary: #3d5a2d;
  --sidebar-primary-foreground: #f1f5ef;
  --sidebar-accent: #e4e9e0;
  --sidebar-accent-foreground: #3d5a2d;
  --sidebar-border: #dce1d8;
  --sidebar-ring: #3d5a2d;

  /* Oat & ERP Semantic Aliases */
  --faint: #f4f6f2;
  --faint-foreground: #5c6356;
  --danger: var(--destructive);
  --danger-foreground: var(--destructive-foreground);
  --success: var(--primary);
  --success-foreground: var(--primary-foreground);
  --warning: #c2843e;
  --warning-foreground: #ffffff;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Source Serif 4', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --font-family-base: var(--font-sans);
  --font-family-mono: var(--font-mono);
  --tracking-normal: -0.01em;

  /* Radii */
  --radius: 0.375rem;
  --radius-base: 0.25rem;
  --radius-small: 0.125rem;
  --radius-medium: 0.25rem;
  --radius-large: 0.375rem;
  --radius-full: 9999px;
  --radius-pill: 9999px;
  --radius-card: 0.25rem;
  --radius-input: 0.125rem;

  /* Shadows */
  --shadow-x: 0px;
  --shadow-y: 4px;
  --shadow-blur: 10px;
  --shadow-spread: 0px;
  --shadow-opacity: 0.05;
  --shadow-color: #000000;
  --shadow-2xs: 0px 4px 10px 0px hsl(0 0% 0% / 0.03);
  --shadow-xs: 0px 4px 10px 0px hsl(0 0% 0% / 0.03);
  --shadow-sm: 0px 4px 10px 0px hsl(0 0% 0% / 0.05), 0px 1px 2px -1px hsl(0 0% 0% / 0.05);
  --shadow: 0px 4px 10px 0px hsl(0 0% 0% / 0.05), 0px 1px 2px -1px hsl(0 0% 0% / 0.05);
  --shadow-md: 0px 4px 10px 0px hsl(0 0% 0% / 0.05), 0px 2px 4px -1px hsl(0 0% 0% / 0.05);
  --shadow-lg: 0px 4px 10px 0px hsl(0 0% 0% / 0.05), 0px 4px 6px -1px hsl(0 0% 0% / 0.05);
  --shadow-xl: 0px 4px 10px 0px hsl(0 0% 0% / 0.05), 0px 8px 10px -1px hsl(0 0% 0% / 0.05);
  --shadow-2xl: 0px 4px 10px 0px hsl(0 0% 0% / 0.13);
  --shadow-small: var(--shadow-sm);
  --shadow-medium: var(--shadow-md);
  --shadow-large: var(--shadow-lg);

  /* Spacing Tokens — Ultra-compact Zero Padding for Low-Res Monitors (1024x768 / 1366x768) */
  --spacing: 0.25rem;
  --space-1: 0.1rem;   /* ~1.5px */
  --space-2: 0.175rem; /* ~2.8px */
  --space-3: 0.3rem;   /* ~4.8px */
  --space-4: 0.45rem;  /* ~7.2px */
  --space-5: 0.65rem;  /* ~10.4px */
  --space-6: 0.85rem;  /* ~13.6px */
  --space-8: 1.1rem;
  --space-10: 1.35rem;
  --space-12: 1.6rem;
  --bar-height: 0.25rem;
  --topbar-height: 38px;

  /* Typography Scales */
  --text-1: 1.25rem;
  --text-2: 1.125rem;
  --text-3: 1rem;
  --text-4: 0.875rem;
  --text-5: 0.8125rem;
  --text-6: 0.75rem;
  --text-7: 0.6875rem;
  --text-8: 0.625rem;
  --text-regular: var(--text-6);
  --leading-normal: 1.2;
}

/* ── Dark Theme ── */
.dark,
[data-theme="dark"] {
  --background: #131611;
  --foreground: #ecf0eb;
  --card: #1a1e17;
  --card-foreground: #ecf0eb;
  --popover: #1a1e17;
  --popover-foreground: #ecf0eb;
  --primary: #6b8e23;
  --primary-foreground: #0d1109;
  --secondary: #4a5441;
  --secondary-foreground: #ecf0eb;
  --muted: #1e241c;
  --muted-foreground: #9ca396;
  --accent: #282f24;
  --accent-foreground: #c5d0bc;
  --destructive: #c84a3c;
  --destructive-foreground: #ffffff;
  --border: #2a3026;
  --input: #2a3026;
  --ring: #6b8e23;
  --chart-1: #6b8e23;
  --chart-2: #d4a373;
  --chart-3: #8fb339;
  --chart-4: #556b2f;
  --chart-5: #e9c46a;
  --sidebar: #0d1109;
  --sidebar-foreground: #ecf0eb;
  --sidebar-primary: #6b8e23;
  --sidebar-primary-foreground: #0d1109;
  --sidebar-accent: #1e241c;
  --sidebar-accent-foreground: #ecf0eb;
  --sidebar-border: #2a3026;
  --sidebar-ring: #6b8e23;

  /* Oat & ERP Semantic Aliases */
  --faint: #1e241c;
  --faint-foreground: #9ca396;
  --danger: var(--destructive);
  --danger-foreground: var(--destructive-foreground);
  --success: var(--primary);
  --success-foreground: var(--primary-foreground);
  --warning: #d4a373;
  --warning-foreground: #0d1109;

  /* Shadows (Dark Mode) */
  --shadow-x: 0px;
  --shadow-y: 6px;
  --shadow-blur: 12px;
  --shadow-spread: 0px;
  --shadow-opacity: 0.4;
  --shadow-color: #000000;
  --shadow-2xs: 0px 6px 12px 0px hsl(0 0% 0% / 0.20);
  --shadow-xs: 0px 6px 12px 0px hsl(0 0% 0% / 0.20);
  --shadow-sm: 0px 6px 12px 0px hsl(0 0% 0% / 0.40), 0px 1px 2px -1px hsl(0 0% 0% / 0.40);
  --shadow: 0px 6px 12px 0px hsl(0 0% 0% / 0.40), 0px 1px 2px -1px hsl(0 0% 0% / 0.40);
  --shadow-md: 0px 6px 12px 0px hsl(0 0% 0% / 0.40), 0px 2px 4px -1px hsl(0 0% 0% / 0.40);
  --shadow-lg: 0px 6px 12px 0px hsl(0 0% 0% / 0.40), 0px 4px 6px -1px hsl(0 0% 0% / 0.40);
  --shadow-xl: 0px 6px 12px 0px hsl(0 0% 0% / 0.40), 0px 8px 10px -1px hsl(0 0% 0% / 0.40);
  --shadow-2xl: 0px 6px 12px 0px hsl(0 0% 0% / 1.00);
  --shadow-small: var(--shadow-sm);
  --shadow-medium: var(--shadow-md);
  --shadow-large: var(--shadow-lg);
}

/* ── Typography ── */
body, button, input, select, textarea {
  font-family: var(--font-family-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Top Bar ── */
.topbar {
  background: var(--sidebar);
  border-bottom: 1px solid var(--sidebar-border);
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 0.5rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  overflow: visible;
}

.topbar-brand {
  flex-shrink: 0;
  margin-right: 0.75rem;
}

.topbar-brand img {
  height: 24px !important;
}

.topbar-title {
  font-weight: 800;
  font-size: 0.8125rem;
  color: var(--sidebar-foreground);
  letter-spacing: -0.02em;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  flex: 1;
  align-self: stretch;
  flex-wrap: nowrap;
  overflow: visible;
}

.topbar-nav a {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-small);
  font-size: 0.725rem;
  font-weight: 500;
  color: var(--sidebar-foreground);
  opacity: 0.85;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  position: relative;
}

.topbar-nav a:hover {
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
  opacity: 1;
}

.topbar-nav a.active {
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
  font-weight: 600;
  opacity: 1;
}

.topbar-nav a svg {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
  opacity: 0.75;
}

.topbar-nav a:hover svg,
.topbar-nav a.active svg {
  opacity: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  margin-left: auto;
  position: relative;
  z-index: 50;
}

.topbar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sidebar-foreground);
  text-decoration: none;
  padding: 0.25rem;
  border-radius: var(--radius-small);
  transition: color 0.15s, background 0.15s;
}

.topbar-logout:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* ── Main Content Area (Dense & Low-res optimized) ── */
.main-content {
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  padding: 0.35rem 0.5rem;
  box-sizing: border-box;
}

/* ── Page Header (Ultra-compact) ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.page-header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0;
}

.page-header .actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.page-header .actions button,
.page-header .actions a {
  margin-right: 0 !important;
}

/* ── Stats Cards (Dashboard - Compact) ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  padding: 0.35rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  transition: border-color 0.2s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  overflow: hidden;
}

.stat-card:hover {
  border-color: var(--ring);
}

.stat-card .stat-icon {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0.2rem;
  border-radius: var(--radius-small);
  background: var(--accent);
  color: var(--accent-foreground);
}

.stat-card .stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-family-mono);
  color: var(--foreground);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stat-card .stat-desc {
  font-size: 0.625rem;
  color: var(--muted-foreground);
}

/* ── Tables (Zero-Padding & Ultra-High Density) ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

table thead th {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.625rem;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  padding: 0.2rem 0.35rem;
  background: var(--muted);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

table thead th:last-child {
  border-right: none;
}

table tbody tr {
  border-bottom: 1px solid var(--border);
  background-color: transparent;
  height: 1.5rem;
}

table tbody tr:hover {
  background-color: color-mix(in srgb, var(--primary) 9%, transparent) !important;
}

table td {
  padding: 0.125rem 0.35rem;
  vertical-align: middle;
  color: var(--foreground);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  line-height: 1.2;
}

table td:last-child {
  border-right: none;
}

table tfoot tr {
  border-top: 2px solid var(--border);
  background-color: var(--muted);
  font-weight: 700;
  height: 1.5rem;
}

table tfoot td {
  padding: 0.15rem 0.35rem;
  line-height: 1.2;
}

.table-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  overflow: hidden;
}

.table-header {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.table-header h2 {
  font-size: 0.725rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

/* ── Action Buttons & Small Buttons Override ── */
button, .btn {
  height: 24px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-small);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  box-sizing: border-box;
}

button.small {
  padding: 0.1rem 0.35rem !important;
  font-size: 0.6875rem !important;
  font-weight: 600 !important;
  border-radius: var(--radius-small) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.2rem !important;
  line-height: 1 !important;
  height: 20px !important;
}

button.small svg {
  width: 0.75rem !important;
  height: 0.75rem !important;
  min-width: 0.75rem !important;
  min-height: 0.75rem !important;
  stroke-width: 2.5 !important;
  display: inline-block !important;
  vertical-align: middle !important;
  flex-shrink: 0 !important;
}

/* ── Forms (Ultra-Compact Zero-Padding) ── */
:where(input:not([type=checkbox],[type=radio],[type=range],[type=file],[type=color]), select) {
  width: 100%;
  margin-block-start: 0;
  margin-top: 0;
  padding: 0.125rem 0.35rem;
  height: 24px;
  font-size: 0.75rem;
  line-height: 1.2;
  background-color: var(--card);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius-small);
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea:where(textarea) {
  width: 100%;
  margin-top: 0;
  padding: 0.2rem 0.35rem;
  font-size: 0.75rem;
  line-height: 1.2;
  background-color: var(--card);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius-small);
  min-height: 2.25rem;
  box-sizing: border-box;
}

:where(input, select, textarea):focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 1px var(--ring);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.25rem 0.4rem;
}

.form-group {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
}

.form-group label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted-foreground);
  line-height: 1.1;
  margin-bottom: 0;
}

.form-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

/* ── Monospace amounts ── */
.mono {
  font-family: var(--font-family-mono);
}

/* ── Status badges ── */
.badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-small);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  white-space: nowrap;
}

.badge-active {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
  color: var(--primary);
}

.badge-draft {
  background: color-mix(in srgb, var(--warning) 15%, transparent);
  color: var(--warning);
}

.badge-inactive {
  background: var(--muted);
  color: var(--muted-foreground);
}

/* ── Loading overlay ── */
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

/* ── Toast container ── */
.toast-container {
  position: fixed;
  top: calc(var(--topbar-height) + 0.35rem);
  right: 0.5rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* ── Theme toggle button ── */
.theme-toggle {
  background: none;
  border: none;
  border-radius: var(--radius-small);
  padding: 0.25rem;
  cursor: pointer;
  color: var(--sidebar-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

.theme-toggle:hover {
  color: var(--primary);
  opacity: 1;
}

/* ── Autocomp dropdown styling (Compact) ── */
.autocomp {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow-md);
  max-height: 180px;
  overflow-y: auto;
  z-index: 50;
}

.autocomp .autocomp-item {
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--foreground);
  line-height: 1.2;
}

.autocomp .autocomp-item:hover,
.autocomp .autocomp-item.autocomp-sel {
  background: var(--accent);
  color: var(--accent-foreground);
}

/* ── Mobile menu toggle default ── */
.mobile-menu-toggle {
  display: none !important;
}

/* ── Mobile menu backdrop default ── */
.mobile-menu-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--topbar-height);
  background: rgba(0, 0, 0, 0.55);
  z-index: 45;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

/* ── Mobile drawer default ── */
.topbar-nav-mobile-drawer {
  display: none !important;
}

/* ── Custom Layout Classes ── */
.layout-200-1fr {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.layout-1fr-2fr {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.5rem;
}

/* ── Responsive ── */
@media (max-width: 1280px) {
  .topbar {
    padding: 0 0.75rem;
  }

  .topbar-brand {
    margin-right: 0.5rem;
  }

  .topbar-title {
    display: none;
  }

  /* Hide desktop horizontal nav */
  .topbar-nav {
    display: none !important;
  }

  /* Show hamburger button */
  .mobile-menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: var(--muted-foreground);
    padding: 0.5rem;
    cursor: pointer;
    margin-right: 0.5rem;
    outline: none;
  }
  /* Lock icon size so the vendor `svg { max-width: 100% }` rule and flex
     shrinking can't collapse it on narrow viewports */
  .mobile-menu-toggle svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }
  .mobile-menu-toggle:hover {
    color: var(--primary);
  }

  /* Show mobile menu backdrop when open */
  .topbar.mobile-open ~ .mobile-menu-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  /* Mobile menu drawer styling */
  .topbar-nav-mobile-drawer {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    top: 52px;
    left: -260px; /* Hidden offscreen by default */
    width: 260px;
    height: calc(100vh - 52px);
    background: #0a0a0a;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem 0.5rem;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.25rem;
    z-index: 50;
    box-shadow: 10px 0 30px rgba(0,0,0,0.6);
    overflow-y: auto;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  [data-theme="light"] .topbar-nav-mobile-drawer {
    background: #ffffff;
    border-right-color: #e2e8f0;
    box-shadow: 10px 0 30px rgba(0,0,0,0.1);
  }

  .topbar.mobile-open ~ .topbar-nav-mobile-drawer {
    left: 0; /* Slide in */
  }

  .topbar-nav-mobile-drawer a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-small);
    font-size: 0.775rem;
    font-weight: 500;
    color: var(--sidebar-foreground);
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.15s ease;
  }

  .topbar-nav-mobile-drawer a:hover {
    background: var(--sidebar-accent);
    color: var(--sidebar-accent-foreground);
  }

  .topbar-nav-mobile-drawer a.active {
    background: var(--sidebar-accent);
    color: var(--sidebar-accent-foreground);
    font-weight: 600;
  }

  .topbar-nav-mobile-drawer a svg {
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    opacity: 0.6;
  }

  .topbar-nav-mobile-drawer a:hover svg,
  .topbar-nav-mobile-drawer a.active svg {
    opacity: 1;
  }
}

@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .page-header .actions {
    flex-wrap: wrap;
    width: 100%;
    gap: 0.5rem;
  }

  .page-header .actions button,
  .page-header .actions a {
    flex: 1 1 auto;
    margin-right: 0 !important;
    text-align: center;
    justify-content: center;
  }

  .page-header .actions a {
    display: inline-flex;
  }

  .page-header .actions a button {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .layout-200-1fr {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
  }

  .layout-1fr-2fr {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
  }

  /* Dual Pane sliding drawer defaults */
  .dual-pane-drawer-toggle {
    display: none !important;
  }

  .dual-pane-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 52px;
    background: rgba(0, 0, 0, 0.55);
    z-index: 43;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
  }
}

@media (max-width: 900px) {
  /* Hide sidebar by default on mobile/tablet and allow editing pane to occupy full width */
  .dual-pane-container {
    grid-template-columns: 1fr !important;
    position: relative;
    height: calc(100vh - 100px) !important;
  }

  .dual-pane-sidebar {
    position: fixed !important;
    top: 52px;
    left: -290px; /* Hidden offscreen */
    width: 280px;
    height: calc(100vh - 52px) !important;
    z-index: 45;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    background: var(--card) !important;
    max-height: none !important;
    border-radius: 0 !important;
  }

  [data-theme="light"] .dual-pane-sidebar {
    box-shadow: 10px 0 30px rgba(0,0,0,0.1);
  }

  /* Slide in sidebar when drawer is open */
  .dual-pane-container.drawer-open .dual-pane-sidebar {
    left: 0 !important;
  }

  /* Show backdrop when open */
  .dual-pane-container.drawer-open .dual-pane-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  /* Show floating toggle button — mobile only */
  .dual-pane-drawer-toggle {
    display: none !important;
  }
}

@media (max-width: 640px) {
  /* Show floating toggle button on phones */
  .dual-pane-drawer-toggle {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    left: 0;
    top: 45%;
    transform: translateY(-50%);
    background: var(--primary);
    color: var(--primary-foreground);
    border: 1px solid var(--primary);
    border-left: none;
    border-radius: 0 6px 6px 0;
    padding: 0.75rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    z-index: 44;
    box-shadow: 3px 0 12px rgba(0, 0, 0, 0.3);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.2s ease;
  }

  [data-theme="light"] .dual-pane-drawer-toggle {
    box-shadow: 3px 0 12px rgba(0, 0, 0, 0.1);
  }

  .dual-pane-drawer-toggle span {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    display: inline-block;
  }

  .dual-pane-drawer-toggle:hover {
    padding-left: 0.625rem;
  }

  /* When drawer is open, shift the toggle button along with the drawer's edge */
  .dual-pane-container.drawer-open .dual-pane-drawer-toggle {
    left: 280px;
    box-shadow: none;
    border-left: 1px solid var(--border);
  }
}

@media (max-width: 768px) {
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Login & Company-Selector Mode — Hide topbar when on body ── */
body[data-page="login"] .topbar,
body[data-page="company-selector"] .topbar {
  display: none !important;
}

body[data-page="login"] .main-content,
body[data-page="company-selector"] .main-content {
  margin-top: 0 !important;
}

/* ── Company Selector Card Layout ── */
.company-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.75rem;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .company-grid {
    grid-template-columns: 1fr;
    max-width: 420px;
    gap: 1.25rem;
  }
}

.company-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.company-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .company-card:hover {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.company-card .select-fy {
  height: 38px !important;
  line-height: 1.4 !important;
  font-size: 0.875rem !important;
  padding: 0.4rem 0.75rem !important;
  border-radius: var(--radius-base, 6px);
  border: 1px solid var(--border);
  background-color: var(--card);
  color: var(--foreground);
  box-sizing: border-box !important;
  cursor: pointer;
  display: block;
  width: 100%;
}

.company-card .select-fy:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--ring, rgba(76, 175, 80, 0.2));
}


/* ── Login Page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-base);
  padding: 2rem;
}

.login-card .logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.login-card .logo img {
  height: 3.5rem;
}

.login-card .logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.login-card .logo p {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

/* ── Action Buttons & Hover Color Contrast System ── */
:is(button, .btn, [type=submit], [type=button], [type=reset], a.button) {
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

/* 1. Primary Button (Default solid button, Save, New, Submit) */
button.primary,
[type=submit],
.btn.primary {
  background-color: var(--primary);
  color: var(--primary-foreground);
  border: 1px solid var(--primary);
}

button.primary:hover:not(:disabled),
[type=submit]:hover:not(:disabled),
.btn.primary:hover:not(:disabled) {
  background-color: #2f4722;
  color: #ffffff;
  border-color: #24371a;
}

.dark button.primary:hover:not(:disabled),
[data-theme="dark"] button.primary:hover:not(:disabled),
.dark [type=submit]:hover:not(:disabled),
[data-theme="dark"] [type=submit]:hover:not(:disabled),
.dark .btn.primary:hover:not(:disabled),
[data-theme="dark"] .btn.primary:hover:not(:disabled) {
  background-color: #7fa82b;
  color: #0d1109;
  border-color: #8fbd30;
}

/* 2. Secondary Button (Export, Print, Reset, Add Line, Spec/Tax tabs) */
button.secondary,
.btn.secondary {
  background-color: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--secondary);
}

button.secondary:hover:not(:disabled),
.btn.secondary:hover:not(:disabled) {
  background-color: #546348;
  color: #ffffff;
  border-color: #48553d;
}

.dark button.secondary:hover:not(:disabled),
[data-theme="dark"] button.secondary:hover:not(:disabled),
.dark .btn.secondary:hover:not(:disabled),
[data-theme="dark"] .btn.secondary:hover:not(:disabled) {
  background-color: #59654f;
  color: #ffffff;
  border-color: #6b7a60;
}

/* 3. Danger Button (Delete, Remove row) */
button.danger,
.btn.danger {
  background-color: var(--danger);
  color: var(--danger-foreground);
  border: 1px solid var(--danger);
}

button.danger:hover:not(:disabled),
.btn.danger:hover:not(:disabled) {
  background-color: #80291d;
  color: #ffffff;
  border-color: #6c2116;
}

.dark button.danger:hover:not(:disabled),
[data-theme="dark"] button.danger:hover:not(:disabled),
.dark .btn.danger:hover:not(:disabled),
[data-theme="dark"] .btn.danger:hover:not(:disabled) {
  background-color: #b33c2f;
  color: #ffffff;
  border-color: #993226;
}

/* 4. Default / Generic Buttons (no explicit variant) */
:is(button, .btn, [type=button]):not(.primary):not(.secondary):not(.danger):not(.outline):not(.ghost):not(.theme-toggle):not(.mobile-menu-toggle):not(.dual-pane-drawer-toggle):not(.pill-btn):not(.filter-pill):not([class*="mkt-"]) {
  background-color: var(--primary);
  color: var(--primary-foreground);
  border: 1px solid var(--primary);
}

:is(button, .btn, [type=button]):not(.primary):not(.secondary):not(.danger):not(.outline):not(.ghost):not(.theme-toggle):not(.mobile-menu-toggle):not(.dual-pane-drawer-toggle):not(.pill-btn):not(.filter-pill):not([class*="mkt-"]):hover:not(:disabled) {
  background-color: #2f4722;
  color: #ffffff;
  border-color: #24371a;
}

.dark :is(button, .btn, [type=button]):not(.primary):not(.secondary):not(.danger):not(.outline):not(.ghost):not(.theme-toggle):not(.mobile-menu-toggle):not(.dual-pane-drawer-toggle):not(.pill-btn):not(.filter-pill):not([class*="mkt-"]):hover:not(:disabled),
[data-theme="dark"] :is(button, .btn, [type=button]):not(.primary):not(.secondary):not(.danger):not(.outline):not(.ghost):not(.theme-toggle):not(.mobile-menu-toggle):not(.dual-pane-drawer-toggle):not(.pill-btn):not(.filter-pill):not([class*="mkt-"]):hover:not(:disabled) {
  background-color: #7fa82b;
  color: #0d1109;
  border-color: #8fbd30;
}

/* 5. Outline & Ghost Buttons */
button.outline,
.btn.outline,
button.ghost,
.btn.ghost {
  background-color: transparent;
  color: var(--foreground);
  border: 1px solid var(--border);
}

button.outline:hover:not(:disabled),
.btn.outline:hover:not(:disabled),
button.ghost:hover:not(:disabled),
.btn.ghost:hover:not(:disabled) {
  background-color: var(--accent);
  color: var(--accent-foreground);
  border-color: var(--primary);
}

/* 6. Pagination Controls Buttons */
.pagination-controls button,
.pagination-controls button.small {
  background-color: var(--card) !important;
  color: var(--foreground) !important;
  border: 1px solid var(--border) !important;
}

.pagination-controls button:hover:not(:disabled),
.pagination-controls button.small:hover:not(:disabled) {
  background-color: var(--accent) !important;
  color: var(--accent-foreground) !important;
  border-color: var(--primary) !important;
}

.pagination-controls button:disabled,
.pagination-controls button.small:disabled {
  background-color: var(--muted) !important;
  color: var(--muted-foreground) !important;
  border-color: var(--border) !important;
  opacity: 0.5 !important;
  cursor: not-allowed !important;
}

/* 7. Focus & Active States */
:is(button, .btn, [type=button], [type=submit], [type=reset]):focus-visible {
  outline: 2px solid var(--ring) !important;
  outline-offset: 1px !important;
}

:is(button, .btn, [type=button], [type=submit], [type=reset]):active:not(:disabled) {
  transform: translateY(1px);
}

:is(button, .btn, [type=button], [type=submit], [type=reset]):disabled,
:is(button, .btn, [type=button], [type=submit], [type=reset])[disabled] {
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
  box-shadow: none !important;
}

/* ── Inline button spinner ── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Warmup loading overlay (post-login) ── */
.warmup-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--background);
  z-index: 9999;
}
.warmup-overlay img {
  height: 4rem;
  margin-bottom: 1.25rem;
}
.warmup-overlay-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--foreground);
  margin-bottom: 0.375rem;
}
.warmup-overlay-sub {
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  margin-bottom: 2rem;
}
.warmup-overlay-track {
  width: 220px;
  height: 3px;
  background: var(--muted);
  border-radius: 2px;
  overflow: hidden;
}
.warmup-overlay-bar {
  height: 100%;
  width: 40%;
  background: var(--primary);
  border-radius: 2px;
  animation: warmup-slide 1.4s ease-in-out infinite;
}
@keyframes warmup-slide {
  0%   { transform: translateX(-150%); }
  100% { transform: translateX(400%); }
}

.form-group {
  position: relative;
}

/* ── Pills Styling (Compact) ── */
.pills-container {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}

.pill-btn {
  border-radius: var(--radius-small) !important;
  border: 1px solid var(--border) !important;
  padding: 0.2rem 0.5rem !important;
  font-size: 0.725rem !important;
  font-weight: 600 !important;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--card) !important;
  color: var(--muted-foreground) !important;
  height: 22px !important;
  display: inline-flex !important;
  align-items: center !important;
}

.pill-btn:hover {
  background: var(--accent) !important;
  color: var(--accent-foreground) !important;
}

.pill-btn.active {
  background: var(--primary) !important;
  color: var(--primary-foreground) !important;
  border-color: var(--primary) !important;
}

/* ── Filter Pills Styling (Compact) ── */
.filter-pills {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}

.filter-pill {
  border-radius: var(--radius-small) !important;
  border: 1px solid var(--border) !important;
  padding: 0.15rem 0.45rem !important;
  font-size: 0.7rem !important;
  font-weight: 600 !important;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--card) !important;
  color: var(--muted-foreground) !important;
  height: 20px !important;
  display: inline-flex !important;
  align-items: center !important;
}

.filter-pill:hover {
  background: var(--accent) !important;
  color: var(--accent-foreground) !important;
}

.filter-pill.active {
  background: var(--primary) !important;
  color: var(--primary-foreground) !important;
  border-color: var(--primary) !important;
}

/* ── Dual Pane Layout System (Compact) ── */
.dual-pane-container {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 0.5rem;
  height: calc(100vh - var(--topbar-height) - 0.75rem);
  align-items: stretch;
}

/* Hidden by default everywhere; shown only on phones via @media (max-width: 640px) */
.dual-pane-drawer-toggle {
  display: none !important;
}

.alter-list-item {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.alter-list-item:hover {
  background: var(--accent);
}

.alter-list-item.active-item, .active-item {
  background: color-mix(in srgb, var(--primary) 12%, transparent) !important;
  border-left: 3px solid var(--primary) !important;
}

.alter-list-item .title {
  font-size: 0.8125rem;
  font-weight: 600;
}

.alter-list-item.active-item .title {
  color: var(--primary);
}

.alter-list-item .subtitle {
  font-size: 0.6875rem;
  color: var(--muted-foreground);
  margin-top: 0.125rem;
}

/* ── Print Styles (Item 11) ── */
@media print {
  .topbar, .topbar-nav, #logout-btn, #theme-toggle, button, .btn, .form-actions, a[data-route] button, .page-header .actions, #btn-proceed, #export-contracts-btn, #export-bills-btn, #export-payments-btn, #export-ledger-btn, .pagination-controls, input[id^="search-"] {
    display: none !important;
  }
  main, #app, body, .main-container {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-shadow: none !important;
  }
  table {
    border-collapse: collapse !important;
    width: 100% !important;
  }
  th, td {
    border: 1px solid #dddddd !important;
    padding: 6px 8px !important;
    color: #000000 !important;
    background: transparent !important;
  }
  tr {
    page-break-inside: avoid !important;
  }
}

/* ── Vercel Geist–style Tooltips ── */
.topbar [data-tooltip]::before,
.topbar [data-tooltip]:before {
  content: "" !important;
  position: absolute !important;
  top: calc(100% + 8px) !important;
  bottom: auto !important;
  left: 50% !important;
  transform: translateX(-50%) translateY(3px) !important;
  border-width: 0 4px 4px 4px !important;
  border-style: solid !important;
  border-color: transparent transparent #111111 transparent !important;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  transition-delay: 0s;
  z-index: 1001;
}

.topbar [data-tooltip]::after,
.topbar [data-tooltip]:after {
  content: attr(data-tooltip) !important;
  position: absolute !important;
  top: calc(100% + 12px) !important;
  bottom: auto !important;
  left: 50% !important;
  transform: translateX(-50%) translateY(3px) !important;
  background: #111111 !important;
  color: #ededed !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  padding: 5px 8px !important;
  font-size: 0.6875rem !important;
  font-weight: 500 !important;
  line-height: 1.25 !important;
  letter-spacing: 0.01em !important;
  white-space: nowrap !important;
  border-radius: 6px !important;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04) !important;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  transition-delay: 0s;
  z-index: 1001;
}

[data-theme="light"] .topbar [data-tooltip]::before,
[data-theme="light"] .topbar [data-tooltip]:before {
  border-color: transparent transparent #0a0a0a transparent !important;
}

[data-theme="light"] .topbar [data-tooltip]::after,
[data-theme="light"] .topbar [data-tooltip]:after {
  background: #0a0a0a !important;
  color: #fafafa !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.04) !important;
}

.topbar [data-tooltip]:is(:hover, :focus-visible)::before,
.topbar [data-tooltip]:is(:hover, :focus-visible):before,
.topbar [data-tooltip]:is(:hover, :focus-visible)::after,
.topbar [data-tooltip]:is(:hover, :focus-visible):after {
  opacity: 1 !important;
  transform: translateX(-50%) translateY(0) !important;
  transition-delay: 0.15s !important;
}

/* Left-aligned tooltip for hamburger icon (far left edge) */
.topbar .mobile-menu-toggle[data-tooltip]::before,
.topbar .mobile-menu-toggle[data-tooltip]:before {
  left: 14px !important;
  right: auto !important;
  transform: translateY(3px) !important;
}

.topbar .mobile-menu-toggle[data-tooltip]::after,
.topbar .mobile-menu-toggle[data-tooltip]:after {
  left: 0 !important;
  right: auto !important;
  transform: translateY(3px) !important;
}

.topbar .mobile-menu-toggle[data-tooltip]:is(:hover, :focus-visible)::before,
.topbar .mobile-menu-toggle[data-tooltip]:is(:hover, :focus-visible):before,
.topbar .mobile-menu-toggle[data-tooltip]:is(:hover, :focus-visible)::after,
.topbar .mobile-menu-toggle[data-tooltip]:is(:hover, :focus-visible):after {
  transform: translateY(0) !important;
}

/* Right-aligned tooltip for logout button (far right edge) */
.topbar .topbar-logout[data-tooltip]::before,
.topbar .topbar-logout[data-tooltip]:before {
  left: auto !important;
  right: 14px !important;
  transform: translateY(3px) !important;
}

.topbar .topbar-logout[data-tooltip]::after,
.topbar .topbar-logout[data-tooltip]:after {
  left: auto !important;
  right: 0 !important;
  transform: translateY(3px) !important;
}

.topbar .topbar-logout[data-tooltip]:is(:hover, :focus-visible)::before,
.topbar .topbar-logout[data-tooltip]:is(:hover, :focus-visible):before,
.topbar .topbar-logout[data-tooltip]:is(:hover, :focus-visible)::after,
.topbar .topbar-logout[data-tooltip]:is(:hover, :focus-visible):after {
  transform: translateY(0) !important;
}

/* ── Custom Premium Scrollbars ── */
::-webkit-scrollbar {
  width: 5px !important;  /* Thin vertical scrollbar */
  height: 5px !important; /* Thin horizontal scrollbar */
}

::-webkit-scrollbar-track {
  background: transparent !important; /* Hide track bar completely */
}

::-webkit-scrollbar-thumb {
  background: rgba(156, 163, 175, 0.25) !important; /* Semi-transparent thumb */
  border-radius: 10px !important;
  border: none !important;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(156, 163, 175, 0.45) !important; /* Darker thumb on hover */
}

/* Firefox compatibility */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.25) transparent;
}

/* ── Dropdown Tab Header ── */
.nav-dropdown {
  position: relative;
  display: inline-block;
}

.nav-dropdown-trigger {
  display: flex !important;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.45rem;
  font-size: 0.725rem;
  font-weight: 500;
  color: var(--sidebar-foreground);
  opacity: 0.85;
  text-decoration: none;
  border-radius: var(--radius-small);
  transition: background-color 0.15s, color 0.15s, opacity 0.15s;
  cursor: pointer;
  background: none;
  border: none;
}

.nav-dropdown-trigger:hover,
.nav-dropdown-trigger.active {
  background-color: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
  opacity: 1;
}

.nav-dropdown-content {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  top: 100%;
  left: 0;
  background-color: var(--card);
  min-width: 150px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  z-index: 1000;
  margin-top: 0.25rem;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  transition-delay: 0.2s; /* stay open while mouse travels to it */
}

/* transparent bridge covers the gap so hover isn't lost mid-travel */
.nav-dropdown::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 0.4rem;
  pointer-events: auto;
}

.nav-dropdown:hover .nav-dropdown-content {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition-delay: 0s;
}

.nav-dropdown-content a {
  color: var(--foreground) !important;
  padding: 0.35rem 0.6rem !important;
  text-decoration: none;
  display: flex !important;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 0 !important;
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s, color 0.15s;
}

.nav-dropdown-content a:last-child {
  border-bottom: none;
}

.nav-dropdown-content a:hover,
.nav-dropdown-content a.active {
  background-color: var(--accent) !important;
  color: var(--accent-foreground) !important;
}

/* ==========================================================================
 * SINGLE-VIEWPORT COMPACT "PAPER FORM" LAYOUT UTILITIES
 * ========================================================================== */

/* ==========================================================================
 * SINGLE-VIEWPORT COMPACT "PAPER FORM" LAYOUT UTILITIES
 * ========================================================================== */

/* Eliminate main-content padding when single-viewport or dual-pane container is active.
   Pin to viewport bounds below topbar and maintain an unbroken flex-column chain
   through #fy-lock-banner and #app so .paper-form-footer is NEVER pushed or clipped. */
.main-content:has(.single-viewport-container),
.main-content:has(.dual-pane-container) {
  position: fixed !important;
  top: var(--topbar-height) !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  margin-top: 0 !important;
  height: auto !important;
  max-height: none !important;
  min-height: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  display: flex !important;
  flex-direction: column !important;
}

/* The lock banner sits at natural height inside that flex column */
.main-content:has(.single-viewport-container) > .fy-lock-banner,
.main-content:has(.dual-pane-container) > .fy-lock-banner {
  flex-shrink: 0;
}

/* #app must be a shrinking flex column so single-viewport/dual-pane children inherit remaining height */
.main-content:has(.single-viewport-container) > #app,
.main-content:has(.dual-pane-container) > #app {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

.main-content:has(.dual-pane-container) > #app {
  padding: 0.25rem 0.5rem;
}

.main-content:has(.dual-pane-container) > #app > a[data-route] {
  flex-shrink: 0;
}

.main-content:has(.dual-pane-container) .dual-pane-container {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  height: auto !important;
}

.main-content:has(.dual-pane-container) .dual-pane-container > .table-container {
  min-height: 0 !important;
}

/* Single-viewport container takes all remaining space inside #app */
.single-viewport-container {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  padding: 0.25rem 0.4rem;
  box-sizing: border-box;
}

.single-viewport-container > :first-child {
  flex-shrink: 0;
}

/* Split pane flex container */
.split-pane-wrapper {
  display: flex;
  gap: 0.35rem;
  flex: 1 1 0;
  min-height: 0; /* allows flex scrolling inside children */
  overflow: hidden;
}

/* Left list pane */
.split-pane-list {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  overflow: hidden;
}

.split-pane-list-header {
  flex-shrink: 0;
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
}

.split-pane-list-body {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}

.split-pane-list-item {
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.split-pane-list-item:hover,
.split-pane-list-item.selected {
  background: var(--accent);
  border-left: 3px solid var(--primary);
}

/* Right paper form pane */
.split-pane-form {
  flex: 1 1 0;
  min-height: 0;       /* crucial: lets flexbox shrink below content size */
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  overflow: hidden;
}

.paper-form-header {
  flex-shrink: 0;
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.paper-form-body {
  flex: 1 1 0;
  min-height: 0;       /* allows inner scroll without pushing footer off-screen */
  padding: 0.25rem 0.4rem !important;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem !important;
}

.paper-form-footer {
  flex-shrink: 0;      /* footer never collapses — always visible */
  padding: 0.3rem 0.5rem;
  border-top: 1px solid var(--border);
  background: var(--muted);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.3rem;
}

/* Dense Multi-Column Grids */
.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.15rem 0.35rem !important;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.15rem 0.35rem !important;
}

.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.15rem 0.35rem !important;
}

.form-grid-6 {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.15rem 0.35rem !important;
}

/* Dense Form Controls (Optimized for Low-Resolution 1366x768 & 1280x800 Displays) */
.compact-group {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.compact-label {
  font-size: 0.65rem !important;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted-foreground);
  line-height: 1;
  margin-bottom: 0.05rem;
}

.compact-input,
.compact-select {
  height: 24px !important;
  padding: 0.1rem 0.35rem !important;
  font-size: 0.75rem !important;
  border-radius: var(--radius-small) !important;
  border: 1px solid var(--input) !important;
  background: var(--card) !important;
  color: var(--foreground) !important;
  width: 100%;
  box-sizing: border-box;
}

.compact-input:focus,
.compact-select:focus {
  border-color: var(--ring) !important;
  outline: none !important;
  box-shadow: 0 0 0 1px var(--ring) !important;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .split-pane-wrapper {
    flex-direction: column;
  }
  .split-pane-list {
    width: 100%;
    max-height: 200px;
  }
  .form-grid-4, .form-grid-6 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Contracts Table Summary Lilac Boxes */
.summary-lilac-box {
  background: #eeddfa;
  border: 1px solid #c084fc;
  color: #3b0764;
  font-weight: 700;
  border-radius: 3px;
  padding: 2px 6px;
  text-align: right;
  font-size: 0.75rem;
  min-height: 22px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .summary-lilac-box {
  background: #3b1d54;
  border-color: #a855f7;
  color: #f5d0fe;
}

/* Role-based UI Restrictions (EMPLOYEE = Data Entry Only) */
body[data-role="EMPLOYEE"] .delete-row-btn,
body[data-role="EMPLOYEE"] [id^="btn-delete"],
body[data-role="EMPLOYEE"] [id^="btn-export"],
body[data-role="EMPLOYEE"] .btn-batch-billing-link {
  display: none !important;
}

/* Topbar In-Department Firm Switcher + Cycle Button */
.topbar-switchers {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-right: 0.5rem;
}

.topbar-switchers select {
  height: 28px;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  border-radius: var(--radius-base);
  max-width: 195px;
}

.btn-cycle-firm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  width: 28px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  border-radius: var(--radius-base);
  cursor: pointer;
}

.btn-cycle-firm:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.fy-lock-banner {
  display: none;
  background: rgba(217, 119, 6, 0.14);
  border-bottom: 1px solid rgba(217, 119, 6, 0.4);
  color: #b45309;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  padding: 0.25rem 0.75rem;
}

[data-theme="dark"] .fy-lock-banner {
  color: #fbbf24;
}

body[data-fy-locked="true"] .fy-lock-banner {
  display: block;
}
