/* Responsive layout and dialog containment for the isolated staging candidate. */
:root {
  --app-safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-safe-top: env(safe-area-inset-top, 0px);
}

html { min-width: 320px; }
body { overflow-x: hidden; }
button, input, select, textarea { max-width: 100%; }

/* Keep dialogs inside the visible viewport and let long forms scroll as one layer. */
.modal {
  position: fixed;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: max(12px, var(--app-safe-top)) 12px calc(12px + var(--app-safe-bottom));
  place-items: center;
}
.modal-card {
  width: min(640px, 100%);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px - var(--app-safe-top) - var(--app-safe-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin: auto;
  overflow-wrap: anywhere;
}
.plan-modal-card { width: min(1000px, 100%); max-height: calc(100dvh - 24px - var(--app-safe-top) - var(--app-safe-bottom)); }
.plan-table { max-height: min(48vh, 440px); }

@media (min-width: 901px) and (max-width: 1200px) {
  .shell { grid-template-columns: 200px minmax(0, 1fr); }
  .main { padding: 20px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app { min-height: 100dvh; height: auto; overflow: visible; }
  .shell { height: auto; min-height: calc(100dvh - 72px); overflow: visible; }
  .main { height: auto; min-height: 0; overflow: visible; }
  .sidebar { position: sticky; top: 0; z-index: 4; }
  .sidebar .nav { display: flex !important; flex-direction: row !important; flex-wrap: nowrap; min-width: max-content; overflow-x: auto; scrollbar-width: thin; }
  .sidebar .nav button { flex: 0 0 auto; }
  .toolbar { flex-wrap: wrap; }
  .toolbar > * { min-width: 0; }
  .panel { max-width: 100%; }
}

@media (max-width: 600px) {
  .topbar { position: sticky; top: 0; min-height: 60px; height: auto; padding-top: max(7px, var(--app-safe-top)); z-index: 5; }
  .brand { min-width: 0; gap: 8px; }
  .brand strong { font-size: 15px; }
  .brand small { font-size: 10px; }
  .who { min-width: 0; }
  .shell { min-height: calc(100dvh - 60px); }
  .sidebar { top: calc(60px + var(--app-safe-top)); padding: 5px 7px; }
  .nav { gap: 4px; }
  .nav button { padding: 9px 11px; font-size: 12px; }
  .main { padding: 12px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { min-width: 0; padding: 12px; }
  .card strong { font-size: 20px; overflow-wrap: anywhere; }
  .page-head { align-items: stretch; }
  .page-head h2 { font-size: 19px; }
  .page-head > * { min-width: 0; }
  .form-grid, .settings { grid-template-columns: minmax(0, 1fr); }
  .form-grid .full, .holiday-setting { grid-column: auto; }
  .modal { align-items: start; padding: max(8px, var(--app-safe-top)) 8px calc(8px + var(--app-safe-bottom)); }
  .modal-card, .plan-modal-card { width: 100%; max-height: calc(100dvh - 16px - var(--app-safe-top) - var(--app-safe-bottom)); border-radius: 13px; padding: 16px; }
  .date-wheels { gap: 5px; margin: 12px 0; }
  .date-wheel select { height: min(34dvh, 210px); min-height: 140px; padding: 4px 2px; font-size: 14px; }
  .service-row { grid-template-columns: auto minmax(0, 1fr) minmax(78px, 95px); gap: 6px; padding: 7px; font-size: 12px; }
  .price-summary { grid-template-columns: minmax(0, 1fr); }
  .actions { flex-wrap: wrap; }
  .actions .btn { flex: 1 1 130px; min-height: 42px; }
  .toast { left: 10px; right: 10px; bottom: calc(10px + var(--app-safe-bottom)); text-align: center; }
}

@media (max-width: 380px) {
  .brand small { display: none; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .date-wheel label { font-size: 10px; }
  .date-wheel select { font-size: 12px; }
  .modal-card, .plan-modal-card { padding: 13px; }
}

@media (min-width: 901px) {
  .modal { padding: 20px; }
  .modal-card { max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); }
}
