/* ==============================================================================
   AQUAFLOW RO SYSTEMS — COMMERCIAL ADMIN DASHBOARD STYLESHEET
   Clean, modern, business-focused, desktop-first design system
   ============================================================================== */

:root {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: #1e293b;
  
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;
  --text-sidebar: #94a3b8;
  --text-sidebar-active: #ffffff;
  
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-subtle: #e0f2fe;
  
  --status-active: #10b981;
  --status-warning: #f59e0b;
  --status-danger: #ef4444;
  --status-offline: #94a3b8;
  
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.08);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
}

/* App Container */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 250px;
  min-width: 250px;
  background-color: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: transform 0.2s ease;
}

.sidebar-header {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-title {
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 8px;
  background: #ffffff;
  padding: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  display: block;
}

.header-brand-logo {
  display: none;
  width: 30px;
  height: 30px;
  object-fit: contain;
  border-radius: 7px;
  background: #ffffff;
  padding: 2px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  margin-right: 6px;
}

@media (max-width: 992px) {
  .header-brand-logo {
    display: inline-block;
  }
}

.brand-dot {
  width: 8px;
  height: 8px;
  background-color: #38bdf8;
  border-radius: 50%;
  display: inline-block;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  margin-bottom: 3px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.nav-item:hover {
  background-color: var(--bg-sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background-color: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  font-weight: 600;
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.nav-item svg {
  width: 16px;
  height: 16px;
  margin-right: 12px;
  stroke-width: 2;
  opacity: 0.85;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: var(--text-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Main Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--bg-app);
}

/* Header */
.top-header {
  height: 60px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.sidebar-toggle-btn {
  display: none;
  background: none;
  border: 1px solid var(--border-subtle);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  background-color: #f1f5f9;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.live-dot {
  width: 7px;
  height: 7px;
  background-color: var(--status-active);
  border-radius: 50%;
  display: inline-block;
}

.header-date {
  font-size: 13px;
  color: var(--text-muted);
}

.admin-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
}

.admin-avatar {
  width: 28px;
  height: 28px;
  background-color: #e2e8f0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
}

.btn-logout {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-logout:hover {
  background-color: #fee2e2;
  color: var(--status-danger);
  border-color: #fecaca;
}

/* Content Area */
.content-area {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* KPI Summary Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

/* Clickable KPI Cards Navigation */
.kpi-card[role="button"] {
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.kpi-card[role="button"]:hover {
  border-color: var(--primary);
  box-shadow: 0 3px 8px 0 rgba(2, 132, 199, 0.14);
  transform: translateY(-1px);
}

.kpi-card[role="button"]:active {
  transform: translateY(0);
}

.kpi-card[role="button"]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi-subtext {
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: 4px;
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.section-actions {
  display: flex;
  gap: 10px;
}

/* Standard Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s, border-color 0.15s;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: #ffffff;
  border-color: var(--border-strong);
  color: var(--text-main);
}

.btn-secondary:hover {
  background-color: #f1f5f9;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* Data Tables */
.table-card,
.table-responsive {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  width: 100%;
  margin-bottom: 24px;
}

.table-card::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar {
  height: 6px;
}

.table-card::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

.table-card::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.table-card::-webkit-scrollbar-thumb:hover,
.table-responsive::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.data-table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  background-color: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table code {
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.data-table td:not(.col-details) > div {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.shope-sale-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* Details Column — Desktop / Laptop */
.data-table th.col-details {
  min-width: 220px;
  max-width: 440px;
  white-space: normal !important;
}

.data-table td.col-details {
  min-width: 220px;
  max-width: 440px;
  white-space: normal !important;
  vertical-align: top;
}

.data-table td.col-details > .details-cell-text,
.data-table td.col-details .details-cell-text,
.details-cell {
  display: flex !important;
  flex-direction: column !important;
  gap: 2px !important;
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.5;
  font-size: 13px;
  color: var(--text-main);
  text-align: left;
}

.details-cell .details-line,
.details-cell-text .details-line {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.45;
}

/* ==========================================================================
   Customer Directory Table — Scoped Column Widths & Address Wrapping
   Prevents address text from overflowing or overlapping adjacent columns.
   ========================================================================== */
#view-customers .data-table {
  table-layout: auto;
  width: 100%;
}

#view-customers .col-cust-id {
  white-space: nowrap !important;
  min-width: 95px;
}

#view-customers .col-cust-name {
  white-space: nowrap !important;
  min-width: 140px;
}

#view-customers .col-cust-address {
  white-space: normal !important;
  min-width: 200px;
  max-width: 320px;
  vertical-align: top;
  word-break: normal;
  overflow-wrap: break-word;
}

#view-customers .customer-address-cell {
  display: block !important;
  width: 100%;
  min-width: 190px;
  max-width: 320px;
  white-space: normal !important;
  word-break: normal;
  overflow-wrap: break-word;
  line-height: 1.45;
  font-size: 13px;
  color: var(--text-main);
  text-align: left;
}

#view-customers .col-cust-area {
  white-space: nowrap !important;
  min-width: 125px;
}

#view-customers .col-cust-city {
  white-space: nowrap !important;
  min-width: 85px;
}

#view-customers .col-cust-phone {
  white-space: nowrap !important;
  min-width: 115px;
}

#view-customers .col-cust-type {
  white-space: nowrap !important;
  min-width: 105px;
}

#view-customers .col-cust-model {
  white-space: nowrap !important;
  min-width: 120px;
}

#view-customers .col-cust-install-date {
  white-space: nowrap !important;
  min-width: 125px;
}

#view-customers table.data-table th.sortable-th {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

#view-customers table.data-table th.sortable-th:hover {
  background-color: #f1f5f9;
  color: #0284c7;
}

#view-customers table.data-table th.sortable-th:hover .sort-indicator {
  opacity: 1 !important;
}

#view-customers .col-cust-actions {
  white-space: nowrap !important;
  min-width: 210px;
}

#view-customers .customer-actions-cell {
  display: inline-flex !important;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap !important;
  white-space: nowrap !important;
}

#view-customers .customer-actions-cell .btn {
  white-space: nowrap !important;
}

.data-table td .btn,
.data-table td button {
  white-space: nowrap;
  flex-shrink: 0;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.clickable-row {
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.clickable-row:hover {
  background-color: #f1f5f9 !important;
}

/* Notification Center Row States */
.notification-row-unread {
  background-color: #f8fafc;
  font-weight: 500;
}

.notification-row-unread td strong {
  color: var(--primary);
}

.notification-row-read {
  opacity: 0.88;
}

/* Worker Identity Presentation: Primary Name, Secondary ID */
.worker-identity-cell {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.25;
  text-align: left;
  white-space: nowrap;
}

.worker-primary-name {
  font-weight: 600;
  color: var(--text-main);
  font-size: 13px;
  white-space: nowrap;
}

.worker-secondary-id {
  font-size: 11px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

/* Subtle Status Indicators */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.active { background-color: var(--status-active); }
.status-dot.offline { background-color: var(--status-offline); }
.status-dot.warning { background-color: var(--status-warning); }
.status-dot.danger { background-color: var(--status-danger); }

/* Empty States */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-subtle);
}

.empty-state p {
  font-size: 14px;
  margin-top: 8px;
  color: var(--text-muted);
}

/* Filter / Search Bar */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  max-width: 360px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 13px;
  background-color: #ffffff;
  outline: none;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.date-select {
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 13px;
  background-color: #ffffff;
  outline: none;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  padding: 16px;
  overflow-y: auto;
}

.modal-overlay.active {
  display: flex;
}

.modal-dialog,
.modal-container {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  margin: auto;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1 1 auto;
  max-height: calc(90vh - 130px);
}

.modal-footer {
  padding: 14px 20px;
  background-color: #f8fafc;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* Form Groups */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 13px;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

/* Calculation Preview Box */
.calc-preview-box {
  background-color: #f1f5f9;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-top: 14px;
  font-size: 12px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.calc-row:last-child {
  margin-bottom: 0;
  padding-top: 6px;
  border-top: 1px dashed var(--border-strong);
  font-weight: 600;
}

/* Breadcrumb */
.breadcrumb-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.breadcrumb-nav a {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}

.breadcrumb-nav a:hover {
  text-decoration: underline;
}

/* Mobile Backdrop & Sidebar Close Button */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

.sidebar-close-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-sidebar);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background-color 0.15s;
}

.sidebar-close-btn:hover {
  color: #ffffff;
  background-color: var(--bg-sidebar-hover);
}

/* Service Spares Rows inside Add Work Modal */
.service-spare-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

/* Settings Page Modular Grid & Cards */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.settings-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.settings-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px dashed #f1f5f9;
  font-size: 13px;
  gap: 12px;
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-label {
  color: var(--text-muted);
  font-weight: 500;
  flex: 1;
}

.settings-value {
  color: var(--text-main);
  font-weight: 600;
  text-align: right;
  flex: 1;
}

.settings-badge-ok {
  display: inline-block;
  padding: 2px 8px;
  background: #ecfdf5;
  color: #065f46;
  border-radius: 4px;
  font-weight: 600;
  font-size: 11px;
}

.settings-badge-info {
  display: inline-block;
  padding: 2px 8px;
  background: #e0f2fe;
  color: #0369a1;
  border-radius: 4px;
  font-weight: 600;
  font-size: 11px;
}

.settings-badge-warn {
  display: inline-block;
  padding: 2px 8px;
  background: #fffbeb;
  color: #92400e;
  border-radius: 4px;
  font-weight: 600;
  font-size: 11px;
}

/* ==============================================================================
   RESPONSIVE DESIGN SYSTEM — ALL DEVICE BREAKPOINTS
   Desktop monitors, laptops, tablets (portrait/landscape), phones (portrait/landscape)
   ============================================================================== */

/* Ultra-wide Monitors (>= 1600px) */
@media (min-width: 1600px) {
  .app-container {
    max-width: 1920px;
    margin: 0 auto;
  }
}

/* Laptops and Desktops (<= 1200px) */
@media (max-width: 1200px) {
  .sidebar {
    width: 230px;
    min-width: 230px;
  }
  .top-header {
    padding: 0 20px;
  }
  .content-area {
    padding: 20px;
  }
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
  }
}

/* Tablets (Portrait & Landscape: <= 992px) */
@media (max-width: 992px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    width: 270px;
    max-width: 82vw;
    z-index: 999;
    transform: translateX(-100%);
    box-shadow: none;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  }

  .sidebar-header {
    justify-content: space-between;
  }

  .sidebar-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    min-height: 38px;
    font-size: 20px;
    cursor: pointer;
  }

  .sidebar-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    min-height: 38px;
    padding: 0;
    font-size: 18px;
  }

  .top-header {
    padding: 0 16px;
    gap: 10px;
  }

  .content-area {
    padding: 18px 16px;
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  .settings-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 14px;
  }
}

/* Mobile Phones (Landscape & Portrait: <= 768px) */
@media (max-width: 768px) {
  body {
    font-size: 13.5px;
  }

  .top-header {
    min-height: 54px;
    height: auto;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-left {
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
  }

  .page-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
  }

  .header-right {
    gap: 8px;
    flex-wrap: wrap;
  }

  .header-date {
    display: none; /* Hide date on small screen to prevent overflow */
  }

  .admin-badge span {
    display: none; /* Keep avatar badge, hide text */
  }

  .admin-avatar {
    width: 26px;
    height: 26px;
    font-size: 10px;
  }

  .btn-logout {
    padding: 6px 12px;
    font-size: 12px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  #btnSyncApkData {
    padding: 6px 12px !important;
    font-size: 12px !important;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .content-area {
    padding: 14px 12px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
  }

  .kpi-card {
    padding: 12px 12px;
  }

  .kpi-label {
    font-size: 10.5px;
    margin-bottom: 4px;
  }

  .kpi-value {
    font-size: 18px;
  }

  .kpi-subtext {
    font-size: 11px;
  }

  .section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 14px;
  }

  .section-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }

  .section-actions button,
  .section-header button {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 36px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: 100%;
  }

  .search-input {
    max-width: 100%;
    width: 100%;
    min-height: 38px;
    font-size: 16px;
  }

  .date-select,
  .form-control,
  select.form-control,
  input.form-control,
  textarea.form-control {
    width: 100%;
    min-height: 38px;
    font-size: 16px;
  }

  /* Tables: Controlled internal scroll, zero whole-page overflow */
  .table-card,
  .table-responsive {
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    max-width: 100%;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    width: 100%;
    min-width: max-content;
  }

  .data-table th,
  .data-table td {
    padding: 10px 14px;
    font-size: 12.5px;
    white-space: nowrap;
  }

  .data-table td .btn,
  .data-table td button {
    min-height: 32px;
    padding: 5px 10px;
  }

  /* Details Column Mobile: natural wrapping, no clamp, multi-line display */
  .data-table th.col-details {
    min-width: 170px;
    max-width: 320px;
    white-space: normal !important;
  }

  .data-table td.col-details {
    min-width: 170px;
    max-width: 320px;
    width: auto;
    white-space: normal !important;
    vertical-align: top;
  }

  .data-table td.col-details > .details-cell-text,
  .data-table td.col-details .details-cell-text,
  .details-cell {
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
    -webkit-line-clamp: unset !important;
    line-clamp: unset !important;
    max-height: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: normal;
    line-height: 1.45;
    font-size: 12px;
  }

  /* Modals on Mobile */
  .modal-overlay {
    padding: 8px;
    align-items: center;
  }

  .modal-dialog,
  .modal-container {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 94vh;
    max-height: 94dvh;
    margin: auto;
  }

  .modal-header {
    padding: 12px 14px;
  }

  .modal-title {
    font-size: 15px;
  }

  .modal-body {
    padding: 14px 12px;
    max-height: calc(94vh - 115px);
    max-height: calc(94dvh - 115px);
  }

  .modal-footer {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  .modal-footer button {
    flex: 1 1 auto;
    min-height: 38px;
    justify-content: center;
  }

  /* Multi-column form grids inside modal stack to single column on mobile */
  #modalAddWorkRecord div[style*="grid-template-columns: 1fr 1fr"],
  #modalAddCustomer div[style*="grid-template-columns: 1fr 1fr"],
  #modalEditCustomer div[style*="grid-template-columns: 1fr 1fr"],
  #modalEditService div[style*="grid-template-columns: 1fr 1fr"],
  .form-grid-2col {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  /* Activity Category Tabs Mobile: single horizontal scrollable row */
  #activityCategoryTabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 8px;
  }

  #activityCategoryTabs .act-tab-btn {
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }

  /* Assembly Adjustment History table container horizontal scroll */
  #asmHistoryTableContainer {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Service Spares Rows inside Modal */
  .service-spare-row {
    background: #f8fafc;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 8px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .service-spare-row .spare-row-select {
    flex: 1 1 100% !important;
    min-height: 36px;
  }

  .service-spare-row .spare-row-qty {
    flex: 1 1 65px !important;
    min-height: 34px;
  }

  .service-spare-row .spare-row-van-stock {
    flex: 1 1 auto;
    font-size: 11px;
  }

  /* Settings Grid & Rows on Mobile */
  .settings-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .settings-card {
    padding: 14px 12px;
  }

  .settings-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 8px 0;
  }

  .settings-value {
    text-align: left;
    width: 100%;
    word-break: break-all;
  }
}

/* Responsive adjustments for phones <= 480px */
@media (max-width: 480px) {
  #toastNotification {
    top: 10px !important;
    right: 10px !important;
    left: 10px !important;
    min-width: 0 !important;
    max-width: calc(100% - 20px) !important;
  }

  /* Edit Assembly Quantity Modal Status Cards: 2-column grid on small phones */
  #editAssembleQtyDisplay {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 6px !important;
  }
}

/* Extra Small Phones (<= 400px) */
@media (max-width: 400px) {
  .page-title {
    max-width: 130px;
    font-size: 14px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .kpi-card {
    padding: 10px 8px;
  }

  .kpi-value {
    font-size: 16px;
  }

  .live-indicator span:last-child {
    display: none; /* Show dot only on extra small screen */
  }

  #btnSyncApkData svg {
    margin: 0;
  }
}

/* Login Screen Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background-color: #0f172a;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.login-modal-box {
  background: #ffffff;
  border-radius: 8px;
  width: 100%;
  max-width: 400px;
  padding: 32px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  border: 1px solid #334155;
  margin: auto;
}

.login-brand-logo-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
}

.login-brand-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: 18px;
  background: #ffffff;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.06);
  display: block;
}

/* ==========================================================================
   APP STARTUP SPLASH SCREEN & OPENING ANIMATION
   ========================================================================== */
.app-splash-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000000;
  background-color: #0b1120;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.35s ease;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  will-change: opacity, visibility;
}

.app-splash-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app-splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  animation: splashFadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  will-change: transform, opacity;
}

.app-splash-logo-box {
  width: 112px;
  height: 112px;
  border-radius: 24px;
  background: #ffffff;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  animation: splashLogoScale 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  will-change: transform;
}

.app-splash-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.app-splash-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.app-splash-title {
  color: #ffffff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.app-splash-subtitle {
  color: #94a3b8;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

@keyframes splashFadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@keyframes splashLogoScale {
  0% {
    transform: scale(0.88);
  }
  100% {
    transform: scale(1);
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .app-splash-overlay {
    animation: none !important;
    transition: none !important;
    display: none !important;
  }
  .app-splash-content,
  .app-splash-logo-box {
    animation: none !important;
  }
}

/* Mobile responsive adjustments */
@media (max-width: 480px) {
  .app-splash-logo-box {
    width: 96px;
    height: 96px;
    border-radius: 20px;
    margin-bottom: 16px;
  }
  .app-splash-title {
    font-size: 15px;
  }
  .app-splash-subtitle {
    font-size: 12px;
  }
  .login-brand-logo {
    width: 70px;
    height: 70px;
    border-radius: 16px;
  }
}

@media (max-width: 340px) {
  .app-splash-logo-box {
    width: 84px;
    height: 84px;
    border-radius: 18px;
  }
  .app-splash-title {
    font-size: 13px;
  }
  .login-brand-logo {
    width: 64px;
    height: 64px;
  }
}

/* ==========================================================================
   Table Action Buttons Touch Spacing (320px and Below)
   Ensures clear separation between adjacent actions (e.g. Edit vs Return)
   without modifying desktop/tablet layout or converting tables.
   ========================================================================== */
@media (max-width: 320px) {
  /* Action button container gap inside table cells */
  .data-table td > div,
  .data-table td:not(.col-details) > div,
  .shope-sale-actions {
    gap: 10px !important;
  }

  /* Specific touch separation for Shope Sales action buttons */
  .shope-sale-actions {
    display: inline-flex !important;
    gap: 10px !important;
    align-items: center !important;
  }

  .shope-sale-actions button,
  .shope-sale-actions .btn {
    padding: 4px 10px !important;
    min-height: 28px !important;
    font-size: 11px !important;
    line-height: 1.2 !important;
  }

  /* Adjacent button margin fallback to ensure comfortable physical gap */
  .data-table td .btn + .btn,
  .data-table td button + button,
  .shope-sale-actions button + button,
  .shope-sale-actions .btn + .btn {
    margin-left: 2px !important;
  }
}

/* ==========================================================================
   MONTHLY SERVICE REPORTS STYLING
   ========================================================================== */
.btn-success {
  background-color: #10b981;
  color: #ffffff !important;
  border: 1px solid #059669;
  cursor: pointer;
}
.btn-success:hover {
  background-color: #059669;
  color: #ffffff !important;
}
.btn-danger {
  background-color: #ef4444;
  color: #ffffff !important;
  border: 1px solid #dc2626;
  cursor: pointer;
}
.btn-danger:hover {
  background-color: #dc2626;
  color: #ffffff !important;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@media (max-width: 768px) {
  .monthly-report-toolbar > div {
    flex-direction: column;
    align-items: stretch !important;
  }
  .monthly-report-toolbar > div > div {
    width: 100%;
    justify-content: stretch;
  }
  .monthly-report-toolbar select,
  .monthly-report-toolbar button {
    width: 100%;
  }
}

/* Responsive Customer Summary Cards */
.customer-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
.customer-summary-card {
  padding: 14px 16px;
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.customer-summary-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

@media (max-width: 992px) {
  .customer-summary-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
}

@media (max-width: 520px) {
  .customer-summary-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .customer-summary-card {
    padding: 10px 12px !important;
  }
  .customer-summary-card .kpi-value {
    font-size: 18px !important;
  }
}

/* Office Stock Search Bar */
.office-stock-search-wrapper {
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.office-stock-search-wrapper .search-box-container {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 400px;
  display: flex;
  align-items: center;
}
.office-stock-search-wrapper .search-input {
  width: 100%;
  padding-left: 36px;
  padding-right: 32px;
}
.office-stock-search-wrapper .search-clear-btn {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  font-size: 14px;
  font-weight: bold;
  color: var(--text-muted, #94a3b8);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 50%;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.office-stock-search-wrapper .search-clear-btn:hover {
  color: var(--text-primary, #0f172a);
  background: #f1f5f9;
}
@media (max-width: 520px) {
  .office-stock-search-wrapper .search-box-container {
    max-width: 100%;
    width: 100%;
  }
}



