/* === CSS Custom Properties === */
:root {
  --bg-base: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-elevated: #f8fafc;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --maroon: #7f1d1d;
  --maroon-light: #991b1b;
  --maroon-glow: rgba(127, 29, 29, 0.06);
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.08);
  --transition: 150ms ease;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}

/* === Login === */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  background: var(--bg-surface);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.login-brand { margin-bottom: 32px; }
.login-brand h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-top: 12px; }
.login-brand p { font-size: 14px; color: var(--text-muted); }
.login-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color var(--transition);
}
.login-input:focus { border-color: var(--maroon); }
.login-input::placeholder { color: var(--text-muted); }
.login-error { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 8px; }
.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--maroon);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 12px;
  transition: background var(--transition);
  min-height: 48px;
}
.login-btn:active { background: #6b1a1a; }
.login-footer { margin-top: 24px; font-size: 12px; color: var(--text-muted); }

/* === App Layout === */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 768px;
  margin: 0 auto;
}

/* === Top Bar === */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}
.topbar-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.topbar-logout:active { background: var(--border); }

/* === Main Content === */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 80px;
  -webkit-overflow-scrolling: touch;
}

/* === Bottom Nav === */
.bottom-nav {
  display: flex;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 768px;
  margin: 0 auto;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  min-height: 56px;
  justify-content: center;
  transition: color var(--transition);
}
.bottom-nav-item.active { color: var(--maroon); }
.bottom-nav-item.active::after {
  content: '';
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--maroon);
  margin-top: 2px;
}
.bottom-nav-item:active { color: #b91c1c; }

/* === Cards === */
.card {
  background: var(--bg-surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.15s;
}
.card:hover { box-shadow: var(--shadow-card-hover); }
.card-header {
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  cursor: pointer;
  min-height: 48px;
}
.card-body { padding: 0 16px 16px; }

/* === Status Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.badge-green { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-green .dot { background: var(--success); }
.badge-yellow { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-yellow .dot { background: var(--warning); }
.badge-red { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-red .dot { background: var(--danger); }
.badge-blue { background: rgba(127, 29, 29, 0.15); color: #b91c1c; }
.badge-blue .dot { background: var(--maroon); }

/* === Super Tabs === */
.super-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.super-tab {
  padding: 10px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  transition: all var(--transition);
}
.super-tab.active {
  background: var(--maroon);
  border-color: var(--maroon);
  color: #fff;
}
.super-tab:active { opacity: 0.8; }

/* === Build Cards === */
.build-card {
  text-decoration: none;
  color: inherit;
  display: block;
}
.build-card-name { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.build-card-address { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }
.build-card-plan { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.build-card-progress { margin-top: 12px; }
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  background: var(--maroon);
  border-radius: 2px;
  transition: width 0.3s;
}
.progress-text { font-size: 13px; color: var(--text-muted); display: flex; justify-content: space-between; }
.build-card-actions {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* === Build Detail === */
.build-header { margin-bottom: 16px; }
.build-detail-name { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.build-detail-address { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }
.build-detail-meta { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 12px;
  padding: 8px 0;
  min-height: 44px;
}
.back-btn:active { color: var(--maroon); }

/* === Build Tabs === */
.build-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  margin-left: -16px;
  margin-right: -16px;
  padding: 0 16px;
}
.build-tab {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  min-height: 44px;
  display: flex;
  align-items: center;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  transition: color var(--transition);
}
.build-tab.active {
  color: var(--maroon);
  border-bottom-color: var(--maroon);
  font-weight: 600;
}
.build-tab:active { color: #b91c1c; }

/* === Schedule Phase Accordion === */
.phase-card { margin-bottom: 10px; }
.phase-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  min-height: 48px;
}
.phase-name { font-size: 15px; font-weight: 600; color: var(--text-primary); flex: 1; }
.phase-progress { font-size: 12px; color: var(--text-muted); margin-right: 8px; }
.phase-toggle { color: var(--text-muted); font-size: 12px; transition: transform 0.2s; }
.phase-card.collapsed .phase-toggle { transform: rotate(-90deg); }
.phase-body { padding: 0 16px 12px; }
.phase-card.collapsed .phase-body { display: none; }

/* Steps */
.step-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}
.step-item:last-child { border-bottom: none; }
.step-checkbox {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid var(--text-muted);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  min-width: 44px;
  min-height: 44px;
  padding: 0;
}
.step-checkbox:active { border-color: var(--maroon); }
.step-checkbox.checked {
  background: var(--success);
  border-color: var(--success);
}
.step-checkbox.checked::after {
  content: '';
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}
.step-name { font-size: 15px; color: var(--text-primary); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-item.done .step-name { color: var(--text-muted); text-decoration: line-through; }
.step-date { font-size: 12px; color: var(--text-muted); }
.step-add-sched {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.step-add-sched:hover { color: var(--maroon); border-color: var(--maroon); }
.step-assignments { padding: 4px 0 8px 36px; display: flex; flex-direction: column; gap: 6px; }
.step-assignment {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 13px;
}
.sa-bar { width: 3px; height: 16px; background: var(--maroon); border-radius: 2px; flex-shrink: 0; }
.sa-date { color: var(--text-secondary); font-weight: 600; white-space: nowrap; }
.sa-note { color: var(--text-primary); flex: 1; word-break: break-word; }
.sa-delete {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
.sa-delete:hover { color: #ef4444; }
.step-sched-form { padding: 0 0 8px 36px; }
.step-sched-form.hidden { display: none; }

/* === Action Items === */
.action-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.action-filter {
  padding: 8px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
}
.action-filter.active { background: var(--maroon); border-color: var(--maroon); color: #fff; }
.action-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.action-item:last-child { border-bottom: none; }
.action-text { font-size: 15px; color: var(--text-primary); }
.action-item.completed .action-text { color: var(--text-muted); text-decoration: line-through; }
.action-meta {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.action-btns {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.priority-high { color: var(--danger); }
.priority-medium { color: var(--warning); }
.priority-low { color: var(--success); }

/* === Plans Viewer === */
.plans-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.plan-image-container {
  width: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  background: var(--bg-base);
}
.plan-image-container img {
  width: 100%;
  display: block;
}
.plan-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px;
}

/* === Topbar AI chat button + floating popup === */
.topbar-chat {
  background: transparent;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 8px;
  margin-left: 10px;
  color: #7f1d1d;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.topbar-chat:hover { background: #fef2f2; border-color: #7f1d1d; }
.topbar-chat[hidden] { display: none; }

#chat-popup {
  position: fixed;
  /* topbar is ~12px padding + 44px control + 2px border = ~70px tall */
  top: 72px;
  right: 8px;
  width: min(380px, calc(100vw - 16px));
  height: min(560px, calc(100vh - 80px));
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-popup-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
}
.chat-popup-title { font-weight: 600; color: #7f1d1d; flex: 1; font-size: 14px; }
.chat-popup-expand { font-size: 12px; color: #475569; text-decoration: underline; }
.chat-popup-close {
  background: transparent;
  border: none;
  color: #475569;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
.chat-popup-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
/* Override the full-tab Chat layout so the same module fits the popup. */
#chat-popup-body .chat-container { height: 100%; margin: 0; flex: 1; }

/* === Chat === */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  margin: -16px;
  margin-top: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}
.chat-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}
.chat-bubble.user {
  background: var(--maroon);
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.chat-timestamp {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  padding: 0 4px;
}
.chat-timestamp.right { text-align: right; }
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  min-height: 44px;
}
.chat-input:focus { border-color: var(--maroon); }
.chat-input::placeholder { color: var(--text-muted); }
.chat-send {
  width: 44px;
  height: 44px;
  background: var(--maroon);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-send:active { background: #6b1a1a; }
.chat-send:disabled { opacity: 0.5; }
.chat-photo-btn {
  width: 44px; height: 44px; border: 1px solid var(--border);
  border-radius: 50%; background: var(--bg-surface); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0; color: var(--text-secondary);
}
.chat-photo-btn:active { background: var(--bg-elevated); }
.chat-photo-preview {
  padding: 8px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-photo-preview img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
}
.chat-photo-preview .remove-photo {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-bubble img {
  max-width: 100%;
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
}

/* === Packages === */
.package-card { margin-bottom: 12px; }
.package-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  min-height: 48px;
}
.package-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.package-desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.package-item-list { padding: 0 16px 12px; }
.package-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.package-item:last-child { border-bottom: none; }
.package-item-desc { color: var(--text-secondary); }
.package-item-qty { color: var(--text-muted); font-weight: 600; white-space: nowrap; margin-left: 12px; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  min-height: 44px;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-primary { background: var(--maroon); color: #fff; }
.btn-primary:active { background: #6b1a1a; }
.btn-secondary { background: var(--border); color: var(--text-primary); }
.btn-secondary:active { background: var(--text-muted); }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:active { background: #b91c1c; }
.btn-block { width: 100%; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:active { background: var(--border); }

/* === Section Headers === */
.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}
.section-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 16px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }

/* === Add Item Form === */
.add-form {
  padding: 16px;
  background: var(--bg-elevated);
  border-radius: 8px;
  margin-bottom: 12px;
}
.add-form input, .add-form select {
  width: 100%;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 15px;
  margin-bottom: 8px;
  min-height: 44px;
  outline: none;
}
.add-form input:focus, .add-form select:focus { border-color: var(--maroon); }
.add-form input::placeholder { color: var(--text-muted); }

/* === Desktop adjustments === */
@media (min-width: 768px) {
  body { background: var(--bg-base); }
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
  .bottom-nav {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* === Typing Indicator === */
.typing-indicator { padding: 12px 18px !important; width: fit-content; }
.dot-pulse { display: flex; gap: 5px; align-items: center; }
.dot-pulse span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  animation: dotPulse 1.4s infinite ease-in-out both;
}
.dot-pulse span:nth-child(1) { animation-delay: -0.32s; }
.dot-pulse span:nth-child(2) { animation-delay: -0.16s; }
.dot-pulse span:nth-child(3) { animation-delay: 0s; }
@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* === Share spinner === */
.spinner-sm {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #f8fafc;
  border-radius: 50%;
  animation: spinSm 0.6s linear infinite;
}
@keyframes spinSm {
  to { transform: rotate(360deg); }
}

/* === Selections === */
.sel-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.sel-row:last-child { border-bottom: none; }
.sel-item { font-size: 13px; color: var(--text-muted); margin-bottom: 2px; }
.sel-value { font-size: 15px; color: var(--text-primary); }

/* === Calendar === */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}
.cal-month-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 16px;
}
.cal-header {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 0;
  text-transform: uppercase;
}
.cal-day {
  min-height: 56px;
  padding: 4px 0 6px;
  border-radius: 8px;
  position: relative;
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  cursor: pointer;
  transition: background 0.15s ease;
}
.cal-day:hover { background: var(--maroon-glow); }
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.empty:hover { background: transparent; }

.cal-day-num {
  font-size: 14px;
  color: var(--text-primary);
  width: 28px;
  height: 28px;
  line-height: 28px;
  text-align: center;
  border-radius: 50%;
  margin-top: 2px;
  font-weight: 500;
}
.cal-day.today .cal-day-num {
  background: var(--maroon);
  color: #fff;
  font-weight: 700;
}
.cal-day.selected:not(.today) .cal-day-num {
  box-shadow: inset 0 0 0 1.5px var(--maroon);
  color: var(--maroon);
  font-weight: 700;
}

.cal-dot-row {
  display: flex;
  gap: 3px;
  margin-top: 4px;
  height: 6px;
  align-items: center;
  justify-content: center;
}
.cal-dot-row .cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: inline-block;
}

/* === Day-list panel (selected day's assignments) === */
.cal-daylist {
  margin-top: 14px;
  margin-bottom: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.cal-dl-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.cal-dl-headdate {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.cal-dl-add {
  min-width: 38px;
  font-size: 18px;
  line-height: 1;
  padding: 6px 12px;
}
.cal-dl-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cal-dl-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  padding: 10px 8px;
  border-radius: 8px;
  background: var(--bg-elevated);
}
.cal-dl-row-editing {
  background: var(--maroon-glow);
}
.cal-dl-stripe {
  width: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}
.cal-dl-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}
.cal-dl-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}
.cal-dl-title .cal-dl-trade {
  color: var(--text-secondary);
  font-weight: 500;
}
.cal-dl-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  overflow-wrap: anywhere;
}
.cal-dl-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-self: center;
}
.cal-dl-actions .btn {
  font-size: 12px;
  padding: 4px 10px;
}
.cal-dl-delete {
  color: var(--maroon);
  border-color: var(--maroon);
}
.cal-dl-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.cal-dl-row.no-trade .cal-dl-stripe {
  background: var(--text-muted) !important;
}

/* === Corner + add button (calendar header + overlay head) === */
.cal-nav-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cal-add-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--maroon);
  color: #ffffff;
  font-size: 22px;
  line-height: 1;
  font-weight: 400;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.05s ease;
  font-family: inherit;
}
.cal-add-btn:hover { background: var(--maroon-light); }
.cal-add-btn:active { transform: scale(0.96); }
.cal-overlay-head-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}
.cal-overlay-head-btns .cal-add-btn {
  width: 32px;
  height: 32px;
  font-size: 20px;
}
/* Corner + only makes sense in day-mode; in add/edit modes the form is
   already showing, so hide it. */
#schedule-overlay:not([data-mode="day"]) .cal-overlay-add { display: none; }

/* === Calendar overlay (popup over the grid for tap-day / + Schedule) === */
/* Stays in the DOM and laid out at all times so the scrim opacity + card
   transform transitions animate on BOTH open and close. visibility flips
   immediately on open and is delayed by the transition duration on close
   so the card finishes its slide-out before being hidden from AT/keyboard.
   pointer-events guards against clicks falling through when closed. */
.cal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 0.2s;
}
.cal-overlay.cal-overlay-open {
  visibility: visible;
  pointer-events: auto;
  transition: visibility 0s linear 0s;
}
.cal-overlay-scrim {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  transition: opacity 0.18s ease-out;
}
.cal-overlay-open .cal-overlay-scrim { opacity: 1; }
.cal-overlay-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  padding: 16px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  transition: transform 0.18s ease-out;
  -webkit-overflow-scrolling: touch;
}
.cal-overlay-open .cal-overlay-card { transform: translateY(0); }
.cal-overlay-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.cal-overlay-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--maroon);
}
.cal-overlay-close {
  background: none;
  border: 0;
  font-size: 20px;
  line-height: 1;
  padding: 6px 10px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
}
.cal-overlay-close:hover { background: var(--bg-base); color: var(--text-primary); }
.cal-overlay-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
body.cal-overlay-lock { overflow: hidden; }

@media (min-width: 720px) {
  .cal-overlay-card {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 8vh;
    width: 480px;
    max-width: calc(100vw - 32px);
    border-radius: 14px;
    transform: translate(-50%, 24px);
  }
  .cal-overlay-open .cal-overlay-card { transform: translate(-50%, 0); }
}

/* === Calendar form (used inside the overlay for add + edit) === */
.cal-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cal-form-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-top: 6px;
}
.cal-form-opt {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
}
.cal-form input[type="text"],
.cal-form input[type="date"],
.cal-form input[type="time"] {
  width: 100%;
  padding: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}
.cal-form input:focus { outline: none; border-color: var(--maroon); }
.cal-form input:disabled {
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: not-allowed;
}
.cal-form-row2 {
  display: flex;
  gap: 8px;
}
.cal-form-row2 > div { flex: 1; min-width: 0; }
.cal-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.cal-form-actions .btn { flex: 1; }

/* === Utilities === */
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* === Per-item Share Button === */
.share-btn-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.share-btn-sm:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.share-btn-sm svg {
  width: 16px;
  height: 16px;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Selection === */
::selection { background: rgba(127, 29, 29, 0.3); color: var(--text-primary); }

/* === Click/Tap Feedback === */
button, .btn, .nav-item, .card-clickable, [role="button"], a.action-link,
.sub-btn, .supplier-tab-btn, .tab-btn, .build-card, .job-card,
.bottom-nav-item, .super-tab, .action-filter, .back-btn, .step-item {
  transition: transform 120ms ease, opacity 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:active, .btn:active, .nav-item:active, .card-clickable:active,
[role="button"]:active, a.action-link:active,
.sub-btn:active, .supplier-tab-btn:active, .tab-btn:active,
.build-card:active, .job-card:active,
.bottom-nav-item:active, .super-tab:active, .action-filter:active, .back-btn:active {
  transform: scale(0.94);
  opacity: 0.7;
  transition: transform 40ms ease, opacity 40ms ease;
}

/* In-flight async button state. Applied only to action buttons by
   Super._withPending — not blanket-applied to cards/nav. */
.is-pending {
  opacity: 0.55 !important;
  cursor: wait !important;
  pointer-events: none;
  position: relative;
  overflow: hidden;
}
.is-pending::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent 0%, rgba(127,29,29,0.18) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: pendingShimmer 900ms linear infinite;
  pointer-events: none;
}
@keyframes pendingShimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* Soft fade on tab content swap so re-renders read as a transition,
   not a flash. Plays on every Super.render() pass — acceptable. */
#super-tab-content {
  animation: tabFadeIn 160ms ease-out;
}
@keyframes tabFadeIn {
  from { opacity: 0.4; transform: translateY(4px); }
  to   { opacity: 1;   transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  button:active, .btn:active, .nav-item:active, .card-clickable:active,
  [role="button"]:active, a.action-link:active,
  .sub-btn:active, .supplier-tab-btn:active, .tab-btn:active,
  .build-card:active, .job-card:active,
  .bottom-nav-item:active, .super-tab:active, .action-filter:active, .back-btn:active {
    transform: none;
    opacity: 0.75;
  }
  .is-pending::after, #super-tab-content { animation: none; }
}
