/**
 * Sangri Agency Order Portal - Premium Design System
 * State-of-the-art modern dashboard aesthetics with rich glassmorphism and vibrant color tokens.
 */

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  --accent: #06b6d4;
  --accent-hover: #0891b2;
  
  --bg-app: #090d16;
  --bg-sidebar: #0f1524;
  --bg-topbar: rgba(15, 21, 36, 0.85);
  --bg-card: #141c2e;
  --bg-card-hover: #19233a;
  --bg-input: #1a233a;
  
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.6);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 14px;
  overflow-x: hidden;
  background-image: 
    radial-gradient(at 15% 15%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
    radial-gradient(at 85% 85%, rgba(6, 182, 212, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
}

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

/* Sidebar Navigation */
.sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.brand-logo svg {
  width: 22px;
  height: 22px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 17px;
  color: var(--text-main);
  letter-spacing: -0.3px;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  padding: 20px 12px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 1px;
  padding: 16px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: all 0.2s ease;
  position: relative;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-item:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.04);
  transform: translateX(3px);
}

.nav-item.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.25), rgba(99, 102, 241, 0.05));
  border-left: 3px solid var(--primary);
  font-weight: 600;
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  background: var(--primary);
  color: #fff;
}

.nav-badge.glow {
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.6);
}

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

.system-status-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 12px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--success);
  font-weight: 600;
  margin-bottom: 4px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
}

.status-dot.pulse {
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.status-details {
  color: var(--text-muted);
  font-size: 11px;
}

/* Main Content Wrapper */
.main-wrapper {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Fullscreen Mode for Order Form & Full Width Views */
body.fullscreen-mode .sidebar,
body.fullscreen-mode .sidebar-backdrop {
  transform: translateX(-100%) !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.fullscreen-mode .main-wrapper {
  margin-left: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
}

body.fullscreen-mode .content-body {
  padding: 16px 28px !important;
  max-width: 100% !important;
}

/* Top Navigation Bar */
.top-navbar {
  height: 70px;
  background-color: var(--bg-topbar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.navbar-left, .navbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-header-info {
  display: flex;
  flex-direction: column;
}

.top-title {
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.top-breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
}

.quick-stats-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fff;
}

.btn-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  background: rgba(16, 185, 129, 0.25);
  color: #fff;
}

/* Content Body */
.content-body {
  padding: 28px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Cards & Containers */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s ease;
}

.card-hover:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-md);
}

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

.card-title {
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
}

/* KPI Summary Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.kpi-card {
  background: linear-gradient(145deg, var(--bg-card), rgba(20, 28, 46, 0.6));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle, var(--primary-light) 0%, transparent 70%);
  opacity: 0.5;
  pointer-events: none;
}

.kpi-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.kpi-icon.blue { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.kpi-icon.indigo { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.kpi-icon.emerald { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.kpi-icon.amber { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.kpi-icon.cyan { background: rgba(6, 182, 212, 0.15); color: #22d3ee; }

.kpi-content {
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-value {
  font-family: 'Outfit', sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 2px;
}

/* Forms & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

select.form-control {
  cursor: pointer;
}

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

/* Tables */
.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.table th {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-size: 13px;
}

.table tbody tr {
  transition: background-color 0.15s ease;
}

.table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

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

/* Badges & Status Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-success .badge-dot { background: #34d399; }

.badge-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-warning .badge-dot { background: #fbbf24; }

.badge-danger { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-danger .badge-dot { background: #f87171; }

.badge-info { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.badge-info .badge-dot { background: #60a5fa; }

.badge-purple { background: rgba(139, 92, 246, 0.15); color: #c4b5fd; }
.badge-purple .badge-dot { background: #c4b5fd; }

/* Filter & Search Bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 250px;
}

.search-box svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
}

.search-box input {
  padding-left: 42px;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(9, 13, 22, 0.8);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 600px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  animation: modalFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-sm { max-width: 420px; }
.modal-lg { max-width: 850px; }

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(0, 0, 0, 0.15);
  border-bottom-left-radius: var(--radius-xl);
  border-bottom-right-radius: var(--radius-xl);
}

/* Flash & Alert Banners */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13.5px;
  margin-bottom: 4px;
}

.alert-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 280px;
  padding: 14px 18px;
  background-color: #1e293b;
  color: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(50px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Order Form Specific Styles */
.line-items-wrapper {
  margin-top: 10px;
  overflow: visible !important;
  min-height: 240px;
}

.order-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}

.order-number-input {
  max-width: 170px !important;
}

.date-input {
  max-width: 145px !important;
}

.status-select {
  max-width: 150px !important;
}

.order-form-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 24px;
  flex-wrap: wrap;
  gap: 20px;
}

.order-form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.order-totals-box {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 100%;
  max-width: 380px;
  margin-left: auto;
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.total-row.grand-total {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

/* Mobile Sidebar Overlay Backdrop */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(9, 13, 22, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 45;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.sidebar-backdrop.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Responsive Utilities */
@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0;
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 768px) {
  body {
    font-size: 13.5px;
  }

  .content-body {
    padding: 14px 12px;
    gap: 16px;
  }

  /* Top Navigation Bar on Mobile */
  .top-navbar {
    height: auto;
    padding: 12px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    position: sticky;
    top: 0;
  }

  .navbar-left {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
  }

  .page-header-info {
    flex: 1;
    min-width: 0;
  }

  .top-title {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .top-breadcrumb {
    font-size: 11px;
    display: none;
  }

  .navbar-right {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }

  .navbar-right .btn-primary {
    flex: 1;
    padding: 8px 14px;
    font-size: 13px;
  }

  .quick-stats-pill {
    display: none;
  }

  /* KPI Grid & Cards on Mobile */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .kpi-card {
    padding: 14px 12px;
    gap: 10px;
  }

  .kpi-icon {
    width: 42px;
    height: 42px;
    font-size: 20px;
  }

  .kpi-icon svg {
    width: 20px;
    height: 20px;
  }

  .kpi-label {
    font-size: 10.5px;
  }

  .kpi-value {
    font-size: 20px;
  }

  /* Cards General */
  .card {
    padding: 16px 14px;
    border-radius: var(--radius-md);
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 12px;
  }

  .card-title {
    font-size: 16px;
  }

  /* Form Elements on Mobile */
  .form-group {
    margin-bottom: 14px;
  }

  .form-label {
    font-size: 13px;
  }

  .form-control {
    font-size: 15px; /* Prevents auto-zoom in iOS Safari */
    padding: 10px 12px;
    min-height: 42px;
  }

  /* Filter & Search Bars */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .search-box {
    width: 100%;
    min-width: 100%;
  }

  .filter-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .filter-actions form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }

  .filter-actions form .form-control,
  .filter-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Modals on Mobile */
  .modal-overlay {
    padding: 10px;
  }

  .modal-card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh;
    border-radius: var(--radius-lg);
  }

  .modal-header {
    padding: 14px 16px;
  }

  .modal-body {
    padding: 16px 14px;
  }

  /* Auto collapse any multi-column grid inside modal forms */
  .modal-body [style*="grid-template-columns"],
  .modal-body .form-grid-2,
  .modal-body .form-grid-3 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .modal-footer {
    padding: 12px 16px;
    flex-direction: column-reverse;
    gap: 8px;
  }

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

  /* Order Form Specific Tablet/Mobile Layout */
  .order-form-grid,
  #mainOrderForm .order-form-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 14px !important;
  }

  .order-form-footer {
    flex-direction: column-reverse !important;
    align-items: stretch !important;
    gap: 16px !important;
    margin-top: 20px !important;
  }

  .order-form-actions {
    width: 100%;
    flex-direction: column !important;
    gap: 10px !important;
  }

  .order-form-actions .btn {
    width: 100%;
    justify-content: center;
    min-height: 48px !important;
    font-size: 15px !important;
  }

  .order-totals-box {
    max-width: 100% !important;
    width: 100% !important;
    padding: 16px;
    margin-left: 0 !important;
  }

  .location-filter-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }

  .location-filter-tabs .btn {
    flex-shrink: 0;
  }

  .total-row {
    font-size: 13.5px;
  }

  .total-row.grand-total {
    font-size: 17px;
  }

  /* Tables Touch Scrolling & Mobile Tap Sizes */
  .table-container {
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
    overflow-x: auto !important;
  }

  #orderItemsTable {
    min-width: 780px;
  }

  #orderItemsTable th, 
  #orderItemsTable td {
    padding: 8px 6px;
  }

  .form-control,
  select.form-control,
  input.form-control {
    min-height: 40px;
    font-size: 13.5px;
  }

  .row-qty {
    min-width: 75px !important;
    height: 40px !important;
    font-size: 13.5px !important;
    text-align: center !important;
    font-weight: 600 !important;
  }

  .row-price {
    min-width: 105px !important;
    height: 40px !important;
    font-size: 13.5px !important;
    text-align: right !important;
    font-weight: 600 !important;
  }

  .group-select {
    min-width: 140px !important;
    height: 40px !important;
    font-size: 13px !important;
  }

  .rate-choice-select {
    min-width: 135px !important;
    height: 40px !important;
    font-size: 12.5px !important;
  }

  .row-unit {
    min-width: 55px !important;
    height: 40px !important;
    text-align: center !important;
    font-size: 13px !important;
  }

  .btn-icon.btn-danger {
    min-width: 36px !important;
    min-height: 36px !important;
    font-size: 18px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .table th, .table td {
    padding: 10px 8px;
    font-size: 12.5px;
  }

  .table td strong {
    font-size: 12.5px;
  }

  /* Flash banners & Toasts */
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 16px;
  }

  .toast {
    min-width: unset;
    width: 100%;
  }

  .signatures { 
    grid-template-columns: 1fr; 
    gap: 30px; 
  }
  
  .grid-info { 
    grid-template-columns: 1fr; 
    gap: 16px; 
  }
}

@media (max-width: 640px) {
  .order-form-grid,
  #mainOrderForm .order-form-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .content-body {
    padding: 14px 10px !important;
    gap: 14px !important;
  }

  .card {
    padding: 14px 10px !important;
  }

  .card-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .card-header .btn {
    width: 100% !important;
    justify-content: center !important;
  }
}

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

  .top-title {
    font-size: 14px;
  }

  .btn {
    padding: 9px 14px;
    font-size: 13px;
    min-height: 40px;
  }

  .btn-sm {
    padding: 6px 10px;
    font-size: 12px;
    min-height: 32px;
  }

  .btn-lg {
    padding: 11px 16px;
    font-size: 14px;
    min-height: 44px;
  }

  .card {
    padding: 12px 8px;
  }

  .modal-body {
    padding: 12px 8px;
  }
}

/* ==========================================================================
   TomSelect & Item Select Touch & Mobile Customizations
   ========================================================================== */
.ts-wrapper.item-select {
  width: 100% !important;
  min-width: 240px !important;
}

.ts-wrapper.item-select .ts-control {
  border: 1px solid rgba(99, 102, 241, 0.35) !important;
  background-color: var(--bg-input) !important;
  color: var(--text-main) !important;
  font-weight: 500 !important;
  min-height: 38px !important;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  white-space: normal !important;
  line-height: 1.35 !important;
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  font-size: 13px !important;
}

.ts-wrapper.item-select .ts-control .item {
  color: var(--text-main) !important;
  white-space: normal !important;
  word-break: break-word !important;
  font-size: 13px !important;
  font-weight: 600 !important;
}

.ts-wrapper.item-select .ts-control input {
  color: var(--text-main) !important;
  font-size: 13px !important;
  min-height: 24px !important;
}

.ts-wrapper.item-select.focus .ts-control {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25) !important;
}

.ts-dropdown {
  position: absolute !important;
  background-color: #141c2e !important;
  border: 1px solid rgba(99, 102, 241, 0.4) !important;
  color: var(--text-main) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.08) !important;
  z-index: 999999 !important;
  min-width: min(100%, 420px) !important;
  max-width: calc(100vw - 24px) !important;
}

.ts-dropdown .ts-dropdown-content,
.ts-dropdown .dropdown-content {
  max-height: 340px !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

.ts-dropdown .option {
  padding: 9px 12px !important;
  min-height: 36px !important;
  font-size: 13px !important;
  color: var(--text-main) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  white-space: normal !important;
  line-height: 1.4 !important;
  word-break: break-word !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
}

.ts-dropdown .active {
  background-color: rgba(99, 102, 241, 0.28) !important;
  color: #fff !important;
}

.ts-dropdown .selected {
  background-color: rgba(99, 102, 241, 0.45) !important;
  color: #fff !important;
  font-weight: 700 !important;
}
