/* Brightway Cleaning — Premium SaaS Design System */

/* ================================================================
   DESIGN TOKENS
   ================================================================ */

:root {
  /* Color Palette — Evergreen Primary */
  --primary: #0F6E56;
  --primary-dark: #0B5544;
  --primary-light: #E8F3EF;
  
  /* Surfaces & Backgrounds */
  --surface: #FFFFFF;
  --background: #F7F4EE;
  --background-alt: #FAFAF8;
  
  /* Text & Ink */
  --text: #12211D;
  --text-muted: #5B6B66;
  --text-light: #8A9592;
  
  /* Semantic Colors */
  --success: #1E8E5A;
  --success-tint: #E8F5F0;
  --warning: #B7791F;
  --warning-tint: #FEF7E8;
  --danger: #C0392B;
  --danger-tint: #FADBD8;
  --info: #2563EB;
  --info-tint: #EFF6FF;
  
  /* Neutral */
  --neutral: #6B7370;
  --neutral-tint: #F5F7F6;
  
  /* Borders & Dividers */
  --border: #E5E8E6;
  --border-light: #F0F2F1;
  --border-dark: #D0D5D2;
  
  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(18, 33, 29, 0.05);
  --shadow-sm: 0 1px 3px rgba(18, 33, 29, 0.1);
  --shadow-md: 0 4px 8px rgba(18, 33, 29, 0.08);
  --shadow-lg: 0 8px 16px rgba(18, 33, 29, 0.12);
  --shadow-xl: 0 12px 32px rgba(18, 33, 29, 0.15);
  
  /* Spacing Scale (8px base rhythm) */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;
  
  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  --font-mono: 'Cascadia Code', 'Menlo', 'Monaco', monospace;
  
  /* Z-index Scale */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal: 1000;
  --z-tooltip: 1100;
}

[data-theme="dark"] {
  --surface: #1A2421;
  --background: #0F1614;
  --background-alt: #131A17;
  --text: #E8F3EF;
  --text-muted: #A5B1AD;
  --text-light: #7A8481;
  --border: #2A3230;
  --border-light: #1F2724;
}

/* ================================================================
   RESET & BASE
   ================================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  color: var(--text);
  background: var(--background);
  line-height: 1.5;
  font-size: 15px;
}

button {
  font-family: var(--font-family);
}

input, select, textarea {
  font-family: var(--font-family);
}

/* ================================================================
   LAYOUT: SIDEBAR + TOPBAR + MAIN
   ================================================================ */

/* Single source of truth for the app shell: the sidebar is fixed, the main
   column is offset by its width. (A second grid-based definition used to
   coexist here and double-counted the offset, breaking small screens.) */
body {
  display: block;
  min-height: 100vh;
  overflow-x: hidden;
}

#sidebar {
  background: var(--primary-dark);
  color: var(--primary-light);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  z-index: var(--z-fixed);
}

#sidebar.collapsed {
  width: 72px;
  grid-template-columns: auto;
}

#sidebar.collapsed .nav-label {
  display: none;
}

.topbar {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  padding: var(--space-md) var(--space-xl);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

main {
  grid-column: 2;
  grid-row: 2;
  overflow-y: auto;
  background: var(--background);
}

#view {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-xl);
  width: 100%;
}

/* ================================================================
   SIDEBAR NAVIGATION
   ================================================================ */

.sidebar-header {
  padding: var(--space-lg) var(--space-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  font-size: 18px;
  font-weight: bold;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-lg) var(--space-sm);
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  color: rgba(232, 243, 239, 0.7);
  font-weight: 500;
  font-size: 14px;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--primary-light);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: var(--primary-light);
  border-color: rgba(255, 255, 255, 0.2);
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-label {
  white-space: nowrap;
}

.sidebar-footer {
  padding: var(--space-lg) var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.company-info {
  font-size: 13px;
  line-height: 1.4;
}

.company-name {
  font-weight: 600;
  color: var(--primary-light);
}

.company-role {
  color: rgba(232, 243, 239, 0.6);
}

.logout-btn {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--primary-light);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

/* ================================================================
   TOPBAR: TITLE, SEARCH, ACTIONS, MENU
   ================================================================ */

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex: 1;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.search-box {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  flex: 0 1 280px;
}

.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
}

.search-box input::placeholder {
  color: var(--text-light);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.topbar-action {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  transition: all 0.2s;
}

.topbar-action:hover {
  background: var(--background);
  border-color: var(--border-dark);
  color: var(--text);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 0.2s;
}

.user-menu:hover {
  background: var(--background);
}

.avatar {
  width: 32px;
  height: 32px;
  background: var(--primary-light);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 13px;
}

/* ================================================================
   BUTTONS
   ================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
  user-select: none;
}

.btn:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primary */
.btn--primary {
  background: var(--primary);
  color: var(--surface);
  border-color: var(--primary);
}

.btn--primary:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Secondary */
.btn--secondary {
  background: var(--background);
  color: var(--text);
  border-color: var(--border);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--background-alt);
  border-color: var(--border-dark);
}

/* Ghost */
.btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: transparent;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--background);
  border-color: var(--border);
}

/* Danger */
.btn--danger {
  background: var(--danger);
  color: var(--surface);
  border-color: var(--danger);
}

.btn--danger:hover:not(:disabled) {
  background: #A2311F;
  border-color: #A2311F;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Size: Small */
.btn--sm {
  padding: var(--space-xs) var(--space-md);
  font-size: 13px;
}

/* ================================================================
   FORMS
   ================================================================ */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-bottom: var(--space-lg);
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: color 0.2s;
}

.input, .select, .textarea {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--background);
  color: var(--text-muted);
  cursor: not-allowed;
}

.textarea {
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-family);
}

.field.error .input,
.field.error .select,
.field.error .textarea {
  border-color: var(--danger);
}

.field.error .input:focus,
.field.error .select:focus,
.field.error .textarea:focus {
  box-shadow: 0 0 0 3px var(--danger-tint);
}

.field-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: var(--space-xs);
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

/* Switch Toggle */
.switch {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  border-radius: var(--radius-full);
  transition: background 0.2s;
  display: flex;
  align-items: center;
  padding: 2px;
}

.switch-slider::after {
  content: '';
  width: 20px;
  height: 20px;
  background: var(--surface);
  border-radius: var(--radius-full);
  transition: transform 0.2s;
  box-shadow: var(--shadow-sm);
}

.switch input:checked + .switch-slider {
  background: var(--primary);
}

.switch input:checked + .switch-slider::after {
  transform: translateX(20px);
}

/* Segmented Control */
.segmented {
  display: inline-flex;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}

.segmented-item {
  padding: var(--space-sm) var(--space-md);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 4px;
  transition: all 0.2s;
}

.segmented-item:hover {
  color: var(--text);
}

.segmented-item.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ================================================================
   CARDS & SECTIONS
   ================================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-xs);
}

.card:hover {
  box-shadow: var(--shadow-sm);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.section-header h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.section-actions {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

/* ================================================================
   GRID & LAYOUT UTILITIES
   ================================================================ */

.grid {
  display: grid;
  gap: var(--space-lg);
}

.grid--2 {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid--3 {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.grid--4 {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.row {
  display: flex;
  gap: var(--space-lg);
  align-items: center;
}

.row--center {
  justify-content: center;
}

.row--between {
  justify-content: space-between;
}

.row--wrap {
  flex-wrap: wrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.split {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-lg);
}

/* ================================================================
   TYPOGRAPHY & TEXT UTILITIES
   ================================================================ */

.muted {
  color: var(--text-muted);
}

.light {
  color: var(--text-light);
}

.right {
  text-align: right;
}

.center {
  text-align: center;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.pos {
  color: var(--success);
}

.neg {
  color: var(--danger);
}

/* ================================================================
   DATA TABLE
   ================================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.data-table thead {
  background: var(--background);
  border-bottom: 1px solid var(--border-dark);
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table th {
  padding: var(--space-md) var(--space-lg);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.data-table th.right {
  text-align: right;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}

.data-table tbody tr:hover {
  background: var(--background-alt);
}

.data-table td {
  padding: var(--space-md) var(--space-lg);
  font-size: 14px;
  color: var(--text);
}

.data-table td.right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table td.muted {
  color: var(--text-muted);
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

/* ================================================================
   BADGES & PILLS
   ================================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: capitalize;
  white-space: nowrap;
}

.badge--success {
  background: var(--success-tint);
  color: var(--success);
}

.badge--warning {
  background: var(--warning-tint);
  color: var(--warning);
}

.badge--danger {
  background: var(--danger-tint);
  color: var(--danger);
}

.badge--info {
  background: var(--info-tint);
  color: var(--info);
}

.badge--neutral {
  background: var(--neutral-tint);
  color: var(--neutral);
}

.badge--teal {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  background: var(--background);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ================================================================
   STATUS INDICATORS & KPI
   ================================================================ */

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.kpi-card:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
  transition: all 0.2s;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-subtext {
  font-size: 13px;
  color: var(--text-muted);
}

/* ================================================================
   PROGRESS & METERS
   ================================================================ */

.progress {
  width: 100%;
  height: 6px;
  background: var(--background);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.progress-bar.warning {
  background: var(--warning);
}

.progress-bar.danger {
  background: var(--danger);
}

/* ================================================================
   TABS
   ================================================================ */

.tabs {
  display: flex;
  gap: var(--space-md);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-xl);
  overflow-x: auto;
  scroll-behavior: smooth;
}

.tab {
  padding: var(--space-md) 0;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ================================================================
   CHIPS & TAGS
   ================================================================ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  background: var(--background-alt);
  border-color: var(--border-dark);
}

.chip.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.chip-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.chip-close:hover {
  opacity: 1;
}

/* ================================================================
   AVATAR & USER
   ================================================================ */

.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.avatar.lg {
  width: 56px;
  height: 56px;
  font-size: 18px;
}

.avatar.sm {
  width: 32px;
  height: 32px;
  font-size: 12px;
}

.avatar-group {
  display: flex;
  gap: -8px;
}

.avatar-group .avatar {
  border: 2px solid var(--surface);
  margin-left: -8px;
}

.avatar-group .avatar:first-child {
  margin-left: 0;
}

/* ================================================================
   TOOLBAR & CONTROLS
   ================================================================ */

.toolbar {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex-wrap: wrap;
}

.toolbar-separator {
  width: 1px;
  background: var(--border);
  margin: 0 var(--space-xs);
}

.toolbar-group {
  display: flex;
  gap: var(--space-sm);
}

/* ================================================================
   EMPTY STATE
   ================================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
  padding: var(--space-3xl) var(--space-xl);
  text-align: center;
  color: var(--text-muted);
  min-height: 300px;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background);
  border-radius: var(--radius-lg);
  color: var(--text-light);
  font-size: 32px;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.empty-state-text {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 320px;
}

/* ================================================================
   SKELETON LOADERS
   ================================================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--background) 0%,
    var(--background-alt) 50%,
    var(--background) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 14px;
  margin-bottom: var(--space-sm);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
}

.skeleton-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
}

/* ================================================================
   MODALS & OVERLAYS
   ================================================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(18, 33, 29, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in 0.2s ease-out;
}

.modal.modal--sm {
  max-width: 400px;
}

.modal.modal--lg {
  max-width: 800px;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--background);
  color: var(--text);
}

.modal-body {
  padding: var(--space-xl);
}

.modal-footer {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-xl);
  border-top: 1px solid var(--border);
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ================================================================
   DRAWER (SLIDE-OVER)
   ================================================================ */

.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(18, 33, 29, 0.5);
  display: none;
  z-index: var(--z-modal);
}

.drawer-overlay.show {
  display: block;
}

.drawer {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  height: 100vh;
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  z-index: calc(var(--z-modal) + 1);
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease-out;
  overflow-y: auto;
}

.drawer.show {
  right: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-body {
  flex: 1;
  padding: var(--space-xl);
  overflow-y: auto;
}

/* ================================================================
   TOAST NOTIFICATIONS
   ================================================================ */

.toast-stack {
  position: fixed;
  top: var(--space-xl);
  right: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  z-index: var(--z-tooltip);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-lg);
  max-width: 360px;
  animation: toast-in 0.3s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.toast-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.toast-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.toast-message {
  font-size: 13px;
  color: var(--text-muted);
}

.toast.success {
  border-color: var(--success);
  background: var(--success-tint);
}

.toast.success .toast-icon {
  color: var(--success);
}

.toast.error {
  border-color: var(--danger);
  background: var(--danger-tint);
}

.toast.error .toast-icon {
  color: var(--danger);
}

.toast.warning {
  border-color: var(--warning);
  background: var(--warning-tint);
}

.toast.warning .toast-icon {
  color: var(--warning);
}

.toast.info {
  border-color: var(--info);
  background: var(--info-tint);
}

.toast.info .toast-icon {
  color: var(--info);
}

/* ================================================================
   CALENDAR
   ================================================================ */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-sm);
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
}

.cal-day:hover {
  background: var(--background-alt);
  border-color: var(--border-dark);
}

.cal-day.today {
  background: var(--primary);
  color: var(--surface);
  border-color: var(--primary);
  font-weight: 600;
}

.cal-day.selected {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.cal-day.other-month {
  color: var(--text-light);
  pointer-events: none;
}

.cal-event {
  font-size: 11px;
  padding: var(--space-xs) 2px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 900px) {
  /* Off-canvas navigation: sidebar slides in over the content. */
  #sidebar,
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.28);
  }
  #sidebar.nav-open,
  .sidebar.nav-open {
    transform: translateX(0);
  }
  .main-wrapper,
  .sidebar.collapsed ~ .main-wrapper {
    margin-left: 0;
  }
  .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: calc(var(--z-fixed) - 1);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .nav-scrim.show {
    opacity: 1;
    pointer-events: auto;
  }
  .nav-toggle {
    display: inline-flex !important;
  }

  .grid--2 {
    grid-template-columns: 1fr;
  }

  .data-table {
    font-size: 13px;
  }

  .data-table th, .data-table td {
    padding: var(--space-md);
  }

  .drawer {
    width: 100%;
    right: -100%;
  }

  .search-box {
    display: none;
  }

  .topbar-action:nth-child(n+3) {
    display: none;
  }
}

@media (max-width: 640px) {
  #view {
    padding: var(--space-lg) var(--space-md);
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-md);
  }

  .topbar-left {
    width: 100%;
  }

  .topbar-right {
    width: 100%;
    justify-content: flex-end;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .section-actions {
    width: 100%;
  }

  .section-actions .btn {
    flex: 1;
  }

  .modal {
    width: 95%;
  }

  .toast-stack {
    right: var(--space-md);
    left: var(--space-md);
  }

  .toast {
    max-width: none;
  }

  .calendar-grid {
    gap: 4px;
  }
}

/* ================================================================
   APP SHELL LAYOUT (sidebar, topbar, main wrapper)
   ================================================================ */

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 240px;
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: white;
  display: flex;
  flex-direction: column;
  z-index: var(--z-fixed);
  transition: width 0.3s;
}

.sidebar.collapsed {
  width: 72px;
}

.sidebar-header {
  padding: var(--space-lg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: white;
}

.logo-text {
  transition: opacity 0.3s;
}

.sidebar.collapsed .logo-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) 0;
}

.sidebar-footer {
  padding: var(--space-lg);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  opacity: 0.7;
}

.main-wrapper {
  margin-left: 240px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s;
}

.sidebar.collapsed ~ .main-wrapper {
  margin-left: 72px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-lg) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.loading-shell {
  padding: var(--space-xl);
}

.loading-shell .skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-width: 600px;
}

/* Login page classes (styled inline in login.html) */
.login-container,
.login-brand,
.login-brand-header,
.login-card,
.login-error,
.login-field,
.login-footer,
.login-form,
.login-form-wrapper,
.login-header,
.login-logo,
.login-password-wrapper,
.login-submit,
.login-tagline,
.login-toggle-password,
.login-wordmark {
  /* Styled inline in templates/login.html */
}

/* ================================================================
   PRINT STYLESHEET (for invoices)
   ================================================================ */

@media print {
  body {
    display: block;
    background: white;
  }

  #sidebar,
  .topbar,
  .section-actions,
  .btn,
  .modal-overlay,
  .drawer,
  .toast-stack {
    display: none !important;
  }

  main {
    all: initial;
  }

  #view {
    max-width: 100%;
    padding: 0;
    margin: 0;
  }

  .card {
    page-break-inside: avoid;
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }

  table {
    page-break-inside: avoid;
    break-inside: avoid;
    border-collapse: collapse;
  }

  th, td {
    border: 1px solid #ccc;
    padding: 8px;
  }
}

/* Inline toggle in toolbars */
.switch-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-2, #5b6472);
  cursor: pointer;
  user-select: none;
  padding: 0 2px;
}
.switch-inline input { accent-color: var(--brand, #2563eb); cursor: pointer; }

/* ================================================================
   RESPONSIVE SHELL — must stay LAST so it beats the base shell rules
   ================================================================ */
@media (max-width: 900px) {
  .main-wrapper,
  .sidebar.collapsed ~ .main-wrapper {
    margin-left: 0 !important;
    width: 100%;
  }
  .sidebar,
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 264px;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
  }
  .sidebar.nav-open,
  #sidebar.nav-open {
    transform: translateX(0);
  }
  .grid--2, .grid--3, .grid--4 {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  .kpi-card { padding: var(--space-md); }
  .stat-value { font-size: 22px; }
  .data-table { white-space: nowrap; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .row--between { flex-wrap: wrap; gap: var(--space-sm); }
  .toolbar { flex-wrap: wrap; }
  .segmented { overflow-x: auto; max-width: 100%; }
}
