/**
 * RC Status grid + utilities — Bootstrap CSS replacement (Phase 4)
 * Flexbox grid compatible with existing Status markup (row/col-*).
 * No Bootstrap dependency. RC 5.2.5
 */

/* Box model */
.status-app, .status-app *, .modal, .modal *, .offcanvas-lg, .offcanvas-lg * {
  box-sizing: border-box;
}

/* Container */
.container {
  width: 100%;
  max-width: 1140px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 12px;
  padding-right: 12px;
}
.container-fluid {
  width: 100%;
  padding-left: 12px;
  padding-right: 12px;
}

/* Grid */
.row {
  display: flex;
  flex-wrap: wrap;
  margin-left: -8px;
  margin-right: -8px;
}
.row > * {
  padding-left: 8px;
  padding-right: 8px;
  max-width: 100%;
}
.g-1 { --rc-g: 4px; margin-left: calc(var(--rc-g) * -1); margin-right: calc(var(--rc-g) * -1); }
.g-1 > * { padding-left: var(--rc-g); padding-right: var(--rc-g); }
.g-2 { --rc-g: 8px; margin-left: calc(var(--rc-g) * -1); margin-right: calc(var(--rc-g) * -1); }
.g-2 > * { padding-left: var(--rc-g); padding-right: var(--rc-g); }
.g-3 { --rc-g: 12px; margin-left: calc(var(--rc-g) * -1); margin-right: calc(var(--rc-g) * -1); }
.g-3 > * { padding-left: var(--rc-g); padding-right: var(--rc-g); }
.g-4 { --rc-g: 16px; margin-left: calc(var(--rc-g) * -1); margin-right: calc(var(--rc-g) * -1); }
.g-4 > * { padding-left: var(--rc-g); padding-right: var(--rc-g); }

.col, .col-12 { flex: 0 0 100%; width: 100%; }
.col-6 { flex: 0 0 50%; width: 50%; }

@media (min-width: 576px) {
  .col-sm-6 { flex: 0 0 50%; width: 50%; }
}
@media (min-width: 768px) {
  .col-md-3 { flex: 0 0 25%; width: 25%; }
  .col-md-4 { flex: 0 0 33.3333%; width: 33.3333%; }
  .col-md-6 { flex: 0 0 50%; width: 50%; }
  .col-md-8 { flex: 0 0 66.6667%; width: 66.6667%; }
  .col-md-12 { flex: 0 0 100%; width: 100%; }
  .ms-md-3 { margin-left: 1rem !important; }
  .px-md-4 { padding-left: 1.5rem !important; padding-right: 1.5rem !important; }
  .p-md-4 { padding: 1.5rem !important; }
}
@media (min-width: 992px) {
  .col-lg-3 { flex: 0 0 25%; width: 25%; }
  .col-lg-4 { flex: 0 0 33.3333%; width: 33.3333%; }
  .col-lg-5 { flex: 0 0 41.6667%; width: 41.6667%; }
  .col-lg-7 { flex: 0 0 58.3333%; width: 58.3333%; }
  .col-lg-8 { flex: 0 0 66.6667%; width: 66.6667%; }
  .col-lg-9 { flex: 0 0 75%; width: 75%; }
  .col-lg-12 { flex: 0 0 100%; width: 100%; }
}

/* Display */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-flex { display: flex !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.flex-column { flex-direction: column !important; }
.flex-row { flex-direction: row !important; }
.flex-grow-1 { flex-grow: 1 !important; }
.flex-fill { flex: 1 1 auto !important; }
.flex-shrink-0 { flex-shrink: 0 !important; }
.flex-wrap { flex-wrap: wrap !important; }
.align-items-center { align-items: center !important; }
.align-items-start { align-items: flex-start !important; }
.align-items-end { align-items: flex-end !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-center { justify-content: center !important; }
.justify-content-end { justify-content: flex-end !important; }
.gap-1 { gap: 0.25rem !important; }
.gap-2 { gap: 0.5rem !important; }
.gap-3 { gap: 1rem !important; }

@media (min-width: 576px) {
  .d-sm-inline { display: inline !important; }
  .d-sm-block { display: block !important; }
  .d-sm-none { display: none !important; }
  .flex-sm-row { flex-direction: row !important; }
}
@media (min-width: 768px) {
  .d-md-inline { display: inline !important; }
  .d-md-block { display: block !important; }
  .d-md-none { display: none !important; }
  .d-md-flex { display: flex !important; }
}
@media (min-width: 992px) {
  .d-lg-none { display: none !important; }
  .d-lg-block { display: block !important; }
  .d-lg-flex { display: flex !important; }
  .d-lg-inline { display: inline !important; }
}

/* Spacing */
.m-0 { margin: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mb-5 { margin-bottom: 3rem !important; }
.mt-0 { margin-top: 0 !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mt-4 { margin-top: 1.5rem !important; }
.ms-0 { margin-left: 0 !important; }
.ms-1 { margin-left: 0.25rem !important; }
.ms-2 { margin-left: 0.5rem !important; }
.me-1 { margin-right: 0.25rem !important; }
.me-2 { margin-right: 0.5rem !important; }
.me-3 { margin-right: 1rem !important; }
.p-0 { padding: 0 !important; }
.p-2 { padding: 0.5rem !important; }
.p-3 { padding: 1rem !important; }
.p-4 { padding: 1.5rem !important; }
.px-2 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
.px-3 { padding-left: 1rem !important; padding-right: 1rem !important; }
.px-4 { padding-left: 1.5rem !important; padding-right: 1.5rem !important; }
.py-1 { padding-top: 0.25rem !important; padding-bottom: 0.25rem !important; }
.py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.py-3 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.py-4 { padding-top: 1.5rem !important; padding-bottom: 1.5rem !important; }

/* Text */
.text-center { text-align: center !important; }
.text-start { text-align: left !important; }
.text-end { text-align: right !important; }
.text-muted, .text-secondary { color: var(--rc-ink-muted, #605e5c) !important; }
.text-dark { color: var(--rc-ink, #201f1e) !important; }
.text-white { color: #fff !important; }
.text-danger { color: #b91c1c !important; }
.fw-bold, .fw-black { font-weight: 700 !important; }
.fw-semibold { font-weight: 600 !important; }
.fw-black { font-weight: 900 !important; }

/* Sizing */
.w-100 { width: 100% !important; }
.h-100 { height: 100% !important; }

/* Borders / radius */
.border { border: 1px solid var(--rc-border, #e1dfdd) !important; }
.border-0 { border: 0 !important; }
.border-2 { border-width: 2px !important; }
.border-bottom { border-bottom: 1px solid var(--rc-border, #e1dfdd) !important; }
.rounded { border-radius: 8px !important; }
.rounded-pill { border-radius: 999px !important; }

/* Buttons (minimal — Status still styles via app.css) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.25;
  padding: 0.4rem 0.85rem;
  min-height: 32px;
  border-radius: 8px;
  border: 1px solid var(--rc-border, #e1dfdd);
  background: var(--rc-card, #fff);
  color: var(--rc-ink, #201f1e);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { filter: brightness(0.98); }
.btn-sm { min-height: 28px; padding: 0.25rem 0.6rem; font-size: 0.8125rem; }
.btn-primary {
  background: var(--rc-accent, #0f6cbd);
  border-color: var(--rc-accent, #0f6cbd);
  color: #fff !important;
}
.btn-close {
  width: 1rem;
  height: 1rem;
  padding: 0.25rem;
  border: 0;
  background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
  opacity: 0.55;
  cursor: pointer;
}
.btn-close:hover { opacity: 0.9; }
html[data-theme="dark"] .btn-close {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23fff'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e");
}
.shadow-none { box-shadow: none !important; }

/* Badge / alert */
.badge {
  display: inline-block;
  padding: 0.2em 0.55em;
  font-size: 0.75em;
  font-weight: 700;
  border-radius: 6px;
  background: var(--rc-paper, #f3f2f1);
  color: var(--rc-ink, #201f1e);
}
.badge.rounded-pill { border-radius: 999px; }
.text-bg-secondary {
  background: #6b7280 !important;
  color: #fff !important;
}
.alert {
  position: relative;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--rc-border, #e1dfdd);
  border-radius: 8px;
  background: var(--rc-paper, #faf9f8);
  color: var(--rc-ink, #201f1e);
}

/* Modal shell (layout; open state in rc-status-chrome) */
.modal-dialog { pointer-events: auto; }
.modal-content {
  background: var(--rc-card, #fff);
  color: var(--rc-ink, #201f1e);
  border: 1px solid var(--rc-border, #e1dfdd);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.modal-header, .modal-footer {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  border-color: var(--rc-border, #e1dfdd);
}
.modal-header { border-bottom: 1px solid var(--rc-border, #e1dfdd); }
.modal-footer { border-top: 1px solid var(--rc-border, #e1dfdd); justify-content: flex-end; gap: 0.5rem; }
.modal-body { padding: 1rem 1.25rem; }
.modal-title { margin: 0; font-size: 1.15rem; font-weight: 700; }

/* bg helpers used in Status */
.bg-white { background-color: var(--rc-card, #fff) !important; }
.bg-light { background-color: var(--rc-paper, #f5f5f5) !important; }

/* ── Device / orientation / safe-area ───────────────────── */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  overflow-x: hidden;
  max-width: 100vw;
}
@supports (padding: max(0px)) {
  body {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .st-theme-seg {
    bottom: max(16px, env(safe-area-inset-bottom, 0px)) !important;
    right: max(16px, env(safe-area-inset-right, 0px)) !important;
  }
}

/* Touch targets on coarse pointers */
@media (pointer: coarse) {
  .btn, .tree-master-btn, .tree-selector, .btn-sidebar-toggle {
    min-height: 44px;
  }
  .st-theme-seg button {
    min-height: 36px;
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* Landscape phones / short viewport */
@media (max-height: 500px) and (orientation: landscape) {
  .modal .modal-dialog {
    margin: 0.5rem auto;
    max-height: 94vh;
  }
  .modal-body {
    max-height: 70vh;
    overflow-y: auto;
  }
  .st-theme-seg {
    transform: scale(0.92);
    transform-origin: bottom right;
  }
}

/* Print: hide chrome */
@media print {
  .st-theme-seg,
  .btn-sidebar-toggle,
  .rc-st-backdrop,
  .no-print {
    display: none !important;
  }
  body {
    background: #fff !important;
    color: #000 !important;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .offcanvas-lg.offcanvas-start,
  .rc-st-backdrop,
  .modal {
    transition: none !important;
  }
}
