/* Modern Apple-Style Theme */
:root {
  /* System Colors */
  --bg-body: #F5F5F7;
  --bg-card: #FFFFFF;
  --bg-input: #F5F5F7;
  
  /* Text Colors */
  --text-primary: #1D1D1F;
  --text-secondary: #86868B;
  --text-tertiary: #AEAEB2;

  /* Accents */
  --accent: #0071E3;
  --accent-hover: #0077ED;
  --danger: #FF3B30;
  --success: #34C759;
  --warning: #FF9F0A;

  /* Borders & Separators */
  --separator: #D2D2D7;
  --separator-light: #E5E5EA;
  
  /* Dimensions */
  --radius-l: 18px;
  --radius-m: 12px;
  --radius-s: 8px;
  
  /* Fonts */
  --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Legacy Aliases */
  --bg-app: var(--bg-body);
  --background: var(--bg-body);
  --radius: var(--radius-m);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg-body);
  color: var(--text-primary);
  font-family: var(--font-stack);
  font-size: 13px; /* macOS standard preferred size */
  line-height: 1.4;
  margin: 0;
  padding-bottom: 40px;
}

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

/* Layout Utilities */
.hidden { display: none !important; }
.block { display: block; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.flex-1 { flex: 1; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-secondary { color: var(--text-secondary); }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 16px; }
.p-2 { padding: 8px; }

/* App Shell - Responsive Container */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Responsive Grid Utilities */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}
.grid-4 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 768px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Section Card */
.section-card {
  background: #FFFFFF;
  border: 1px solid var(--separator-light);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* Toolbar (Glassmorphism) - with iOS safe area support */
.apple-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  /* Account for iOS safe area (notch/Dynamic Island) */
  height: calc(52px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
  padding-right: 20px;
}

.toolbar-group {
  display: flex;
  background: rgba(118, 118, 128, 0.12);
  padding: 2px;
  border-radius: 8px;
  gap: 1px;
}

.toolbar-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}

.toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.5);
}

.toolbar-btn:active {
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Segmented Control */
.segmented-control {
  display: flex;
  background: rgba(118, 118, 128, 0.12);
  padding: 2px;
  border-radius: 8px;
  width: 100%;
  margin-bottom: 12px;
}

.segment-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 4px 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  text-align: center;
}

.segment-btn.active {
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  font-weight: 600;
}

/* Grouped Lists (Settings Style) */
.apple-group-title {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin: 24px 0 8px 16px;
  letter-spacing: 0.01em;
}
/* Remove top margin for first child */
.apple-group-title:first-child { margin-top: 0; }

.apple-group {
  background: var(--bg-card);
  border-radius: var(--radius-m);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  margin-bottom: 24px;
}
/* Compact groups inside inspector */
.inspector-panel .apple-group { margin-bottom: 16px; }

.apple-row {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  position: relative;
  background: var(--bg-card);
}

.apple-row:not(:last-child)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 12px; /* Inset separator */
  right: 0;
  height: 1px;
  background: var(--separator-light);
}

.apple-row label {
  flex: 0 0 100px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
}

.apple-row .input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

/* Inputs (Seamless) */
.apple-input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  padding: 10px 0;
  outline: none;
}

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

.apple-input:focus {
  /* No outline in list view usually, or maybe blue text? */
}

/* Table Inputs: Make them visible/interactive (Card Style) */
.apple-table .apple-input, .card-input {
  background: #FFFFFF;
  border: 1px solid #D1D1D6;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.apple-table .apple-input:focus, .card-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.15);
  outline: none;
}

.apple-table {
  width: 100%;
  border-collapse: separate; /* Allow spacing between rows */
  border-spacing: 0 12px; /* Vertical spacing between rows */
}

.apple-table th {
  padding: 0 12px 8px 12px; /* Adjust header padding */
  border: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.apple-table tbody tr {
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border-radius: 8px;
  /* Note: border-radius on TR requires distinct handling or block display in some browsers, 
     but td:first-child border-radius works well */
}

.apple-table td {
  border-top: 1px solid var(--separator-light);
  border-bottom: 1px solid var(--separator-light);
  padding: 16px 12px;
  background: #FFFFFF;
  vertical-align: top;
}

.apple-table td:first-child {
  border-left: 1px solid var(--separator-light);
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}

.apple-table td:last-child {
  border-right: 1px solid var(--separator-light);
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
}

/* Unit Label under input */
.unit-label {
  display: block;
  font-size: 10px;
  color: var(--text-secondary);
  text-align: right;
  margin-top: 4px;
  text-transform: uppercase;
}

/* Selects need custom appearance to look clean */


/* Standalone Fields (Textareas, Search) */
.apple-field {
  width: 100%;
  border: 1px solid var(--separator-light);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  background: var(--bg-body); /* Slightly off-white for contrast in white panels */
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}

.apple-field:focus {
  background: #FFFFFF;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

/* Buttons */
.apple-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border-radius: var(--radius-s);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  text-decoration: none;
  line-height: 1.2;
}

/* Secondary / Default Button */
.apple-btn {
  background: rgba(118, 118, 128, 0.08); /* Light gray fill */
  color: var(--text-primary);
}
.apple-btn:hover {
  background: rgba(118, 118, 128, 0.12);
}
.apple-btn:active {
  background: rgba(118, 118, 128, 0.16);
  transform: scale(0.98);
}

/* Primary Button */
.apple-btn.primary {
  background: var(--accent);
  color: #FFFFFF;
}
.apple-btn.primary:hover {
  background: var(--accent-hover);
}

/* Ghost Button */
.apple-btn.ghost {
  background: transparent;
  color: var(--accent);
  padding: 4px 8px;
}
.apple-btn.ghost:hover {
  background: rgba(0, 113, 227, 0.08);
}
.apple-btn.ghost.danger {
  color: var(--danger);
}
.apple-btn.ghost.danger:hover {
  background: rgba(255, 59, 48, 0.08);
}

/* Danger Button */
.apple-btn.danger {
  background: rgba(255, 59, 48, 0.1);
  color: var(--danger);
}
.apple-btn.danger:hover {
  background: rgba(255, 59, 48, 0.15);
}

/* Customer Card */
.customer-card {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.customer-card .name { font-weight: 600; font-size: 14px; }
.customer-card .meta { font-size: 12px; color: var(--text-secondary); }
.customer-placeholder {
  padding: 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.2s;
}
.customer-placeholder:hover { color: var(--accent); }

/* Tables */
.apple-table-container {
  border: 1px solid var(--separator-light);
  border-radius: var(--radius-m);
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.apple-table {
  width: 100%;
  border-collapse: collapse;
}

.apple-table th {
  background: #FAFAFA;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--separator-light);
}

.apple-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--separator-light);
  font-size: 13px;
  color: var(--text-primary);
  vertical-align: top;
}

.apple-table tbody tr:nth-child(even) {
  background-color: #F9F9F9;
}

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

/* Modals */
.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  animation: fadeIn 0.2s forwards;
}

.modal-window {
  background: #FFFFFF;
  width: 100%;
  max-width: 520px;
  border-radius: var(--radius-l);
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  max-height: 90vh; /* Limit height */
  margin: 20px; /* Ensure spacing from edges */
  transform: scale(0.95);
  animation: popIn 0.2s forwards;
}

@keyframes fadeIn { to { opacity: 1; } }
@keyframes popIn { to { transform: scale(1); } }

.modal-header {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--separator-light);
}

.modal-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}

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

/* Drawers */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  backdrop-filter: blur(2px);
  z-index: 900;
}

.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 360px;
  background: #FFFFFF;
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
}

/* Status Badges */
.status-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 12px;
  letter-spacing: 0.02em;
  display: inline-block;
}
.status-badge.draft { background: #F2F2F7; color: #8E8E93; }
.status-badge.sent { background: #E0F2FE; color: #0071E3; }
.status-badge.accepted { background: #E8F5E9; color: #34C759; }
.status-badge.declined { background: #FEE2E2; color: #FF3B30; }
.status-badge.expired { background: #FFF7ED; color: #FF9F0A; }
.status-badge.archived { background: #E5E5EA; color: #AEAEB2; }

/* Public Hero (if used) */

.public-hero {

  background: #FFFFFF;

  border-bottom: 1px solid var(--separator-light);

  padding: 40px 0;

}



/* Sticky Utilities */



.sticky-header {
  position: sticky;
  /* Account for toolbar height + iOS safe area */
  top: calc(52px + env(safe-area-inset-top, 0px));
  z-index: 40;
  background: var(--bg-body); /* Match body bg to hide content behind */
  padding-top: 10px;
  padding-bottom: 10px;
  margin-bottom: 0 !important; /* Remove margin so table header sits flush */
}







.apple-table th {







  padding: 0 12px 8px 12px;







  border: none;







  font-size: 11px;







  font-weight: 600;







  color: var(--text-secondary);







  text-transform: uppercase;







  text-align: left;







}







.sticky-sidebar {
  position: sticky;
  /* Toolbar + padding + iOS safe area */
  top: calc(76px + env(safe-area-inset-top, 0px));
  height: calc(100vh - 100px - env(safe-area-inset-top, 0px));
  overflow-y: auto;
  /* Hide scrollbar for clean look but allow scroll */
  scrollbar-width: thin;
}



.label {

  font-size: 10px;

  text-transform: uppercase;

  font-weight: 600;

  color: var(--text-secondary);

  letter-spacing: 0.05em;

  display: block;

}



/* Compatibility / Shared Classes */

.panel {

  background: var(--bg-card);

  border-radius: var(--radius-l);

  box-shadow: 0 4px 12px rgba(0,0,0,0.05);

  padding: 24px;

  overflow: hidden;

}



.btn {

  display: inline-flex;

  align-items: center;

  padding: 8px 16px;

  border-radius: var(--radius-s);

  font-size: 14px;

  font-weight: 500;

  cursor: pointer;

  transition: all 0.2s;

  border: none;

  text-decoration: none;

  background: rgba(118, 118, 128, 0.1);

  color: var(--text-primary);

}

.btn:hover { background: rgba(118, 118, 128, 0.15); }

.btn.primary { background: var(--accent); color: #FFFFFF; }

.btn.primary:hover { background: var(--accent-hover); }

.btn.danger { background: rgba(255, 59, 48, 0.1); color: var(--danger); }

/* Mobile Table Stacking */
@media (max-width: 768px) {
  .apple-table { display: block; }
  .apple-table thead { display: none; }
  .apple-table tbody { display: block; }
  .apple-table tbody tr {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--separator-light);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }
  .apple-table td {
    display: block;
    border: none;
    padding: 0;
    width: 100% !important;
    text-align: left !important;
  }
  /* Fix first/last child borders from desktop styles */
  .apple-table td:first-child, .apple-table td:last-child {
    border: none;
    border-radius: 0;
  }
  
  /* Mobile Labels */
  .mobile-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 4px;
  }
}

/* Desktop: Hide mobile labels */
@media (min-width: 769px) {
  .mobile-label { display: none; }
}
