/* =============================================
   ClearView Business Management - Design System
   ============================================= */

:root {
  /* Color Palette - Sophisticated Professional */
  --primary: #1a4d2e;
  --primary-light: #2d6a47;
  --primary-dark: #0f2918;
  --accent: #d4a574;
  --accent-light: #e8c9a1;
  --accent-dark: #b8884f;
  
  --surface: #fafaf9;
  --surface-elevated: #ffffff;
  --surface-hover: #f5f5f4;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  
  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-tertiary: #78716c;
  --text-on-primary: #ffffff;
  
  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #d97706;
  --warning-bg: #fed7aa;
  --danger: #dc2626;
  --danger-bg: #fecaca;
  --info: #0284c7;
  --info-bg: #bae6fd;
  
  /* Typography */
  --font-display: 'Crimson Pro', 'Georgia', serif;
  --font-body: 'Work Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  
  /* Spacing Scale */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
  
  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  
  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Layout */
  --sidebar-width: 280px;
  --header-height: 64px;
  --max-content-width: 1400px;
}

/* =============================================
   Base Styles & Reset
   ============================================= */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--surface);
  min-height: 100vh;
}

/* =============================================
   Typography
   ============================================= */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
}

h1 {
  font-size: 2.5rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 2rem;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.5rem;
}

h4 {
  font-size: 1.25rem;
}

h5 {
  font-size: 1.125rem;
}

h6 {
  font-size: 1rem;
}

p {
  margin-bottom: var(--space-md);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary-light);
  text-decoration: underline;
}

/* =============================================
   Layout Structure
   ============================================= */

.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
  width: var(--sidebar-width);
  background: var(--primary-dark);
  color: var(--text-on-primary);
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition-base);
}

.sidebar-header {
  padding: var(--space-xl) var(--space-lg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-on-primary);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.sidebar-logo::before {
  content: '';
  width: 8px;
  height: 32px;
  background: linear-gradient(180deg, var(--accent), var(--accent-light));
  border-radius: var(--radius-sm);
}

.sidebar-nav {
  padding: var(--space-lg) 0;
}

.nav-section {
  margin-bottom: var(--space-lg);
}

.nav-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.5);
  padding: 0 var(--space-lg);
  margin-bottom: var(--space-sm);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: all var(--transition-fast);
  position: relative;
  font-weight: 500;
}

.nav-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--accent);
  transition: height var(--transition-fast);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-on-primary);
  text-decoration: none;
}

.nav-link:hover::before {
  height: 70%;
}

.nav-link.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-on-primary);
}

.nav-link.active::before {
  height: 70%;
}

.nav-icon {
  width: 20px;
  height: 20px;
  opacity: 0.8;
}

.nav-link:hover .nav-icon,
.nav-link.active .nav-icon {
  opacity: 1;
}

/* Main Content Area */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top Header Bar */
.top-header {
  height: var(--header-height);
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-2xl);
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.header-search {
  flex: 1;
  max-width: 500px;
}

.search-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  padding-left: var(--space-2xl);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  background: var(--surface);
  transition: all var(--transition-fast);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2378716c'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 18px;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  background-color: var(--surface-elevated);
  box-shadow: 0 0 0 3px rgba(26, 77, 46, 0.1);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.user-menu:hover {
  background: var(--surface-hover);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-primary);
  font-weight: 600;
  font-size: 0.875rem;
}

/* Content Container */
.content {
  flex: 1;
  padding: var(--space-2xl);
  max-width: var(--max-content-width);
  width: 100%;
  margin: 0 auto;
}

/* Page Header */
.page-header {
  margin-bottom: var(--space-2xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-lg);
}

.page-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-top: var(--space-xs);
  font-family: var(--font-body);
  font-weight: 400;
}

.page-actions {
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

/* =============================================
   Dashboard Components
   ============================================= */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-2xl);
}

.stat-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  position: relative;
  overflow: hidden;
  transition: all var(--transition-base);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition-base);
}

.stat-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.stat-card:hover::before {
  transform: scaleX(1);
}

.stat-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--space-sm);
}

.stat-change {
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.stat-change.positive {
  color: var(--success);
}

.stat-change.negative {
  color: var(--danger);
}

/* =============================================
   Cards & Containers
   ============================================= */

.card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 1.25rem;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body {
  padding: 0;
}

.card-footer {
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* =============================================
   Tables
   ============================================= */

.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
}

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

thead {
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

th {
  padding: var(--space-md) var(--space-lg);
  text-align: left;
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

th:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

th.sortable::after {
  content: '⇅';
  margin-left: var(--space-sm);
  opacity: 0.3;
  font-size: 0.75rem;
}

th.sorted-asc::after {
  content: '↑';
  opacity: 1;
  color: var(--primary);
}

th.sorted-desc::after {
  content: '↓';
  opacity: 1;
  color: var(--primary);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}

tbody tr:hover {
  background: var(--surface-hover);
}

tbody tr:last-child {
  border-bottom: none;
}

td {
  padding: var(--space-lg);
  color: var(--text-primary);
  font-size: 0.9375rem;
}

td.numeric {
  font-family: var(--font-mono);
  text-align: right;
  font-size: 0.875rem;
}

td.status {
  font-weight: 500;
}

/* =============================================
   Buttons
   ============================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.5;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--text-on-primary);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-light);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-accent {
  background: var(--accent);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-on-primary);
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.btn-sm {
  padding: var(--space-xs) var(--space-md);
  font-size: 0.8125rem;
}

.btn-lg {
  padding: var(--space-md) var(--space-xl);
  font-size: 1rem;
}

.btn-icon {
  padding: var(--space-sm);
  width: 36px;
  height: 36px;
}

/* =============================================
   Forms
   ============================================= */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.form-group {
  margin-bottom: var(--space-lg);
}

.form-group-full {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

label.required::after {
  content: '*';
  color: var(--danger);
  margin-left: var(--space-xs);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="url"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: var(--space-md);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--text-primary);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 77, 46, 0.1);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.input-group {
  display: flex;
  gap: var(--space-sm);
}

.input-prefix,
.input-suffix {
  display: flex;
  align-items: center;
  padding: var(--space-md);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.875rem;
  white-space: nowrap;
}

.input-prefix {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  border-right: none;
}

.input-suffix {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  border-left: none;
}

.input-group input {
  border-radius: 0;
}

.input-group input:first-child {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.input-group input:last-child {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.form-help {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
}

.form-error {
  font-size: 0.8125rem;
  color: var(--danger);
  margin-top: var(--space-xs);
}

/* Checkbox and Radio */
.checkbox-group,
.radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.checkbox-label,
.radio-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-weight: 400;
}

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* =============================================
   Badges & Status Indicators
   ============================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-info {
  background: var(--info-bg);
  color: var(--info);
}

.badge-neutral {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.success {
  background: var(--success);
}

.status-dot.warning {
  background: var(--warning);
}

.status-dot.danger {
  background: var(--danger);
}

.status-dot.info {
  background: var(--info);
}

/* =============================================
   Filters & Toolbar
   ============================================= */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
  padding: var(--space-lg);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.filter-group label {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.filter-group select {
  min-width: 150px;
}

/* =============================================
   Empty States
   ============================================= */

.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--text-secondary);
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto var(--space-lg);
  opacity: 0.3;
}

.empty-state h3 {
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.empty-state p {
  font-size: 0.9375rem;
  margin-bottom: var(--space-xl);
}

/* =============================================
   Alerts & Messages
   ============================================= */

.alert {
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  border-left: 4px solid;
  margin-bottom: var(--space-lg);
  display: flex;
  gap: var(--space-md);
}

.alert-success {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}

.alert-warning {
  background: var(--warning-bg);
  border-color: var(--warning);
  color: var(--warning);
}

.alert-danger {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.alert-info {
  background: var(--info-bg);
  border-color: var(--info);
  color: var(--info);
}

/* =============================================
   Loading States
   ============================================= */

.loading-spinner {
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 0.8s linear infinite;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* =============================================
   Mobile Menu Toggle
   ============================================= */

.mobile-menu-toggle {
  display: none;
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  width: 56px;
  height: 56px;
  background: var(--primary);
  color: var(--text-on-primary);
  border: none;
  border-radius: 50%;
  box-shadow: var(--shadow-xl);
  cursor: pointer;
  z-index: 1000;
  transition: all var(--transition-base);
}

.mobile-menu-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-xl), 0 0 0 8px rgba(26, 77, 46, 0.1);
}

/* =============================================
   Responsive Design
   ============================================= */

@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }
  
  .content {
    padding: var(--space-xl);
  }
  
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .top-header {
    padding: 0 var(--space-lg);
  }
  
  .header-search {
    display: none;
  }
  
  .content {
    padding: var(--space-lg);
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .toolbar-left,
  .toolbar-right {
    width: 100%;
    justify-content: space-between;
  }
  
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    min-width: 600px;
  }
  
  h1 {
    font-size: 1.875rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  :root {
    --space-2xl: 2rem;
    --space-3xl: 2.5rem;
  }
  
  .content {
    padding: var(--space-md);
  }
  
  .card {
    padding: var(--space-lg);
  }
  
  .btn {
    width: 100%;
    justify-content: center;
  }
  
  .page-actions {
    width: 100%;
  }
  
  .page-actions .btn {
    flex: 1;
  }
}

/* =============================================
   Print Styles
   ============================================= */

@media print {
  .sidebar,
  .top-header,
  .mobile-menu-toggle,
  .page-actions,
  .toolbar,
  .btn {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .content {
    max-width: none;
    padding: 0;
  }
  
  .card {
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* =============================================
   Utility Classes
   ============================================= */

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }

.mt-0 { margin-top: 0; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }

.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

.hidden { display: none; }

@media (max-width: 768px) {
  .hide-mobile { display: none; }
}

@media (min-width: 769px) {
  .show-mobile { display: none; }
}
/* =============================================
   ClearView v4 Compatibility Bridge
   Maps v4 template variables to V2.2 design system
   ============================================= */

:root {
  --bg:           var(--surface);
  --bg-surface:   var(--surface-elevated);
  --bg-card:      var(--surface-elevated);
  --bg-elevated:  var(--surface-hover);
  --border-light: var(--border-strong);
  --text:         var(--text-primary);
  --text-tertiary: var(--text-tertiary);
  --accent-light: var(--primary-light);
  --accent-dim:   rgba(26,77,46,0.08);
  --success-dim:  var(--success-bg);
  --warning-dim:  var(--warning-bg);
  --danger-dim:   var(--danger-bg);
  --info-dim:     var(--info-bg);
  --radius:       var(--radius-lg);
  --radius-sm:    var(--radius-md);
  --shadow:       var(--shadow-md);
  --shadow-lg:    var(--shadow-lg);
  --sidebar-w:    var(--sidebar-width);
  --header-h:     var(--header-height);
  --font-display: 'Crimson Pro', Georgia, serif;
  --font-body:    'Work Sans', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
}

/* Content padding */
.content {
  padding: var(--space-xl);
  flex: 1;
}

/* Stat cards */
.stat-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: 6px;
}

.stat-change { font-size: 0.8rem; color: var(--text-secondary); }
.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

/* Cards */
.card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0;
}

.card-body { padding: var(--space-lg); }

.card-footer {
  padding: var(--space-sm) var(--space-lg);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

thead th {
  background: var(--surface);
  padding: 11px 14px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

thead th:hover { color: var(--text-secondary); }
thead th.sorted-asc::after { content: ' ↑'; color: var(--primary); }
thead th.sorted-desc::after { content: ' ↓'; color: var(--primary); }

tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition-fast); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-hover); }
tbody td { padding: 11px 14px; color: var(--text-primary); vertical-align: middle; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  height: 38px;
}

.btn-primary { background: var(--primary); color: var(--text-on-primary); }
.btn-primary:hover { background: var(--primary-light); color: var(--text-on-primary); text-decoration: none; }

.btn-secondary { background: var(--surface-hover); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-strong); color: var(--text-primary); text-decoration: none; }

.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; text-decoration: none; }

.btn-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.btn-success:hover { background: var(--success); color: #fff; text-decoration: none; }

.btn-sm { height: 30px; padding: 5px 11px; font-size: 0.8rem; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-info    { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--surface-hover); color: var(--text-secondary); border: 1px solid var(--border); }
.badge-accent  { background: rgba(212,165,116,0.15); color: var(--accent-dark); }

/* Forms */
.form-group { margin-bottom: 18px; }

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
  width: 100%;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  transition: all var(--transition-fast);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,77,46,0.1);
}

input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
select option { background: var(--surface-elevated); color: var(--text-primary); }

.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Alerts */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 0.875rem;
  border-left: 3px solid;
}

.alert-info    { background: var(--info-bg); border-color: var(--info); color: var(--info); }
.alert-success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.alert-danger  { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

/* Collection queue */
.collection-queue { display: flex; flex-direction: column; gap: 10px; }

.collection-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: box-shadow var(--transition-fast);
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.collection-item:hover { box-shadow: var(--shadow-md); }
.collection-item.critical { border-left: 3px solid var(--danger); }
.collection-item.high     { border-left: 3px solid #f97316; }
.collection-item.medium   { border-left: 3px solid var(--warning); }
.collection-item.low      { border-left: 3px solid var(--success); }

.collection-item-info { flex: 1; min-width: 0; }
.collection-client { font-weight: 600; font-size: 0.9rem; color: var(--text-primary); }
.collection-meta { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.collection-amount { font-family: var(--font-mono); font-size: 0.9rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.collection-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* Pipeline */
.pipeline-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: var(--space-lg);
}

.pipeline-stage {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  text-align: center;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.pipeline-stage::after {
  content: '→';
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
}

.pipeline-stage:last-child::after { display: none; }
.pipeline-stage-name { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); margin-bottom: 8px; }
.pipeline-stage-count { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

/* Command grid */
.command-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: var(--space-lg); }

.command-panel {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.command-panel-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
}

.command-panel-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-xl);
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 0;
}

.page-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; margin-bottom: 0; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: var(--space-lg);
}

/* Utility */
.font-mono    { font-family: var(--font-mono); }
.font-serif   { font-family: var(--font-display); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary  { color: var(--text-tertiary); }
.font-semibold  { font-weight: 600; }
.font-bold      { font-weight: 700; }
.text-sm  { font-size: 0.875rem; }
.text-xs  { font-size: 0.78rem; }
.mt-4  { margin-top: 16px; }
.mb-1  { margin-bottom: 4px; }
.mb-4  { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex  { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.items-center { align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

.section-divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.3; }
.empty-state-text { font-size: 0.9rem; }

.hidden { display: none !important; }

/* Mobile */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 200;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 48px; height: 48px;
  align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .mobile-menu-toggle { display: flex; }
  .command-grid { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .pipeline-row { grid-template-columns: repeat(2, 1fr); }
  .hide-mobile { display: none; }
  .content { padding: var(--space-md); }
}

/* ============================================================
   AR INTELLIGENCE LAYER — bento profiles, risk badges, charts,
   mapping UI. Ported from the AR Command Centre merge; all
   colors resolve through the variables above so they inherit
   the warm light theme automatically.
   ============================================================ */

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  transition: all var(--transition-base);
}
.chart-container:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.chart-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}
.charts-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

/* These three collapse to a single column on phones — placed after their
   base definitions above so the cascade actually picks this up (an
   earlier @media block with the same selector would otherwise lose to
   these later unconditional rules regardless of viewport width). */
@media (max-width: 768px) {
  .grid-2,
  .charts-row,
  .charts-row-3 {
    grid-template-columns: 1fr;
  }
}

.command-panel-body { padding: 16px 18px; }

/* Bento client profile grid */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.bento-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.bento-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}
.bento-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.bento-card:hover::before { opacity: 1; }

.bento-card.risk-high::before { background: var(--danger); opacity: 1; }
.bento-card.risk-medium::before { background: var(--warning); opacity: 1; }
.bento-card.risk-low::before { background: var(--success); opacity: 1; }

.bento-client-name {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.bento-client-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-bottom: 14px;
}
.bento-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.bento-metric-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 2px;
}
.bento-metric-value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}
.bento-metric-value.danger { color: var(--danger); }
.bento-metric-value.warning { color: var(--warning); }
.bento-metric-value.success { color: var(--success); }

/* Job messages — chat thread */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  max-height: 440px;
  overflow-y: auto;
}
.chat-row {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}
.chat-row.own { align-self: flex-end; align-items: flex-end; }
.chat-row.other { align-self: flex-start; align-items: flex-start; }
.chat-meta {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin: 0 4px 3px;
}
.chat-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 0.85rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-row.own .chat-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-row.other .chat-bubble {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-row.other.role-admin .chat-bubble {
  background: rgba(212, 165, 116, 0.14);
  border-color: var(--accent);
}
.chat-empty {
  padding: 28px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.85rem;
}

.bento-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Risk badge */
.risk-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.risk-badge.critical { background: var(--danger-dim); color: var(--danger); border: 1px solid var(--danger); }
.risk-badge.high     { background: var(--warning-dim); color: #c2410c; border: 1px solid #f97316; }
.risk-badge.medium   { background: var(--warning-dim); color: var(--warning); border: 1px solid var(--warning); }
.risk-badge.low      { background: var(--success-dim); color: var(--success); border: 1px solid var(--success); }

.pipeline-stage-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

/* Import ledger mapping UI */
.mapping-table { width: 100%; border-collapse: collapse; }
.mapping-table td { padding: 10px 12px; vertical-align: middle; border-bottom: 1px solid var(--border); }
.mapping-confidence {
  display: flex;
  align-items: center;
  gap: 8px;
}
.confidence-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}
.confidence-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--success);
  transition: width 0.3s;
}
.confidence-fill.medium { background: var(--warning); }
.confidence-fill.low    { background: var(--danger); }
.confidence-pct {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  width: 36px;
  text-align: right;
}

/* Printable invoice preview wrapper */
.invoice-preview {
  background: #fff;
  color: #1c1917;
  border-radius: var(--radius);
  padding: 48px;
  max-width: 740px;
}
