/* Numus Logistics - Business Web App Styles */
/* Industrial-grade design with precision typography */

/* ==================== CSS Variables ==================== */
:root {
  /* Numus Logistics Brand Colors */
  --color-primary: #0b1c2d; /* Numus Deep Navy */
  --color-primary-dark: #050e17;
  --color-primary-light: #162d42;
  --color-accent: #00b3a4; /* Velocity Teal */
  --color-accent-hover: #009688;

  --color-success: #16a34a; /* Route Green */
  --color-success-bg: #dcfce7;
  --color-success-dark: #15803d; /* AA-compliant on white */
  --color-warning: #f5a524; /* Signal Amber — decorative; not for text on white */
  --color-warning-bg: #fef3c7;
  --color-warning-dark: #b45309; /* AA-compliant on white / on warning-bg */
  --color-error: #dc2626; /* Alert Red */
  --color-error-bg: #fee2e2;
  --color-error-dark: #b91c1c;
  --color-info: #00b3a4; /* Velocity Teal (In Transit) */
  --color-info-bg: #e0f7f5;
  --color-info-dark: #0f766e;

  /* Neutral Colors */
  --color-bg: #f9fafb; /* Cloud White */
  --color-surface: #ffffff;
  --color-border: #e5e7eb; /* Mist Gray */
  --color-border-dark: #d1d5db;
  --color-text: #111827; /* Graphite Black */
  --color-text-secondary: #4b5563; /* AA on white (was #6b7280) */
  --color-text-muted: #6b7280; /* AA on white (was #9ca3af = 2.84:1, failed) */

  /* Typography */
  --font-display:
    DM Sans, -apple-system, BlinkMacSystemFont, sans-serif, "Museo Moderno";
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:
    0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl:
    0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 64px;

  /* Motion (use motion-safe variants below where needed) */
  --transition: all 0.2s ease;
  --transition-fast: 0.12s ease;
  --transition-base: 0.2s ease;
  --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Focus ring (single source of truth) */
  --focus-ring-width: 3px;
  --focus-ring-color: rgba(0, 179, 164, 0.45); /* accent @ 45% */
  --focus-ring-offset: 2px;

  /* Z-index scale — use these tokens, do not hardcode */
  --z-base: 1;
  --z-sticky: 50;          /* sticky header */
  --z-dropdown: 100;
  --z-sidebar: 200;        /* fixed sidebar */
  --z-overlay: 1000;       /* modals/overlays */
  --z-toast: 2000;         /* toasts */
  --z-tooltip: 3000;
  --z-takeover: 5000;      /* full-page blocking overlays (e.g. coming-soon) */
}

/* Skip-to-main-content link for keyboard users (WCAG 2.4.1) */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-weight: 600;
  z-index: var(--z-tooltip);
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-md);
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

/* Respect user's motion preference */
@media (prefers-reduced-motion: reduce) {
  :root {
    --transition: none;
    --transition-fast: none;
    --transition-base: none;
    --transition-slow: none;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==================== Reset & Base ==================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh; /* mobile-safe viewport (safari dynamic viewport) */
  overflow-x: hidden; /* prevent horizontal scroll from inline styles/overflowing tables */
  -webkit-tap-highlight-color: transparent;
}

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

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

img,
svg {
  max-width: 100%;
  height: auto;
}

svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ==================== Accessibility primitives ==================== */

/* Visually hidden (for screen-reader-only text) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip to main content link — becomes visible on focus */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-md);
  z-index: var(--z-tooltip);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus,
.skip-link:focus-visible {
  top: var(--space-md);
  color: #fff;
}

/* Unified keyboard-only focus ring */
:focus {
  outline: none;
}

:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-sm);
}

/* Components with their own rounded bounds get a matching offset */
.btn:focus-visible,
.nav-link:focus-visible,
.pagination-btn:focus-visible,
.tab:focus-visible,
.user-menu:focus-visible,
.modal-close:focus-visible,
.chat-modal-close:focus-visible,
.chat-tab:focus-visible,
.chat-send-btn:focus-visible,
.chat-conversation-item:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

/* Inputs already have box-shadow focus — suppress outline there */
.form-input:focus-visible,
.form-select:focus-visible,
.form-textarea:focus-visible,
.search-box input:focus-visible,
.chat-input:focus-visible,
.chat-search input:focus-visible,
.chat-priority-select:focus-visible,
.chat-modal-input:focus-visible,
.chat-modal-select:focus-visible,
.filter-select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* ==================== SVG Icon System ==================== */
/* Usage: <svg class="icon icon-md" ...>  — fill/stroke inherit color */
.icon {
  width: 1.25em;
  height: 1.25em;
  flex-shrink: 0;
  color: currentColor;
  fill: currentColor;
  vertical-align: -0.125em;
}

.icon-sm { width: 1em; height: 1em; }
.icon-md { width: 1.25em; height: 1.25em; }
.icon-lg { width: 1.5em; height: 1.5em; }
.icon-xl { width: 2rem; height: 2rem; }
.icon-2xl { width: 3rem; height: 3rem; }

/* Stroke-based icons (e.g., Lucide) — no fill, inherits stroke color */
.icon-stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==================== Typography ==================== */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text);
}

h1 {
  font-size: 2rem;
}
h2 {
  font-size: 1.5rem;
}
h3 {
  font-size: 1.25rem;
}
h4 {
  font-size: 1.125rem;
}
h5 {
  font-size: 1rem;
}
h6 {
  font-size: 0.875rem;
}

.text-muted {
  color: var(--color-text-muted);
}
.text-secondary {
  color: var(--color-text-secondary);
}
.text-success {
  color: var(--color-success);
}
.text-warning {
  color: var(--color-warning);
}
.text-error {
  color: var(--color-error);
}

/* ==================== Layout ==================== */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(
    180deg,
    var(--color-primary) 0%,
    var(--color-primary-dark) 100%
  );
  color: white;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh; /* mobile-safe viewport */
  overflow: hidden;
  z-index: var(--z-sidebar);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  /* Respect iPhone notch / gesture bar */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Scrim shown behind the sidebar on mobile when .open is toggled */
.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, 0.5);
  z-index: calc(var(--z-sidebar) - 1);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base),
    visibility var(--transition-base);
}

.sidebar.open ~ .sidebar-scrim,
.sidebar-scrim.active {
  opacity: 1;
  visibility: visible;
}

@media (min-width: 1025px) {
  .sidebar-scrim {
    display: none;
  }
}

.sidebar-header {
  padding: var(--space-lg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  background: var(--color-primary);
}

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

.sidebar-logo-link {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-md);
  text-decoration: none;
}

.sidebar-logo .logo-icon {
  width: 40px;
  height: 40px;
  background: var(--color-accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.sidebar-logo .logo-text {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar-beta-badge {
  background: #f59e0b;
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1;
  margin-left: 4px;
}

.sidebar-user-info {
  padding: var(--space-md);
  padding-top: var(--space-sm);
  margin-top: var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: white;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-detail {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 4px;
}

.sidebar-user-detail-icon {
  font-size: 0.75rem;
  opacity: 0.8;
}

.sidebar-user-role {
  text-transform: capitalize;
}

.sidebar-user-login-time {
  font-size: 0.6875rem;
  color: rgba(255, 255, 255, 0.5);
}

.sidebar-nav {
  padding: var(--space-md);
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Custom scrollbar for sidebar nav */
.sidebar-nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

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

/* Footer-pinned section (e.g., logout) */
.nav-section-footer {
  margin-top: auto;
  margin-bottom: 0;
  padding-top: var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-label {
  flex: 1;
  min-width: 0;
}

.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: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-xs);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  color: rgba(255, 255, 255, 0.8);
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: var(--space-xs);
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.nav-link.active {
  background: var(--color-accent);
  color: white;
}

.nav-link .nav-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-link .nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
}

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

/* Header */
.main-header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  /* Respect notch in landscape on iPhone */
  padding-left: max(var(--space-xl), env(safe-area-inset-left));
  padding-right: max(var(--space-xl), env(safe-area-inset-right));
}

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

/* Mobile menu toggle — hidden on desktop, shown ≤1024px (rule below) */
#menuToggle {
  display: none;
}

@media (max-width: 1024px) {
  #menuToggle {
    display: inline-flex;
  }
}

/* When sidebar is open on mobile, prevent body scroll behind it */
body.sidebar-open {
  overflow: hidden;
}

@media (min-width: 1025px) {
  body.sidebar-open {
    overflow: auto;
  }
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.header-right {
  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: var(--transition);
}

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

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
}

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

/* ==================== Cards ==================== */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

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

.card-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

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

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  transition: var(--transition);
}

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

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.stat-icon svg,
.plan-icon svg,
.role-icon svg,
.payment-method-icon svg,
.upgrade-modal-icon svg,
.limit-warning-icon svg,
.feature-icon svg,
.chat-avatar svg,
.chat-main-empty-icon svg,
.chat-search-icon svg,
.usage-title svg,
.section-editor-title svg,
.stats-group-label svg {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.125em;
}

.stat-icon.primary {
  background: #dbeafe;
  color: var(--color-primary);
}
.stat-icon.success {
  background: #d1fae5;
  color: var(--color-success-dark);
}
.stat-icon.warning {
  background: #fef3c7;
  color: var(--color-warning-dark); /* was var(--color-warning) — failed AA on bg */
}
.stat-icon.accent {
  background: #e0f7f5; /* was peach #ffedd5 — didn't match accent teal */
  color: var(--color-info-dark);
}
.stat-icon.error {
  background: var(--color-error-bg);
  color: var(--color-error-dark);
}

.stat-content {
  flex: 1;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  font-family: var(--font-display);
  line-height: 1.2;
}

.stat-label {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  margin-top: var(--space-xs);
}

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

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

/* ==================== Tables ==================== */
/*
 * Horizontal scroll + scroll-shadow indicator so users on mobile know there is
 * more content to the right. The right-edge shadow disappears when you scroll
 * all the way to the end. Implemented via a CSS-only background-attachment trick.
 */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  background:
    /* left shadow — appears when scrolled right */ linear-gradient(
        to right,
        rgba(0, 0, 0, 0.08),
        transparent 20px
      )
      0 0 / 20px 100% no-repeat local,
    /* right shadow — appears when more content is to the right */
      linear-gradient(to left, rgba(0, 0, 0, 0.08), transparent 20px) 100% 0 /
      20px 100% no-repeat local,
    /* solid cover layers — hide shadows when scrolled to the edges */
      linear-gradient(to right, var(--color-surface), rgba(255, 255, 255, 0))
      0 0 / 20px 100% no-repeat scroll,
    linear-gradient(to left, var(--color-surface), rgba(255, 255, 255, 0))
      100% 0 / 20px 100% no-repeat scroll;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: max-content; /* preserve columns on narrow screens */
}

.data-table th {
  text-align: left;
  padding: var(--space-md);
  background: var(--color-bg);
  border-bottom: 2px solid var(--color-border);
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-secondary);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

/* Tabular numerals for price/quantity columns to prevent shift */
.data-table td.num,
.data-table .order-id,
.data-table .amount {
  font-variant-numeric: tabular-nums;
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: var(--color-bg);
}

.data-table .order-id {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 500;
}

/* Status Badges */
.status-badge {
  display: inline-block;
  width: 140px;
  max-width: 100%;
  box-sizing: border-box;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  text-align: center;
  line-height: 1.4;
  vertical-align: middle;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  min-height: 40px; /* baseline — bumped to 44px on touch devices below */
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition-base),
    color var(--transition-base), transform var(--transition-fast),
    box-shadow var(--transition-base);
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
  text-decoration: none; /* <a class="btn"> */
}

/* Subtle press feedback (respects reduced-motion via root var) */
.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

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

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

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

.btn-accent {
  background: var(--color-accent);
  color: white;
}

.btn-accent:hover:not(:disabled) {
  background: var(--color-accent-hover);
}

.btn-success {
  background: var(--color-success);
  color: white;
}

.btn-danger {
  background: var(--color-error);
  color: white;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.btn-outline:hover:not(:disabled) {
  background: var(--color-bg);
}

.btn-sm {
  padding: var(--space-xs) var(--space-sm);
  min-height: 32px;
  font-size: 0.8125rem;
}

.btn-lg {
  padding: var(--space-md) var(--space-lg);
  min-height: 48px;
  font-size: 1rem;
}

/* Icon-only button. Visually 40x40, expands hit area to 44x44 via ::after on touch. */
.btn-icon {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  position: relative;
}

.btn-icon::after {
  /* Invisible hit-area extender for touch — ensures 44x44 without visual growth */
  content: "";
  position: absolute;
  inset: -2px;
}

.btn-group {
  display: flex;
  gap: var(--space-xs);
}

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

/* ==================== Forms ==================== */
.form-group {
  margin-bottom: var(--space-lg);
}

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

.form-label.required::after {
  content: " *";
  color: var(--color-error);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  min-height: 44px; /* touch-friendly — iOS also avoids auto-zoom at 16px */
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 16px; /* >= 16px prevents iOS Safari zoom-on-focus */
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-base),
    box-shadow var(--transition-base);
  appearance: none;
  -webkit-appearance: none;
}

/* Custom chevron for <select> elements. Native appearance is stripped above
 * (and on .filter-select below) for a consistent look across browsers, so we
 * paint a chevron via inline-SVG background-image. Right padding reserves
 * space for the chevron so option text never overlaps it. */
.form-select,
.filter-select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-md) center;
  padding-right: calc(var(--space-md) * 2 + 16px);
}

.filter-select {
  appearance: none;
  -webkit-appearance: none;
}

@media (min-width: 768px) {
  .form-input,
  .form-select,
  .form-textarea {
    font-size: 0.9375rem; /* desktop can safely go smaller (no zoom trigger) */
  }
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 179, 164, 0.2);
}

.form-input::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.form-input.error,
.form-select.error,
.form-textarea.error,
.form-input[aria-invalid="true"],
.form-select[aria-invalid="true"],
.form-textarea[aria-invalid="true"] {
  border-color: var(--color-error);
}

.form-input.error:focus,
.form-select.error:focus,
.form-textarea.error:focus,
.form-input[aria-invalid="true"]:focus,
.form-select[aria-invalid="true"]:focus,
.form-textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
}

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

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

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
}

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

.form-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
}

/* ==================== Modals ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, 0.55); /* per HIG: ~40–60% opacity scrim */
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  z-index: var(--z-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

/* Prevent body scroll when a modal is open (toggle class on <body>) */
body.modal-open {
  overflow: hidden;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  transform: scale(0.95);
  transition: var(--transition);
  /* Flex items default to min-width: auto (content-based), which can push
   * the modal past max-width on narrow viewports. Force it to respect the cap. */
  min-width: 0;
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-lg {
  max-width: 800px;
}

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

.modal-header h3 {
  font-size: 1.125rem;
}

.modal-close {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  font-size: 1.5rem;
  line-height: 1;
  transition: var(--transition);
  position: relative;
}

.modal-close::after {
  content: "";
  position: absolute;
  inset: -2px; /* extend hit area to 44x44 on touch */
}

.modal-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.modal-body {
  padding: var(--space-lg);
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-width: 0;
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  background: var(--color-bg);
}

/* ==================== Toast Notifications ==================== */
.toast {
  position: fixed;
  bottom: max(var(--space-xl), env(safe-area-inset-bottom));
  right: max(var(--space-xl), env(safe-area-inset-right));
  max-width: calc(100vw - var(--space-xl) * 2);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  background: var(--color-text);
  color: white;
  box-shadow: var(--shadow-lg);
  transform: translateY(100px);
  opacity: 0;
  transition: transform var(--transition-base), opacity var(--transition-base);
  z-index: var(--z-toast);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

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

.toast-icon {
  font-size: 1.125rem;
}

.toast-success {
  background: var(--color-success);
}
.toast-error {
  background: var(--color-error);
}
.toast-warning {
  /* amber + white text fails AA (2.3:1). Swap to dark amber so white passes. */
  background: var(--color-warning-dark);
}
.toast-info {
  background: var(--color-info-dark);
}

/* ==================== Loading States ==================== */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.loading-spinner {
  text-align: center;
}

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

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

/* ==================== Empty States ==================== */
.empty-state {
  padding: var(--space-2xl);
  text-align: center;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.5;
  /* When inner content is an SVG, render it at 48x48 with muted color */
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.empty-state-icon svg {
  width: 48px;
  height: 48px;
}

.empty-state-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.empty-state-description {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-lg);
  max-width: 32ch;
  margin-left: auto;
  margin-right: auto;
}

/* ==================== Pagination ==================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0;
}

.pagination-info {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
}

.pagination-buttons {
  display: flex;
  gap: var(--space-xs);
}

.pagination-btn {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.875rem;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--color-bg);
}

.pagination-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

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

/* ==================== Filters & Search ==================== */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  align-items: center;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 400px;
}

.search-box input {
  width: 100%;
  min-height: 44px;
  padding: var(--space-sm) var(--space-md);
  padding-left: 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 16px; /* iOS no-zoom */
  background: var(--color-surface);
  transition: border-color var(--transition-base),
    box-shadow var(--transition-base);
}

@media (min-width: 768px) {
  .search-box input {
    font-size: 0.9375rem;
  }
}

.search-box input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 179, 164, 0.2);
}

/* Lucide "search" icon (stroke) embedded as an inline SVG data URI.
 * Replaces the previous 🔍 emoji — platform-consistent, theme-able via color. */
.search-box::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  pointer-events: none;
}

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

.filter-label {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.filter-select {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  min-width: 150px;
}

/* ==================== Driver Card ==================== */
.driver-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.driver-card:hover {
  box-shadow: var(--shadow-sm);
}

.driver-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.125rem;
}

.driver-info {
  flex: 1;
}

.driver-name {
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.driver-meta {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Highlight the currently-assigned driver */
.driver-card-current {
  border-color: var(--color-primary);
  box-shadow: inset 3px 0 0 var(--color-primary);
}

.assignment-current-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #fff;
  background: var(--color-success);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-left: var(--space-xs);
  vertical-align: middle;
}

/* Driver assignment history timeline */
.assignment-history {
  position: relative;
  padding-left: var(--space-xl);
}

.assignment-history::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--color-border);
}

.assignment-item {
  position: relative;
  padding-bottom: var(--space-lg);
}

.assignment-item:last-child {
  padding-bottom: 0;
}

.assignment-dot {
  position: absolute;
  left: -22px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-border);
  border: 2px solid var(--color-surface);
}

.assignment-item-current .assignment-dot {
  background: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(30, 58, 95, 0.2);
}

.assignment-name {
  font-weight: 600;
}

.assignment-meta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

/* ==================== Order Details ==================== */
.order-timeline {
  position: relative;
  padding-left: var(--space-xl);
}

.order-timeline::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-border);
}

.timeline-item {
  position: relative;
  padding-bottom: var(--space-lg);
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -22px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-border);
  border: 2px solid var(--color-surface);
}

.timeline-item.completed .timeline-dot {
  background: var(--color-success);
}

.timeline-item.active .timeline-dot {
  background: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(30, 58, 95, 0.2);
}

.timeline-content {
  background: var(--color-bg);
  padding: var(--space-md);
  border-radius: var(--radius-md);
}

.timeline-time {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: var(--space-xs);
}

/* ==================== Tabs ==================== */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--space-lg);
}

.tab {
  padding: var(--space-md) var(--space-lg);
  border: none;
  background: none;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  position: relative;
  transition: var(--transition);
}

.tab:hover {
  color: var(--color-text);
}

.tab.active {
  color: var(--color-primary);
}

.tab.active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ==================== Auth Pages ==================== */
.auth-container {
  min-height: 100vh;
  display: flex;
  background: linear-gradient(
    135deg,
    var(--color-primary) 0%,
    var(--color-primary-dark) 100%
  );
}

.auth-branding {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-2xl);
  color: white;
}

.auth-branding h1 {
  font-size: 2.5rem;
  color: white;
  margin-bottom: var(--space-md);
}

.auth-branding p {
  font-size: 1.125rem;
  opacity: 0.9;
  max-width: 400px;
}

.auth-form-container {
  width: 100%;
  max-width: 480px;
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-2xl);
}

.auth-form {
  width: 100%;
}

.auth-form h2 {
  margin-bottom: var(--space-sm);
}

.auth-form .subtitle {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}

.auth-footer {
  margin-top: var(--space-xl);
  text-align: center;
  color: var(--color-text-secondary);
}

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

/* Tablet and Small Desktop (1024px and below) */
@media (max-width: 1024px) {
  :root {
    --space-xl: 1.5rem;
    --space-2xl: 2rem;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }

  .main-content {
    margin-left: 0;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
  }

  .main-header {
    padding: 0 var(--space-md);
  }

  .page-content {
    padding: var(--space-md);
    max-width: 100%;
    overflow-x: hidden;
  }

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

  .card-header,
  .card-body {
    padding: var(--space-md);
  }

  /* Make dashboard grid single column on tablet */
  .page-content > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  .header-right {
    gap: var(--space-sm);
  }

  .user-menu span {
    display: none;
  }

  #planBadge {
    font-size: 11px;
    padding: 3px 8px;
    margin-right: 6px;
  }

  /* Modals — when sidebar is collapsed, drop the centered card in favor of
   * a full-width sheet so form content never forces horizontal scroll on
   * tablet portraits (e.g. iPad 768px). */
  .modal-overlay {
    padding: 0;
  }

  .modal {
    margin: 0;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  .modal-lg {
    max-width: 100%;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-md) var(--space-lg);
  }
}

/* Mobile (768px and below) */
@media (max-width: 768px) {
  :root {
    font-size: 14px;
  }

  html {
    font-size: 14px;
  }

  /* Auth pages - hide branding, show only form */
  .auth-container {
    padding: var(--space-md);
  }

  .auth-branding {
    display: none;
  }

  .auth-form-container {
    max-width: 100%;
    padding: var(--space-lg);
  }

  /* Typography adjustments */
  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  h3 {
    font-size: 1.125rem;
  }

  .page-title {
    font-size: 1.125rem;
  }

  /* Stats grid - single column on mobile */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
  }

  .stat-card {
    padding: var(--space-md);
  }

  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  /* Forms */
  .form-row {
    grid-template-columns: 1fr;
  }

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

  /* Filters and search */
  .filters-bar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-sm);
  }

  .search-box {
    max-width: none;
  }

  .filter-select {
    width: 100%;
  }

  /* Modals - full screen on mobile */
  .modal-overlay {
    padding: 0;
  }

  .modal {
    margin: 0;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  .modal-lg {
    max-width: 100%;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-md);
  }

  /* Tables - improve mobile readability.
   * Note: we previously hid columns 4+ on mobile; that silently lost data.
   * Now we keep all columns and rely on horizontal scroll + scroll-shadow
   * (see .table-container). Authors who want to hide secondary columns at
   * narrow widths should opt in with .hide-sm / .hide-md utility classes. */
  .data-table {
    font-size: 0.8125rem;
  }

  .data-table th,
  .data-table td {
    padding: var(--space-sm);
  }

  .data-table th {
    font-size: 0.75rem;
  }

  /* Cards */
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  /* Buttons */
  .btn-group {
    flex-wrap: wrap;
  }

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

  /* Toast notifications */
  .toast {
    left: var(--space-md);
    right: var(--space-md);
    bottom: var(--space-md);
  }

  /* Driver cards */
  .driver-card {
    padding: var(--space-sm);
  }

  .driver-avatar {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }

  /* Pagination */
  .pagination {
    flex-direction: column;
    gap: var(--space-sm);
    align-items: stretch;
  }

  .pagination-buttons {
    justify-content: center;
  }

  .pagination-info {
    text-align: center;
  }

  /* Empty states */
  .empty-state {
    padding: var(--space-lg);
  }

  .empty-state-icon {
    font-size: 2rem;
  }
}

/* Small Mobile (480px and below) */
@media (max-width: 480px) {
  :root {
    --space-md: 0.75rem;
    --space-lg: 1rem;
    --space-xl: 1.25rem;
  }

  .page-content {
    padding: var(--space-sm);
  }

  .main-header {
    padding: 0 var(--space-sm);
    height: 56px;
  }

  .auth-form-container {
    padding: var(--space-md);
  }

  .card {
    border-radius: var(--radius-md);
  }

  .stat-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
  }

  /* Stack buttons vertically on very small screens */
  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer .btn {
    width: 100%;
  }

  .btn-group {
    flex-direction: column;
    width: 100%;
  }

  .btn-group .btn {
    width: 100%;
  }

  /* Make action buttons full width */
  .page-content .btn:not(.btn-icon) {
    width: 100%;
    justify-content: center;
  }

  /* Simplify header on very small screens */
  .header-right .btn:not(.btn-icon) span {
    display: none;
  }

  .header-right .btn:not(.btn-icon)::before {
    content: "+";
    font-size: 1.25rem;
  }

  #planBadge {
    display: none;
  }
}

/* Landscape orientation adjustments */
@media (max-height: 600px) and (orientation: landscape) {
  .auth-container {
    padding: var(--space-sm);
  }

  .auth-form-container {
    padding: var(--space-md);
    justify-content: flex-start;
    overflow-y: auto;
  }

  .modal {
    max-height: 95vh;
  }
}

/* Print styles */
@media print {
  .sidebar,
  .main-header,
  .btn,
  .filters-bar,
  .pagination {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
  }

  .card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #000;
  }

  .page-content {
    padding: 0;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  /* Increase touch target sizes */
  .btn {
    min-height: 44px;
    padding: var(--space-sm) var(--space-lg);
  }

  .btn-sm {
    min-height: 40px; /* still touch-friendly with hit-area extender */
  }

  .btn-icon {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .modal-close,
  .chat-modal-close {
    width: 44px;
    height: 44px;
  }

  .pagination-btn {
    min-height: 44px;
  }

  .nav-link {
    padding: var(--space-md);
    min-height: 44px;
  }

  .form-checkbox input {
    width: 24px;
    height: 24px;
  }

  .tab {
    min-height: 44px;
  }

  /* Improve scrolling on touch devices */
  .sidebar,
  .modal-body,
  .page-content {
    -webkit-overflow-scrolling: touch;
  }

  /* Remove transform-based hover effects on touch devices (no hover) */
  .btn:hover,
  .nav-link:hover,
  .card:hover,
  .stat-card:hover {
    transform: none;
  }
}

/* ==================== Utility Classes ==================== */
.hidden { display: none !important; }
.block  { display: block; }
.inline-block { display: inline-block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }

.flex-col { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-auto { flex: auto; }

.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.justify-between { justify-content: space-between; }

.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

.m-0 { margin: 0; }
.mb-xs { margin-bottom: var(--space-xs); }
.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); }
.mt-xs { margin-top: var(--space-xs); }
.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); }
.mr-sm { margin-right: var(--space-sm); }
.mr-md { margin-right: var(--space-md); }
.ml-sm { margin-left: var(--space-sm); }
.ml-md { margin-left: var(--space-md); }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }

.p-0 { padding: 0; }
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.p-xl { padding: var(--space-xl); }
.px-md { padding-left: var(--space-md); padding-right: var(--space-md); }
.py-md { padding-top: var(--space-md); padding-bottom: var(--space-md); }

.w-full { width: 100%; }
.h-full { height: 100%; }
.max-w-sm { max-width: 480px; }
.max-w-md { max-width: 640px; }
.max-w-lg { max-width: 800px; }
.max-w-xl { max-width: 1024px; }

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-mono { font-family: var(--font-mono); }
.tabular-nums { font-variant-numeric: tabular-nums; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cursor-pointer { cursor: pointer; }
.relative { position: relative; }
.absolute { position: absolute; }

.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

.border { border: 1px solid var(--color-border); }
.border-t { border-top: 1px solid var(--color-border); }
.border-b { border-bottom: 1px solid var(--color-border); }

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

/* Responsive visibility */
.hide-on-mobile { display: initial; }
.show-on-mobile { display: none; }

@media (max-width: 768px) {
  .hide-on-mobile { display: none !important; }
  .show-on-mobile { display: initial; }
  .hide-sm { display: none !important; }
  .stack-on-mobile { flex-direction: column !important; align-items: stretch !important; }
  .full-on-mobile { width: 100% !important; }
}

@media (max-width: 1024px) {
  .hide-md { display: none !important; }
}

/* ==================== Team Chat ==================== */

.chat-container {
  display: flex;
  height: 100%;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-height: 0;
}

/* Chat Sidebar (conversation list) */
.chat-sidebar {
  width: 320px;
  min-width: 320px;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  min-height: 0;
  overflow: hidden;
}

.chat-sidebar-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-tabs {
  display: flex;
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.chat-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.chat-tab:hover {
  color: var(--color-text);
  background: var(--color-surface);
}

.chat-tab.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.chat-search {
  margin-top: var(--space-sm);
  position: relative;
}

.chat-search input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 16px;
  background: var(--color-bg);
  outline: none;
  transition: var(--transition);
}

@media (min-width: 768px) {
  .chat-search input {
    font-size: 0.8125rem;
  }
}

.chat-search input:focus {
  border-color: var(--color-accent);
  background: var(--color-surface);
}

.chat-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.875rem;
  opacity: 0.5;
}

/* Conversation list */
.chat-conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xs) 0;
  min-height: 0;
}

.chat-conversation-item {
  display: flex;
  align-items: center;
  padding: 10px var(--space-md);
  cursor: pointer;
  transition: var(--transition);
  gap: 10px;
  border-left: 3px solid transparent;
}

.chat-conversation-item:hover {
  background: var(--color-bg);
}

.chat-conversation-item.active {
  background: #e0f7f5;
  border-left-color: var(--color-accent);
}

.chat-conv-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.875rem;
}

.chat-conv-avatar.group {
  background: var(--color-accent);
}

.chat-conv-info {
  flex: 1;
  min-width: 0;
}

.chat-conv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-conv-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-conv-time {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.chat-conv-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.chat-conv-last-msg {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-unread-badge,
.chat-conv-unread {
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.chat-priority-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  display: inline-block;
  margin-left: 4px;
}

/* Chat sidebar actions */
.chat-sidebar-actions {
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.chat-sidebar-actions .btn {
  flex: 1;
  font-size: 0.75rem;
  padding: 6px 8px;
}

/* Chat Main Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.chat-main-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--color-text-muted);
  gap: var(--space-md);
}

.chat-main-empty-icon {
  font-size: 3rem;
  opacity: 0.3;
}

.chat-main-empty-text {
  font-size: 0.9375rem;
  font-family: var(--font-display);
}

/* Chat header (conversation detail header) */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--color-text);
}

.chat-header-meta {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.chat-header-actions {
  display: flex;
  gap: var(--space-sm);
}

.chat-header-actions .btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.chat-header-actions .btn-icon:hover {
  background: var(--color-bg);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  background: var(--color-bg);
  min-height: 0;
}

.chat-date-divider {
  text-align: center;
  padding: var(--space-sm) 0;
}

.chat-date-divider span {
  background: var(--color-surface);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.chat-message {
  display: flex;
  gap: 8px;
  max-width: 75%;
}

.chat-message.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.625rem;
  font-weight: 600;
  align-self: flex-end;
}

.chat-msg-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  position: relative;
}

.chat-message:not(.own) .chat-msg-bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.chat-message.own .chat-msg-bubble {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg-sender {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-accent);
  margin-bottom: 2px;
}

.chat-message.own .chat-msg-sender {
  color: rgba(255, 255, 255, 0.7);
}

.chat-msg-text {
  font-size: 0.8125rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-msg-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}

.chat-msg-time {
  font-size: 0.625rem;
  opacity: 0.6;
}

.chat-msg-priority {
  font-size: 0.5625rem;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-msg-priority.high {
  background: #fef3c7;
  color: #92400e;
}

.chat-msg-priority.urgent {
  background: #fee2e2;
  color: #991b1b;
}

.chat-message.own .chat-msg-priority.high {
  background: rgba(245, 165, 36, 0.3);
  color: #fef3c7;
}

.chat-message.own .chat-msg-priority.urgent {
  background: rgba(239, 68, 68, 0.3);
  color: #fee2e2;
}

/* Chat input area */
.chat-input-area {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
}

.chat-priority-select {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.75rem;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  outline: none;
  min-width: 90px;
}

.chat-priority-select:focus {
  border-color: var(--color-accent);
}

.chat-input-wrapper {
  flex: 1;
  position: relative;
}

.chat-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 16px;
  background: var(--color-bg);
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  transition: var(--transition);
}

@media (min-width: 768px) {
  .chat-input {
    font-size: 0.8125rem;
    min-height: 38px;
  }
}

.chat-input:focus {
  border-color: var(--color-accent);
  background: var(--color-surface);
}

.chat-send-btn {
  padding: 8px 16px;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.chat-send-btn:hover {
  background: var(--color-accent-hover);
}

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

/* Chat Modals */
.chat-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  z-index: var(--z-overlay);
}

.chat-modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  width: 440px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}

.chat-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.chat-modal-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.0625rem;
  color: var(--color-text);
}

.chat-modal-close {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.chat-modal-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.chat-modal-field {
  margin-bottom: var(--space-md);
}

.chat-modal-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-modal-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  outline: none;
}

.chat-modal-input:focus {
  border-color: var(--color-accent);
}

.chat-modal-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  background: var(--color-surface);
  outline: none;
}

/* Member picker */
.chat-member-picker {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-top: 4px;
}

.chat-member-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 10px;
  cursor: pointer;
  transition: var(--transition);
}

.chat-member-item:hover {
  background: var(--color-bg);
}

.chat-member-item.selected {
  background: #e0f7f5;
}

.chat-member-checkbox {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.625rem;
  color: #fff;
  transition: var(--transition);
}

.chat-member-item.selected .chat-member-checkbox {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.chat-member-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text);
}

.chat-member-role {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
}

.chat-modal-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
  margin-top: var(--space-lg);
}

/* Group settings members list */
.chat-settings-members {
  margin-top: var(--space-sm);
}

.chat-settings-member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
}

.chat-settings-member:last-child {
  border-bottom: none;
}

.chat-settings-member-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-settings-member-remove {
  background: none;
  border: none;
  color: var(--color-error);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.chat-settings-member-remove:hover {
  background: var(--color-error-bg);
}

/* Nav unread badge */
.nav-link .chat-unread-badge {
  margin-left: auto;
  font-size: 0.625rem;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
}

/* Responsive */
@media (max-width: 768px) {
  .chat-sidebar {
    width: 100%;
    min-width: unset;
  }

  .chat-main {
    display: none;
  }

  .chat-container.conv-active .chat-sidebar {
    display: none;
  }

  .chat-container.conv-active .chat-main {
    display: flex;
  }

  .chat-message {
    max-width: 90%;
  }
}
