/* ============================================================
   SENTINELLA v2 — Complete Design System
   Mobile-first, dark mode, glassmorphism
   ============================================================ */

/* ============================================================
   CSS CUSTOM PROPERTIES
   ============================================================ */
:root {
  /* Colors */
  --bg-primary:     #070d1a;
  --bg-secondary:   #0d1629;
  --bg-card:        rgba(13, 22, 41, 0.85);
  --glass-bg:       rgba(14, 25, 50, 0.7);
  --glass-border:   rgba(56, 189, 248, 0.12);
  --glass-inner:    rgba(255,255,255,0.03);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;

  --cyan:     #38bdf8;
  --cyan-dim: rgba(56,189,248,0.15);
  --emerald:  #10b981;
  --emerald-dim: rgba(16,185,129,0.15);
  --blue:     #3b82f6;
  --blue-dim: rgba(59,130,246,0.15);
  --purple:   #8b5cf6;
  --purple-dim: rgba(139,92,246,0.15);
  --amber:    #f59e0b;
  --amber-dim: rgba(245,158,11,0.15);
  --red:      #ef4444;
  --red-dim:  rgba(239,68,68,0.15);

  --sidebar-w: 240px;
  --header-h:  64px;
  --bottom-nav-h: 60px;
  --radius:    12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: all 0.2s ease;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Outfit', 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  top: -30%;
  left: -10%;
  width: 60vw;
  height: 60vw;
  background: radial-gradient(circle, rgba(56,189,248,0.04) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select, textarea { font-family: inherit; outline: none; }

.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-cyan { color: var(--cyan); }
.text-emerald { color: var(--emerald); }
.text-amber { color: var(--amber); }
.text-red { color: var(--red); }
.font-semibold { font-weight: 600; }
.font-normal { font-weight: 400; }
.text-left { text-align: left; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.w-100 { width: 100%; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }

/* ============================================================
   GLASS MORPHISM
   ============================================================ */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
}

.glass-inner {
  background: var(--glass-inner);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 1rem;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #070d1a 0%, #0d1629 50%, #091522 100%);
  padding: 1rem;
}

.login-bg-glow {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: 500px;
  height: 300px;
  background: radial-gradient(ellipse, rgba(56,189,248,0.08) 0%, transparent 70%);
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2.5rem 2rem;
  position: relative;
  z-index: 1;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  box-shadow: 0 0 30px rgba(56,189,248,0.3);
}

.login-logo-img {
  width: 90px;
  height: 90px;
  object-fit: contain;
  margin: 0 auto 1rem;
  border-radius: 50%;
  box-shadow: 0 0 25px rgba(56,189,248,0.4);
  display: block;
}

.app-brand-img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  border-radius: 50%;
  filter: drop-shadow(0 0 6px rgba(56,189,248,0.4));
}

.login-logo-icon svg { width: 36px; height: 36px; color: white; }

.login-logo h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-logo p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 0.3rem;
}

.login-error {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--red-dim);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  color: #fca5a5;
  margin-bottom: 0.8rem;
}

.login-error svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-full { width: 100%; justify-content: center; }

.login-footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 1.5rem;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: linear-gradient(180deg, #0a1428 0%, #07101f 100%);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--glass-border);
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 15px rgba(56,189,248,0.25);
}

.brand-icon { width: 20px; height: 20px; color: white; }

.logo-text h2 {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--cyan);
}

.logo-text span {
  font-size: 0.6rem;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
}

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

.nav-item:hover {
  background: rgba(56,189,248,0.08);
  color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(56,189,248,0.15), rgba(56,189,248,0.05));
  color: var(--cyan);
  border-left: 3px solid var(--cyan);
}

.nav-admin { border-top: 1px solid var(--glass-border); margin-top: 0.5rem; padding-top: 0.85rem; }

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

/* User Badge */
.user-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
  margin-bottom: 0.6rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: white;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 0.68rem; color: var(--text-muted); text-transform: capitalize; }

.btn-logout {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.btn-logout:hover { background: var(--red-dim); color: var(--red); }
.btn-logout svg { width: 14px; height: 14px; }

/* Sync Status */
.sync-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.sync-status.glow-green { background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.2); }

.indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.indicator.blink { background: var(--emerald); animation: pulse-dot 2s infinite; }
.indicator.failed { background: var(--red); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* Badge (mailbox count) */
.badge {
  background: var(--red);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  margin-left: auto;
}

/* ============================================================
   HEADER
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 2rem;
}

.content-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: var(--header-h);
  background: rgba(7,13,26,0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--glass-border);
  gap: 1rem;
}

.header-left { display: flex; align-items: center; gap: 0.75rem; }

.btn-hamburger {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-hamburger svg { width: 20px; height: 20px; }

.header-title h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.header-title p {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.header-actions { display: flex; align-items: center; gap: 0.5rem; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  transition: var(--transition);
  white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--blue));
  color: white;
  box-shadow: 0 4px 14px rgba(56,189,248,0.2);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(56,189,248,0.3); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: rgba(255,255,255,0.07);
  color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }

.btn-emerald {
  background: linear-gradient(135deg, var(--emerald), #059669);
  color: white;
  box-shadow: 0 4px 14px rgba(16,185,129,0.2);
}
.btn-emerald:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(16,185,129,0.3); }

.btn-danger {
  background: linear-gradient(135deg, var(--red), #dc2626);
  color: white;
  box-shadow: 0 4px 14px rgba(239,68,68,0.2);
}
.btn-danger:hover { transform: translateY(-1px); }

.btn-whatsapp {
  background: linear-gradient(135deg, #25d366, #128c7e);
  color: white;
  box-shadow: 0 4px 14px rgba(37,211,102,0.2);
}
.btn-whatsapp:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(37,211,102,0.3); }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
}

.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.78rem; }
.btn-sm svg { width: 13px; height: 13px; }

.btn-glow { animation: glow-pulse 2s ease-in-out infinite alternate; }
@keyframes glow-pulse {
  from { box-shadow: 0 4px 14px rgba(56,189,248,0.2); }
  to { box-shadow: 0 4px 24px rgba(56,189,248,0.45); }
}

.btn-link {
  background: none;
  color: var(--cyan);
  font-size: 0.82rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0;
  transition: var(--transition);
}
.btn-link:hover { color: white; }
.btn-link svg { width: 14px; height: 14px; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ============================================================
   TAB SECTIONS
   ============================================================ */
.tab-content {
  display: none;
  padding: 1.5rem;
  flex: 1;
}

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

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1rem;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 20px; height: 20px; color: white; }

.bg-cyan { background: linear-gradient(135deg, var(--cyan), #0ea5e9); }
.bg-emerald { background: linear-gradient(135deg, var(--emerald), #059669); }
.bg-blue { background: linear-gradient(135deg, var(--blue), #2563eb); }
.bg-purple { background: linear-gradient(135deg, var(--purple), #7c3aed); }
.bg-amber { background: linear-gradient(135deg, var(--amber), #d97706); }
.bg-red { background: linear-gradient(135deg, var(--red), #dc2626); }

.stat-info h3 { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.stat-info p { font-size: 0.72rem; color: var(--text-secondary); margin-top: 4px; }

/* ============================================================
   DASHBOARD GRID
   ============================================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

.work-orders-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
}

.span-2 { grid-column: span 2; }

/* ============================================================
   CARDS
   ============================================================ */
.card { overflow: hidden; }

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

.card-header h2 { font-size: 0.95rem; font-weight: 600; }

.view-all-link {
  font-size: 0.75rem;
  color: var(--cyan);
  font-weight: 500;
  transition: var(--transition);
}

.view-all-link:hover { color: white; }

.card-body { padding: 1.25rem; }
.card-body.flex-col { display: flex; flex-direction: column; }
.card-body.justify-center { justify-content: center; }
.card-body.align-center { align-items: center; }

/* ============================================================
   CUSTOM TABLE
   ============================================================ */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.custom-table thead tr {
  background: rgba(255,255,255,0.04);
}

.custom-table th {
  padding: 0.65rem 0.85rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.custom-table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-primary);
}

.custom-table tbody tr:hover { background: rgba(56,189,248,0.04); }

.table-total-row td {
  background: rgba(255,255,255,0.04);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--cyan) !important;
  border-top: 2px solid var(--glass-border);
}

/* Status badges */
.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-sent { background: var(--emerald-dim); color: var(--emerald); }
.badge-simulated { background: var(--blue-dim); color: var(--blue); border: 1px solid rgba(59,130,246,0.3); }
.badge-failed { background: var(--red-dim); color: var(--red); }
.badge-pending { background: rgba(100,116,139,0.15); color: var(--text-muted); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper > svg {
  position: absolute;
  left: 0.85rem;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

.input-wrapper input,
.input-wrapper select {
  width: 100%;
  padding: 0.65rem 0.85rem 0.65rem 2.4rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.88rem;
  transition: var(--transition);
}

.input-wrapper.read-only input { color: var(--text-secondary); cursor: default; }

input:not(.input-wrapper input),
select:not(.input-wrapper select),
textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.88rem;
  transition: var(--transition);
}

.input-wrapper input:focus,
.input-wrapper select:focus,
input:not(.input-wrapper input):focus,
select:not(.input-wrapper select):focus,
textarea:focus {
  border-color: var(--cyan);
  background: rgba(56,189,248,0.05);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.1);
}

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

select { appearance: none; -webkit-appearance: none; }
select option { background: var(--bg-secondary); color: var(--text-primary); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid.compact { gap: 0.75rem; }

.col-span-2 { grid-column: span 2; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.flex-3 { flex: 3; }
.flex-0 { flex: 0 0 auto; }
.align-self-end { align-self: flex-end; }

.error-msg {
  font-size: 0.75rem;
  color: var(--red);
  display: none;
}

.form-group.has-error .input-wrapper input,
.form-group.has-error .input-wrapper select,
textarea.has-error {
  border-color: var(--red);
  background: var(--red-dim);
}

.form-group.has-error .error-msg { display: block; }

.field-hint { font-size: 0.73rem; color: var(--text-muted); margin-top: 0.25rem; }

.form-divider {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--glass-border);
  padding-top: 0.75rem;
  margin: 0.75rem 0;
}

/* Toggle switch */
.toggle-switch {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  text-transform: none !important;
  letter-spacing: normal !important;
  font-size: 0.88rem !important;
  font-weight: 500 !important;
  color: var(--text-primary) !important;
}

.toggle-switch input { display: none; }

.slider {
  width: 44px;
  height: 24px;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  position: relative;
  transition: var(--transition);
  flex-shrink: 0;
}

.slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  transition: var(--transition);
}

.toggle-switch input:checked + .slider { background: var(--cyan); }
.toggle-switch input:checked + .slider::after { transform: translateX(20px); }

/* ============================================================
   FORM WIZARD
   ============================================================ */
.form-wizard {
  padding: 1.5rem;
}

.wizard-steps {
  display: flex;
  align-items: center;
  margin-bottom: 2rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  flex-shrink: 0;
}

.step-num {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.07);
  border: 2px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  transition: var(--transition);
}

.step-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.wizard-step.active .step-num { background: var(--cyan); border-color: var(--cyan); color: var(--bg-primary); }
.wizard-step.active .step-label { color: var(--cyan); }
.wizard-step.completed .step-num { background: var(--emerald); border-color: var(--emerald); color: white; }
.wizard-step.completed .step-label { color: var(--emerald); }

.wizard-line {
  flex: 1;
  height: 2px;
  background: rgba(255,255,255,0.1);
  margin: 0 0.5rem;
  align-self: flex-start;
  margin-top: 16px;
  min-width: 20px;
}

.wizard-step-content { display: none; }
.wizard-step-content.active { display: block; }

.form-section-title {
  margin-bottom: 1.5rem;
}

.form-section-title h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.3rem; }
.form-section-title p { font-size: 0.82rem; color: var(--text-secondary); }

.wizard-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--glass-border);
}

.wizard-actions .btn:first-child { margin-right: auto; }

/* ============================================================
   LABOR COST PANEL
   ============================================================ */
.labor-cost-panel {
  padding: 1.1rem;
  border-radius: var(--radius);
  background: rgba(245,158,11,0.04);
  border: 1px solid rgba(245,158,11,0.15);
}

.labor-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.labor-panel-header svg { width: 18px; height: 18px; color: var(--amber); }
.labor-panel-header h3 { font-size: 0.9rem; font-weight: 700; color: var(--amber); }

.labor-cost-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: rgba(245,158,11,0.08);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245,158,11,0.2);
}

.labor-preview-label { font-size: 0.8rem; color: var(--text-secondary); }
.labor-preview-amount { font-size: 1rem; font-weight: 700; color: var(--amber); }

/* ============================================================
   CONFIRMATION SUMMARY
   ============================================================ */
.confirmation-summary {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.summary-section {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.summary-section h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--glass-border);
}

.summary-details { font-size: 0.85rem; line-height: 1.8; }
.summary-details.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem; }
.summary-details p strong { color: var(--text-secondary); font-weight: 500; }
.summary-notes { color: var(--text-secondary); font-style: italic; }

.table-container.small .custom-table th,
.table-container.small .custom-table td { padding: 0.5rem 0.65rem; font-size: 0.8rem; }

/* Cost Breakdown Card */
.cost-breakdown-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}

.cost-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.cost-row span:first-child {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
}

.cost-row span:last-child { font-weight: 600; }

.total-row {
  background: rgba(56,189,248,0.06);
  border-bottom: none;
}

.total-row span:first-child { font-weight: 700; font-size: 0.9rem; color: var(--text-primary); }
.total-row span:last-child { font-size: 1.15rem; color: var(--cyan); font-weight: 800; }

/* ============================================================
   ALERT BOXES
   ============================================================ */
.alert-box {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  line-height: 1.5;
  margin-top: 0.75rem;
}

.alert-box svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

.info-alert { background: var(--blue-dim); border: 1px solid rgba(59,130,246,0.25); color: #93c5fd; }
.info-alert svg { color: var(--blue); }
.warning-alert { background: var(--amber-dim); border: 1px solid rgba(245,158,11,0.25); color: #fcd34d; }
.warning-alert svg { color: var(--amber); }

.info-box {
  background: rgba(56,189,248,0.06);
  border: 1px solid rgba(56,189,248,0.2);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

/* ============================================================
   MATERIALS SELECTOR
   ============================================================ */
.materials-selector-panel {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1.1rem;
}

.selector-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.custom-material-toggle { margin-top: 0.75rem; }

.custom-material-form {
  margin-top: 0.75rem;
  padding: 1rem;
}

.custom-material-form h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--cyan); }

/* ============================================================
   HISTORY TAB
   ============================================================ */
.history-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  flex: 1;
  min-width: 200px;
}

.search-box svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }

.search-box input {
  background: none;
  border: none;
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-primary);
  min-width: 100px;
}

.filter-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-box select {
  padding: 0.5rem 0.85rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.82rem;
  min-width: 120px;
}

.services-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

/* Service Card (History) */
.service-card {
  padding: 1.1rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.service-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

.service-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.service-card-client { font-size: 0.95rem; font-weight: 700; color: var(--text-primary); }
.service-card-id { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

.service-card-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.service-card-meta-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.service-card-meta-item svg { width: 13px; height: 13px; color: var(--text-muted); flex-shrink: 0; }

.service-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--glass-border);
  gap: 0.5rem;
}

.service-cost-badge {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--cyan);
}

/* ============================================================
   BRAND CHART
   ============================================================ */
.brand-chart-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.brand-bar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.82rem;
}

.brand-bar-label { width: 100px; color: var(--text-secondary); text-align: right; flex-shrink: 0; font-weight: 500; }
.brand-bar-track { flex: 1; height: 10px; background: rgba(255,255,255,0.06); border-radius: 5px; overflow: hidden; }
.brand-bar-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--cyan), var(--blue)); transition: width 0.8s ease; }
.brand-bar-count { width: 30px; color: var(--text-muted); font-size: 0.75rem; }

/* ============================================================
   STATS TAB
   ============================================================ */
.stats-controls {
  padding: 1rem;
  margin-bottom: 1rem;
}

.stats-date-range {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.stats-date-range .form-group { flex: 1; min-width: 130px; }

.stats-quick-filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.stats-charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.bar-chart-container {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 150px;
}

.month-bar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
}

.month-bar-label { width: 70px; color: var(--text-secondary); text-align: right; flex-shrink: 0; font-size: 0.75rem; }
.month-bar-track { flex: 1; height: 24px; background: rgba(255,255,255,0.04); border-radius: 4px; overflow: hidden; position: relative; }
.month-bar-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--cyan), var(--blue)); transition: width 0.8s ease; display: flex; align-items: center; padding-left: 8px; }
.month-bar-value { color: white; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.month-bar-count { width: 50px; color: var(--text-muted); font-size: 0.72rem; white-space: nowrap; }

.top-material-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.82rem;
}

.top-mat-rank {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--cyan-dim);
  color: var(--cyan);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.top-mat-name { flex: 1; color: var(--text-primary); }
.top-mat-qty { color: var(--text-muted); font-size: 0.75rem; }

/* ============================================================
   SUCCESS OVERLAY
   ============================================================ */
.success-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 10;
}

.success-content {
  text-align: center;
  max-width: 460px;
  width: 100%;
  padding: 2.5rem 2rem;
  border-radius: var(--radius-lg);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
}

.success-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--emerald), #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
  box-shadow: 0 0 40px rgba(16,185,129,0.3);
}

.success-icon svg { width: 40px; height: 40px; color: white; }

.success-content h2 { font-size: 1.25rem; font-weight: 800; margin-bottom: 0.4rem; }
.success-content > p { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 1.25rem; }

.animated.zoomIn {
  animation: zoomIn 0.3s ease forwards;
}

@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

/* ============================================================
   MAILBOX TAB
   ============================================================ */
.mailbox-layout {
  display: flex;
  height: calc(100vh - var(--header-h) - 3rem);
  overflow: hidden;
}

.mail-sidebar {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
}

.mail-sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--glass-border);
}

.mail-sidebar-header h2 { font-size: 0.9rem; font-weight: 700; margin-bottom: 2px; }
.sub-label { font-size: 0.7rem; color: var(--text-muted); }

.mail-list { flex: 1; overflow-y: auto; }

.mail-item {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  transition: var(--transition);
}

.mail-item:hover { background: rgba(56,189,248,0.06); }
.mail-item.active { background: rgba(56,189,248,0.1); border-left: 3px solid var(--cyan); }

.mail-item-from { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); margin-bottom: 3px; }
.mail-item-subject { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-item-date { font-size: 0.68rem; color: var(--text-muted); margin-top: 4px; }
.mail-item-badge { float: right; }

.mail-viewer { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.mail-viewer-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-muted);
}

.mail-viewer-empty svg { width: 48px; height: 48px; opacity: 0.3; }
.mail-viewer-empty p { font-size: 0.85rem; text-align: center; max-width: 250px; }

.mail-viewer-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.mail-header-card {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--glass-border);
  position: relative;
}

.mail-subject { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.5rem; }

.mail-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
  gap: 1rem;
}

.mail-from-to { display: flex; flex-direction: column; gap: 2px; }
.mail-date { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

.mail-badge {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
}

.mail-body-frame-container { flex: 1; overflow: hidden; }
#mail-body-frame { width: 100%; height: 100%; border: none; background: white; }

/* ============================================================
   SETTINGS TAB
   ============================================================ */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.db-sync-card { display: flex; flex-direction: column; gap: 0.85rem; }

.sync-graphic {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.25rem;
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
}

.database-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.database-node svg { width: 32px; height: 32px; color: var(--cyan); }
.database-node span { font-size: 0.72rem; color: var(--text-muted); }
.database-node.cloud svg { color: var(--blue); }

.sync-arrows svg { width: 24px; height: 24px; color: var(--emerald); }
.pulse-icon { animation: pulse-icon 1.5s ease infinite; }

@keyframes pulse-icon {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================================
   ADMIN TAB
   ============================================================ */
.admin-subtabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem;
  margin-bottom: 1rem;
  overflow-x: auto;
}

.admin-subtab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  transition: var(--transition);
  white-space: nowrap;
}

.admin-subtab svg { width: 15px; height: 15px; }
.admin-subtab:hover { background: rgba(255,255,255,0.07); color: var(--text-primary); }
.admin-subtab.active { background: rgba(56,189,248,0.12); color: var(--cyan); }

.admin-subtab-content { display: none; }
.admin-subtab-content.active { display: block; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  width: 100%;
  max-width: 650px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.modal-header h2 { font-size: 1rem; font-weight: 700; }

.btn-close {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: rgba(255,255,255,0.07);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-close:hover { background: var(--red-dim); color: var(--red); }
.btn-close svg { width: 16px; height: 16px; }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.modal-footer .btn-danger { margin-right: auto; }

/* ============================================================
   SERVICE DETAIL MODAL CONTENT
   ============================================================ */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.detail-section {
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  border: 1px solid rgba(255,255,255,0.06);
}

.detail-section h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.detail-section p { font-size: 0.83rem; color: var(--text-primary); margin-bottom: 3px; }
.detail-section p strong { color: var(--text-secondary); font-weight: 500; }

.detail-notes {
  grid-column: span 2;
}

.notes-block {
  background: rgba(255,255,255,0.03);
  border-left: 3px solid var(--blue);
  padding: 0.85rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.83rem;
  color: var(--text-secondary);
  white-space: pre-line;
  line-height: 1.6;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  backdrop-filter: blur(16px);
  border: 1px solid transparent;
  pointer-events: auto;
  animation: slideInRight 0.3s ease forwards;
  max-width: 320px;
}

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

.toast.fadeOut { animation: fadeOut 0.3s ease forwards; }

@keyframes fadeOut {
  to { opacity: 0; transform: translateX(110%); }
}

.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast-success { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.3); color: #6ee7b7; }
.toast-error   { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.3); color: #fca5a5; }
.toast-info    { background: rgba(59,130,246,0.15); border-color: rgba(59,130,246,0.3); color: #93c5fd; }
.toast-warning { background: rgba(245,158,11,0.15); border-color: rgba(245,158,11,0.3); color: #fcd34d; }

/* ============================================================
   ROTATE ANIMATION (refresh button)
   ============================================================ */
.rotate-anim { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   FLEX UTILITIES
   ============================================================ */
.flex-row { display: flex; flex-direction: row; }
.flex-col { display: flex; flex-direction: column; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.align-center { align-items: center; }

/* ============================================================
   BOTTOM NAVIGATION (Mobile only — hidden on desktop)
   ============================================================ */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  height: var(--bottom-nav-h);
  background: rgba(7,13,26,0.97);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--glass-border);
  align-items: center;
  justify-content: space-around;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.4rem 1rem;
  color: var(--text-muted);
  font-size: 0.6rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.bottom-nav-item svg { width: 20px; height: 20px; }
.bottom-nav-item.active { color: var(--cyan); }
.bottom-nav-item:hover { color: var(--text-primary); }

/* ============================================================
   OVERLAY for mobile sidebar
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0,0,0,0.5);
}

.sidebar-overlay.visible { display: block; }

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ============================================================
   MOBILE RESPONSIVE — max-width: 768px
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --header-h: 56px;
    --bottom-nav-h: 60px;
  }

  html {
    height: -webkit-fill-available;
    -webkit-text-size-adjust: 100%;
  }

  body {
    width: 100% !important;
    max-width: 100vw !important;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden !important;
    font-size: 15px;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
  }

  /* Reset WebKit/iOS native form appearance */
  input[type="text"],
  input[type="tel"],
  input[type="email"],
  input[type="number"],
  input[type="password"],
  input[type="datetime-local"],
  select,
  textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: rgba(255,255,255,0.05);
    color: var(--text-primary);
  }

  /* Prevent Safari Grid & Flex item truncation/overflow */
  .form-grid > *, 
  .dashboard-grid > *, 
  .stats-grid > *, 
  .summary-details > *,
  .cost-breakdown-card > * {
    min-width: 0;
  }

  /* Prevent container overflow */
  .main-content, .top-header, .tab-content, .glass, .modal-card, .form-wizard, .container {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* iOS Momentum Scroll for Table Containers & Modals */
  .table-container,
  .modal-body,
  .mail-list,
  .tab-content {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Show hamburger, hide certain header text */
  .btn-hamburger { display: flex; width: 40px; height: 40px; align-items: center; justify-content: center; }
  .header-title h1 { font-size: 1.15rem; }
  .header-title p { display: none; }
  .btn-quick-new span { display: none; }
  .btn-quick-new { padding: 0.5rem; width: 40px; height: 40px; justify-content: center; }

  /* Top header safe area inset for Notch / Dynamic Island */
  .top-header {
    padding-top: max(0.6rem, env(safe-area-inset-top, 0px));
  }

  /* Sidebar becomes a drawer */
  .sidebar {
    transform: translateX(-100%);
    z-index: 300;
    box-shadow: 4px 0 30px rgba(0,0,0,0.5);
    padding-top: env(safe-area-inset-top, 0px);
  }

  .sidebar.open { transform: translateX(0); }

  /* Main content fills full width with clean spacing above bottom nav and safe area */
  .main-content { 
    margin-left: 0; 
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 1.2rem) !important; 
  }

  /* Tab content padding reduction */
  .tab-content { padding: 0.75rem 0.6rem; }

  /* Form inputs & labels for touch readability */
  label {
    font-size: 0.88rem !important;
    font-weight: 600 !important;
    margin-bottom: 0.4rem;
    color: var(--text-primary) !important;
  }

  input[type="text"],
  input[type="tel"],
  input[type="email"],
  input[type="number"],
  input[type="password"],
  input[type="datetime-local"],
  select,
  textarea {
    font-size: 16px !important; /* 16px prevents iOS Safari auto-zoom on focus */
    min-height: 46px;
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
  }

  .btn {
    min-height: 46px;
    font-size: 0.92rem;
    font-weight: 600;
    padding: 0.65rem 1.1rem;
  }

  .btn-sm {
    min-height: 38px;
    font-size: 0.82rem;
    padding: 0.45rem 0.75rem;
  }

  /* Stats grid becomes 2 columns */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .stat-card { padding: 0.8rem 0.6rem; }
  .stat-icon { width: 40px; height: 40px; }
  .stat-info h3 { font-size: 1.25rem; font-weight: 700; }
  .stat-info p { font-size: 0.72rem; font-weight: 600; }

  /* Dashboard grid: single column */
  .dashboard-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }

  /* Form wizard & actions spacing */
  .form-wizard { padding: 0.85rem 0.65rem 0.5rem 0.65rem !important; }
  .form-grid { grid-template-columns: 1fr; }
  .col-span-2 { grid-column: span 1; }
  .summary-details.grid-2 { grid-template-columns: 1fr; }

  .wizard-actions {
    margin-top: 1rem;
    padding-top: 0.85rem;
    margin-bottom: 0.3rem !important;
    position: relative;
    z-index: 10;
  }

  /* Wizard steps: labels on small screens */
  .step-label { font-size: 0.72rem; font-weight: 600; }
  .step-num { width: 30px; height: 30px; font-size: 0.82rem; }
  .form-section-title h2 { font-size: 1.25rem; }
  .form-section-title p { font-size: 0.85rem; }

  /* Settings: single column */
  .settings-grid { grid-template-columns: 1fr; }

  /* Stats charts: single column */
  .stats-charts-grid { grid-template-columns: 1fr; }
  .stats-charts-grid .span-2 { grid-column: span 1; }

  /* History controls: stack */
  .history-controls { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .filter-box { flex-direction: row; flex-wrap: wrap; gap: 0.5rem; }
  .filter-box select { flex: 1; min-width: 110px; font-size: 15px !important; }

  /* Service cards */
  .services-list-grid { grid-template-columns: 1fr; gap: 0.85rem; }
  .service-card { padding: 1rem; }
  .service-card-client { font-size: 1.1rem; font-weight: 700; }
  .service-card-id { font-size: 0.82rem; }
  .service-card-meta-item { font-size: 0.88rem; }
  .service-cost-badge { font-size: 0.92rem; font-weight: 700; }

  /* Mailbox: full width, no split */
  .mailbox-layout { flex-direction: column; height: auto; }
  .mail-sidebar { width: 100%; max-height: 250px; }
  .mail-viewer { min-height: 350px; }
  .mail-body-frame-container { min-height: 300px; }

  /* Modal: bottom sheet respecting iOS Safe Area */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-card {
    max-width: 100% !important;
    width: 100% !important;
    max-height: calc(88vh - env(safe-area-inset-bottom, 0px));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1.1rem 0.85rem calc(1.5rem + env(safe-area-inset-bottom, 0px)) 0.85rem;
    margin-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  }
  .modal-card.modal-sm { max-width: 100% !important; }
  .modal-card.modal-lg { max-width: 100% !important; }
  .modal-header h2 { font-size: 1.2rem; }

  /* Stats date range: stacked */
  .stats-date-range { flex-direction: column; }

  /* Selector controls: stacked */
  .selector-controls { flex-direction: column; align-items: stretch; }

  /* Bottom nav: account for iOS Home Indicator Gesture Bar */
  .bottom-nav {
    display: flex !important;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(7, 13, 26, 0.98);
    box-shadow: 0 -4px 25px rgba(0,0,0,0.7);
    transform: translateZ(0);
    will-change: transform;
  }

  .bottom-nav-item {
    font-size: 0.65rem;
    font-weight: 500;
    gap: 2px;
    padding: 0.25rem 0.4rem;
  }

  .bottom-nav-item svg {
    width: 19px;
    height: 19px;
  }
}

/* ============================================================
   TABLET — max-width: 1024px
   ============================================================ */
@media (max-width: 1024px) and (min-width: 769px) {
  :root { --sidebar-w: 64px; }

  .logo-text, .nav-item span, .user-info, .sync-status span { display: none; }
  .nav-item { justify-content: center; padding: 0.75rem; }
  .sidebar-brand { justify-content: center; }
  .logo-icon { margin: 0; }
  .sidebar-footer { padding: 0.5rem; }
  .user-badge { flex-direction: column; align-items: center; gap: 0.3rem; padding: 0.4rem; }
  .user-name, .user-role { display: none; }
  .sync-status { justify-content: center; padding: 0.3rem; }
  .badge { position: absolute; top: 2px; right: 2px; }
  .nav-item { position: relative; }
}

/* ============================================================
   CLIENT AUTOCOMPLETE SUGGESTIONS
   ============================================================ */
.autocomplete-container {
  position: relative !important;
  width: 100%;
}

.autocomplete-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #0f1c35;
  border: 1px solid var(--cyan);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}

.autocomplete-item {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: rgba(56, 189, 248, 0.18);
}

.autocomplete-item .client-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.autocomplete-item .client-details {
  font-size: 0.75rem;
  color: var(--cyan);
}
