/* ═══════════════════════════════════════════════
   SGF — Sistema de Gestão de Faturas
   MOBILE-FIRST Design System
   ═══════════════════════════════════════════════ */

/* ─── CSS Custom Properties ─── */
:root {
  /* Palette */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f8f8;
  --bg-tertiary: #f0f0f0;
  --bg-card: #ffffff;
  --bg-card-hover: #fafafa;

  --border-default: #e5e5e5;
  --border-subtle: #f0f0f0;
  --border-focus: #999999;

  --text-primary: #111111;
  --text-secondary: #555555;
  --text-tertiary: #999999;

  --accent: #111111;
  --accent-hover: #333333;

  --success: #2e7d32;
  --danger: #cc0000;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
  --shadow-xl: 0 12px 40px rgba(0,0,0,0.12);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --sidebar-width: 240px;
  --bottom-nav-height: 60px;
  --mobile-header-height: 56px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
}

/* ─── Scrollbar (desktop) ─── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: var(--radius-full); }

/* ═══════════════════════════════════════════════
   SIDEBAR — Hidden on mobile, shown on desktop
   ═══════════════════════════════════════════════ */

.sidebar {
  display: none;
}

.sidebar-header { padding: var(--space-6) var(--space-5); border-bottom: 1px solid var(--border-subtle); }

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

.logo-icon { display: flex; align-items: center; justify-content: center; }
.logo-icon svg rect { fill: #fff !important; }
.logo-icon svg path { stroke: #000 !important; }

.logo-text {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  position: relative;
}

.nav-item::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 2px; height: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--accent);
  transition: height var(--transition-base);
}

.nav-item:hover { color: var(--text-primary); background: rgba(0,0,0,0.05); }
.nav-item.active { color: var(--text-primary); background: rgba(0,0,0,0.08); }
.nav-item.active::before { height: 60%; }

.sidebar-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-subtle); }
.user-info { display: flex; align-items: center; gap: var(--space-3); }

.user-avatar {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.user-details { display: flex; flex-direction: column; }
.user-name { font-size: 0.85rem; font-weight: 600; }
.user-role { font-size: 0.72rem; color: var(--text-tertiary); }

/* ═══════════════════════════════════════════════
   MAIN CONTENT — Mobile-first
   ═══════════════════════════════════════════════ */

.main-content {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ─── Desktop Top Bar — hidden on mobile ─── */
.top-bar { display: none; }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
}

.breadcrumb-item { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }

.top-bar-right { display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; }

.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  min-width: 240px;
  transition: all var(--transition-fast);
}

.search-bar:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 2px rgba(0,0,0,0.06); }
.search-bar svg { color: var(--text-tertiary); flex-shrink: 0; }

.search-bar input {
  background: none; border: none; outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  width: 100%;
}

.search-bar input::placeholder { color: var(--text-tertiary); }

.notification-btn {
  position: relative;
  background: none;
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-fast);
}

.notification-btn:hover { color: var(--text-primary); border-color: var(--border-focus); }

.notification-dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  border: 1.5px solid var(--bg-primary);
}

/* ═══════════════════════════════════════════════
   MOBILE HEADER
   ═══════════════════════════════════════════════ */

.mobile-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  padding-top: calc(var(--space-3) + var(--safe-top));
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  height: var(--mobile-header-height);
}

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

.mobile-logo {
  display: flex;
  align-items: center;
}

.mobile-page-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.mobile-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.mobile-search-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: color var(--transition-fast);
}

.mobile-search-btn:active { color: var(--text-primary); }

/* ─── Mobile Search Overlay ─── */
.mobile-search-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  padding: var(--space-3) var(--space-4);
  padding-top: calc(var(--space-3) + var(--safe-top));
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-default);
  animation: slideDown 0.2s ease-out;
}

.mobile-search-overlay.active { display: block; }

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.mobile-search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
}

.mobile-search-bar svg { color: var(--text-tertiary); flex-shrink: 0; }

.mobile-search-bar input {
  flex: 1;
  background: none; border: none; outline: none;
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--text-primary);
  min-height: 40px;
}

.mobile-search-bar input::placeholder { color: var(--text-tertiary); }

.mobile-search-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-1);
  display: flex;
  min-width: 36px;
  min-height: 36px;
  align-items: center;
  justify-content: center;
}

/* ═══════════════════════════════════════════════
   BOTTOM NAVIGATION
   ═══════════════════════════════════════════════ */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: var(--bottom-nav-height);
  padding-bottom: var(--safe-bottom);
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-default);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.2px;
  transition: color var(--transition-fast);
  padding: var(--space-1) 0;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item svg {
  transition: transform var(--transition-fast);
}

.bottom-nav-item.active {
  color: var(--accent);
  font-weight: 700;
}

.bottom-nav-item.active svg {
  transform: scale(1.1);
}

.bottom-nav-item:active svg {
  transform: scale(0.9);
}

/* ═══════════════════════════════════════════════
   FAB (Floating Action Button)
   ═══════════════════════════════════════════════ */

.fab {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 16px);
  right: 16px;
  z-index: 90;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 2px 4px rgba(0,0,0,0.1);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.fab.hidden { display: none; }

/* ═══════════════════════════════════════════════
   PAGES
   ═══════════════════════════════════════════════ */

.page {
  display: none;
  padding: var(--space-4);
  padding-bottom: var(--space-8);
  animation: pageIn 0.3s ease-out;
}

.page.active { display: block; }

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.page-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Hide the "Nova Fatura" etc. buttons on mobile page headers — FAB replaces them */
.page-header .btn--primary { display: none; }

/* ─── Stats Grid ─── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: all var(--transition-base);
}

.stat-card::before { display: none; }

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

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

.stat-icon--blue,
.stat-icon--green,
.stat-icon--purple,
.stat-icon--orange {
  background: rgba(0,0,0,0.06);
  color: var(--accent);
}

.stat-info { display: flex; flex-direction: column; }

.stat-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.stat-trend { display: none; }

/* ═══════════════════════════════════════════════
   CARDS & DATA DISPLAY — Card layout by default
   ═══════════════════════════════════════════════ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

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

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

.table-wrap { overflow-x: auto; }

/* ─── Mobile card layout for data tables ─── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { display: none; }

.data-table tbody { display: flex; flex-direction: column; }

.data-table tr:not(.empty-row) {
  display: flex;
  flex-direction: column;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-1);
}

.data-table tr:not(.empty-row):active {
  background: var(--bg-secondary);
}

.data-table td {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 0;
  border-bottom: none;
  white-space: normal;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.data-table td::before {
  content: attr(data-label);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex-shrink: 0;
  margin-right: var(--space-3);
}

.data-table td:first-child {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  padding-bottom: var(--space-1);
}

.data-table td:first-child::before {
  display: none;
}

.data-table td:last-child {
  padding-top: var(--space-2);
  justify-content: flex-start;
}

.data-table td:last-child::before { display: none; }

.data-table .empty-row { display: table-row; }
.data-table .empty-row td { display: table-cell; }
.data-table .empty-row td::before { content: none; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-4);
  gap: var(--space-2);
  color: var(--text-tertiary);
}

.empty-state p { font-weight: 600; font-size: 0.95rem; color: var(--text-secondary); }
.empty-state span { font-size: 0.8rem; }

/* ─── Status Badge ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge--paid { background: rgba(0,0,0,0.08); color: var(--accent); }
.badge--pending { background: rgba(0,0,0,0.05); color: #777; }
.badge--cancelled { background: rgba(0,0,0,0.03); color: #999; }

/* ─── Action Buttons ─── */
.action-btns { display: flex; gap: var(--space-2); }

.action-btn {
  background: none;
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-fast);
  min-width: 40px;
  min-height: 40px;
}

.action-btn:active {
  background: rgba(0,0,0,0.05);
  color: var(--accent);
}

.action-btn--danger:active {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(204,0,0,0.05);
}

/* ═══════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  min-height: 44px;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.btn--primary:active {
  background: var(--accent-hover);
  transform: scale(0.97);
}

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

.btn--outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(0,0,0,0.2);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn--sm {
  padding: var(--space-2) var(--space-3);
  font-size: 0.82rem;
  min-height: 36px;
}

.btn--danger {
  background: rgba(0,0,0,0.04);
  color: #999;
  border: 1px solid rgba(0,0,0,0.08);
}

/* ═══════════════════════════════════════════════
   MODALS — Full-screen on mobile
   ═══════════════════════════════════════════════ */

dialog.modal {
  position: fixed;
  border: none;
  background: transparent;
  padding: 0;
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

dialog.modal::backdrop {
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

dialog.modal[open] {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: modalFadeIn 0.25s ease-out;
}

dialog.modal[open]::backdrop {
  animation: backdropIn 0.25s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes backdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-height: 95vh;
  max-height: 95dvh;
  overflow-y: auto;
  animation: modalSlideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  -webkit-overflow-scrolling: touch;
}

.modal-content--wide {
  max-width: 100%;
}

@keyframes modalSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 10;
}

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

.modal-close {
  background: none;
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  min-width: 40px;
  min-height: 40px;
  transition: all var(--transition-fast);
}

.modal-close:active {
  background: rgba(0,0,0,0.05);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  padding-bottom: calc(var(--space-4) + var(--safe-bottom));
  border-top: 1px solid var(--border-subtle);
  position: sticky;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 10;
}

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

/* ═══════════════════════════════════════════════
   FORMS — Touch-optimized
   ═══════════════════════════════════════════════ */

.invoice-form {
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.invoice-form .modal-actions {
  padding: var(--space-4) 0 0 0;
  border-top: 1px solid var(--border-subtle);
  position: static;
}

.form-group {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  flex: 1;
}

.form-group legend {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-primary);
  padding: 0 var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group .form-field + .form-field {
  margin-top: var(--space-3);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.form-row--three {
  grid-template-columns: 1fr;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: var(--space-3);
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px; /* Prevents iOS zoom */
  outline: none;
  min-height: 48px;
  transition: all var(--transition-fast);
  -webkit-appearance: none;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--border-focus);
  background: var(--bg-primary);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.06);
}

.form-field input[readonly] {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
}

.form-field select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23999' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

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

#client-form,
#product-form {
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

#client-form .modal-actions,
#product-form .modal-actions {
  padding: var(--space-4) 0 0 0;
  border-top: 1px solid var(--border-subtle);
  position: static;
}

/* ─── Items Section ─── */
.items-section {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
}

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

.items-header h3 { font-size: 0.85rem; font-weight: 700; }

/* Items as stacked cards on mobile */
.items-table { width: 100%; border-collapse: collapse; }
.items-table thead { display: none; }

.items-table tbody { display: flex; flex-direction: column; }

.items-table tr {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
}

.items-table td { padding: var(--space-1) 0; display: block; }

/* Product select — full width */
.items-table td:nth-child(1) { grid-column: 1 / -1; }
/* Description — full width */
.items-table td:nth-child(2) { grid-column: 1 / -1; }
/* Subtotal */
.items-table td:nth-child(7) { text-align: left; font-weight: 700; font-size: 0.95rem; color: var(--text-primary); }
/* Remove button */
.items-table td:nth-child(8) { position: absolute; top: var(--space-3); right: var(--space-2); width: auto; }

.items-table input,
.items-table select {
  padding: var(--space-2) var(--space-3);
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  outline: none;
  width: 100%;
  min-height: 44px;
  transition: all var(--transition-fast);
}

.items-table input:focus,
.items-table select:focus { border-color: var(--border-focus); }

.items-table select { cursor: pointer; appearance: none; }

.remove-item-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  min-width: 40px;
  min-height: 40px;
}

.remove-item-btn:active { color: var(--danger); background: rgba(0,0,0,0.05); }

/* ─── Totals ─── */
.totals-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.totals-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.total-row--grand {
  border-top: 2px solid var(--accent);
  padding-top: var(--space-3);
  margin-top: var(--space-2);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
}

.total-row--grand span:last-child { color: var(--accent); }

/* ═══════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════ */

.toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 8px);
  left: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  z-index: 1000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 500;
  color: #fff;
  animation: toastIn 0.3s ease-out, toastOut 0.3s 3.6s ease-in forwards;
  pointer-events: auto;
}

.toast--success { border-left: 3px solid var(--success); }
.toast--error { border-left: 3px solid var(--danger); }
.toast--info { border-left: 3px solid #aaa; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(20px); }
}

/* ─── Sidebar Overlay ─── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

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

/* ═══════════════════════════════════════════════
   DESKTOP ADAPTATION ( >= 1024px )
   ═══════════════════════════════════════════════ */

@media (min-width: 1024px) {
  body {
    display: flex;
    background: var(--bg-primary);
    padding-bottom: 0;
  }

  /* Show sidebar */
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width);
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-right: 1px solid var(--border-default);
    z-index: 100;
  }

  /* Show desktop top bar, hide mobile header */
  .top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-8);
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .top-bar-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
  }

  .mobile-header { display: none; }
  .mobile-search-overlay { display: none !important; }

  /* Hide bottom nav and FAB */
  .bottom-nav { display: none; }
  .fab { display: none; }

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

  /* Pages */
  .page {
    padding: var(--space-8);
  }

  .page-header {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--space-8);
    flex-wrap: wrap;
    gap: var(--space-4);
  }

  .page-header .btn--primary { display: inline-flex; }

  .page-header h1 { font-size: 1.75rem; }

  /* Stats grid */
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-5);
    margin-bottom: var(--space-8);
  }

  .stat-card {
    flex-direction: row;
    align-items: center;
    padding: var(--space-5) var(--space-6);
    gap: var(--space-4);
  }

  .stat-icon { width: 48px; height: 48px; }
  .stat-icon svg { width: 24px; height: 24px; }

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

  .stat-trend {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    color: #ccc;
    background: rgba(0,0,0,0.03);
  }

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

  /* Tables — desktop layout */
  .data-table thead { display: table-header-group; }
  .data-table tbody { display: table-row-group; }
  .data-table tr:not(.empty-row) { display: table-row; }
  .data-table td { display: table-cell; white-space: nowrap; }
  .data-table td::before { display: none; }

  .data-table th {
    padding: var(--space-3) var(--space-5);
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(0,0,0,0.02);
    border-bottom: 1px solid var(--border-subtle);
  }

  .data-table td {
    padding: var(--space-4) var(--space-5);
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-subtle);
  }

  .data-table td:first-child { font-weight: 600; }
  .data-table td:last-child { justify-content: flex-start; }

  .data-table tbody tr:not(.empty-row):hover {
    background: rgba(0,0,0,0.02);
  }

  .action-btn { min-width: auto; min-height: auto; padding: 5px 7px; }
  .action-btn:hover { color: var(--accent); border-color: var(--accent); background: rgba(0,0,0,0.05); }
  .action-btn--danger:hover { color: var(--danger); border-color: var(--danger); background: rgba(204,0,0,0.05); }

  /* Card header */
  .card-header { padding: var(--space-5) var(--space-6); }

  /* Modals — centered popup */
  dialog.modal[open] {
    align-items: center;
  }

  .modal-content {
    border-radius: var(--radius-xl);
    max-width: 520px;
    max-height: 90vh;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-default);
    background: var(--bg-secondary);
  }

  .modal-content--wide { max-width: 900px; }

  @keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }

  .modal-actions {
    flex-direction: row;
    justify-content: flex-end;
    padding-bottom: var(--space-5);
  }

  .modal-actions .btn { width: auto; }

  /* Forms */
  .form-row { grid-template-columns: 1fr 1fr; gap: var(--space-5); }
  .form-row--three { grid-template-columns: 1fr 1fr 1fr; }

  .form-field input,
  .form-field select,
  .form-field textarea {
    padding: var(--space-2) var(--space-3);
    font-size: 0.85rem;
    min-height: auto;
  }

  #client-form .modal-actions,
  #product-form .modal-actions {
    position: static;
  }

  /* Items table — desktop */
  .items-table thead { display: table-header-group; }
  .items-table tbody { display: table-row-group; }

  .items-table tr {
    display: table-row;
    padding: 0;
    border-bottom: none;
  }

  .items-table td {
    display: table-cell;
    padding: var(--space-2);
    position: static;
    width: auto;
  }

  .items-table td:nth-child(1),
  .items-table td:nth-child(2) { grid-column: auto; }

  .items-table input,
  .items-table select {
    min-height: auto;
    font-size: 0.82rem;
    padding: var(--space-1) var(--space-2);
  }

  .remove-item-btn { min-width: auto; min-height: auto; padding: 4px; }

  /* Totals */
  .totals-section {
    flex-direction: row;
    justify-content: space-between;
  }

  .totals-box { min-width: 260px; width: auto; }

  /* Toasts */
  .toast-container {
    bottom: var(--space-6);
    left: auto;
    right: var(--space-6);
    max-width: 360px;
  }

  .btn--primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    transform: translateY(-1px);
  }

  .btn--secondary:hover { background: var(--bg-tertiary); }
  .btn--outline:hover { background: rgba(0,0,0,0.05); }
  .btn--ghost:hover { color: var(--text-primary); background: rgba(0,0,0,0.03); }
}

/* ═══════════════════════════════════════════════
   SMALL MOBILE ( <= 380px )
   ═══════════════════════════════════════════════ */

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

  .items-table tr { grid-template-columns: 1fr; }

  .items-table td:nth-child(8) {
    position: static;
    width: 100%;
    text-align: right;
  }
}
