/* ==========================================================================
   Convo Monitor Responsive Components
   Spec: HotelEar_UIUX_Design.md §5, §11 + Premium Shell Motion §7, §9
   Mobile-first. Design tokens only.
   ========================================================================== */

/* ---------------------------------------------------------------- buttons / touch */
.btn { min-height: 40px; }
.btn:active { transform: scale(.98); transition-duration: 80ms; }

@media (hover: none) {
  .device-card:hover { transform: none; box-shadow: none; }
  tbody tr.clickable:hover { background: transparent; }
  .btn:hover { background: inherit; }
  .btn-primary:hover, .btn-danger:hover, .btn-success:hover { background: var(--primary); }
  .btn-primary.btn-danger:hover { background: var(--danger); }
}

/* ---------------------------------------------------------------- chips (quick tags / filter)
   Horizontal scroll with scroll-snap (settings tabs, filter chips). */

.chip {
  flex: 0 0 auto; scroll-snap-align: start;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; min-width: 44px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-2);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background var(--dur-fast) ease-out, color var(--dur-fast) ease-out, border-color var(--dur-fast) ease-out;
}
.chip:active { transform: scale(.97); }
.chip.is-active {
  background: var(--primary-soft); color: var(--primary);
  border-color: var(--primary);
}

/* ---------------------------------------------------------------- tabs (scroll-snap + fade edges) */
.tabs {
  display: flex; gap: 4px;
  margin: 0 calc(-1 * var(--content-pad));
  padding: 0 var(--content-pad);
  overflow-x: auto; scroll-snap-type: x mandatory; white-space: nowrap;
  border-bottom: 1px solid var(--border); margin-bottom: 18px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  position: relative;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs .tab, .tabs button {
  scroll-snap-align: start; min-height: 44px;
}

/* Fade edges for scrollable strips */
.fade-edges { position: relative; }
.fade-edges::before, .fade-edges::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 24px; z-index: 2;
  pointer-events: none; opacity: 0;
  transition: opacity var(--dur-fast) ease-out;
}
.fade-edges::before { left: 0; background: linear-gradient(to right, var(--bg), transparent); }
.fade-edges::after { right: 0; background: linear-gradient(to left, var(--bg), transparent); }
.fade-edges.has-left::before, .fade-edges.has-right::after { opacity: 1; }
.is-scrolled.fade-edges::before, .is-scrolled.fade-edges::after { background-size: 100% 100%; }

/* ---------------------------------------------------------------- forms (mobile-first)
   Inputs are 16px and 48px tall on phones to avoid iOS focus zoom + fat targets. */
label { font-size: 12.5px; }
input, select, textarea { min-height: var(--field-h); font-size: 16px; }
.filters { padding: 14px; gap: 8px; }
.filters label { margin: 0; }
.form-grid { grid-template-columns: minmax(0, 1fr); gap: 6px 14px; }

.switch-input { width: 44px; height: 26px; }
.switch-input::after { width: 20px; height: 20px; top: 2px; left: 2px; }
.switch-input:checked::after { transform: translateX(18px); }

/* ---------------------------------------------------------------- tables -> stacked cards (≤860) */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

@media (min-width: 861px) {
  input, select, textarea { font-size: 13.5px; }
  .form-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .filters { padding: 16px 20px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 860px) {
  /* ---- Pattern A: tables -> expandable cards ---- */
  .table-cards, .table-cards thead, .table-cards tbody,
  .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-wrap:has(.table-cards) { border: 0; background: transparent; box-shadow: none; padding: 0; }
  .table-cards thead { display: none; }
  .table-cards tbody { display: flex; flex-direction: column; gap: 10px; }
  .table-cards tr {
    position: relative;
    padding: 10px 14px 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
  }
  /* collapsed (key) cells */
  .table-cards td.is-primary {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 5px 0; border: 0; text-align: right; font-size: 13.5px;
  }
  .table-cards td.is-primary::before {
    content: attr(data-label); flex-shrink: 0;
    font-size: 11px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--text-3);
  }
  .table-cards td.is-primary:first-child { padding-top: 2px; }
  .table-cards td.is-primary > .cell-value { text-align: right; min-width: 0; overflow-wrap: anywhere; }
  .table-cards td.is-primary > .cell-value .muted { display: block; }
  /* expandable secondary panel */
  .table-cards td.cardify-panel {
    display: grid; grid-template-rows: 0fr;
    padding: 0; border: 0; overflow: hidden;
    transition: grid-template-rows var(--dur-slow) var(--ease-out);
  }
  .table-cards tr.is-open td.cardify-panel { grid-template-rows: 1fr; }
  .table-cards td.cardify-panel > .cardify-panel__inner { min-height: 0; overflow: hidden; }
  .table-cards td.cardify-panel td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 8px 0 0; border: 0; border-top: 1px dashed var(--border-light);
    margin-top: 8px; text-align: right; font-size: 13.5px;
  }
  .table-cards td.cardify-panel td > .cell-value { text-align: right; min-width: 0; overflow-wrap: anywhere; }
  .table-cards td.cardify-panel td.hide-sm { display: flex; }
  .table-cards td.cardify-panel td::before {
    content: attr(data-label); flex-shrink: 0;
    font-size: 11px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--text-3);
  }
  /* toggle footer */
  .table-cards td.cardify-toggle { display: flex; justify-content: center; padding: 8px 0 0; border: 0; }
  .table-cards .cardify-toggle__btn {
    display: inline-flex; align-items: center; gap: 7px;
    min-height: 40px; padding: 0 14px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
    border-radius: 999px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  }
  .table-cards .cardify-toggle__btn::after {
    content: ""; width: 7px; height: 7px; margin-top: -3px;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: rotate(45deg); transition: transform var(--dur-base) var(--ease-out);
  }
  .table-cards tr.is-open .cardify-toggle__btn::after { transform: rotate(-135deg); margin-top: 3px; }
  .table-cards td.empty { display: block; text-align: center; padding: 24px 12px; border: 0; }
  .table-cards td.empty::before { content: none; }
  .table-cards tr.clickable { cursor: pointer; }
  .table-cards tr.clickable:active { transform: scale(.985); }
  .table-cards .row { justify-content: flex-end; flex-wrap: wrap; }

  /* ---- Pattern C: real tables keep horizontal scroll with a sticky first column ---- */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; position: relative; }
  .table-scroll table { min-width: 480px; }
  .table-scroll th:first-child, .table-scroll td:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
  }
  .table-scroll thead th:first-child { z-index: 2; }
}

/* ---- containers that swap between table (desktop) and rich card list (mobile) ---- */
@media (max-width: 860px) { .hide-mobile { display: none !important; } }
.card-list-mobile { display: none; }
@media (max-width: 860px) { .card-list-mobile { display: flex; flex-direction: column; gap: 10px; } }

/* ---------------------------------------------------------------- modals -> bottom sheets (≤620) */
@media (max-width: 620px) {
  .modal-backdrop {
    align-items: flex-end; justify-content: center;
    padding: 0; z-index: 85;
  }
  .modal {
    width: 100%;
    max-height: 90dvh; border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
    padding: 14px 16px calc(16px + var(--safe-bottom));
    overflow-y: auto; overscroll-behavior: contain;
    transform: translateY(100%);
    transition: transform var(--dur-slow) var(--ease-out);
  }
  .modal::before {
    content: ""; display: block; width: 40px; height: 5px;
    margin: 0 auto 12px; border-radius: 3px; background: var(--surface-3);
  }
}
@media (min-width: 621px) and (max-width: 860px) {
  .modal { margin: auto 12px; }
}
.modal-backdrop { z-index: 85; }
.modal { max-height: 90dvh; overflow: auto; }

/* Edit drawers -> bottom sheet (≤860) */
@media (max-width: 860px) {
  .drawer-backdrop { align-items: flex-end; padding: 0; z-index: 85; }
  .drawer {
    width: 100%; height: 92dvh; max-height: 92dvh;
    border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
    transform: translateY(100%);
  }
  .drawer-backdrop.open .drawer { transform: translateY(0); }
  .drawer-body { padding: 16px 16px calc(16px + var(--safe-bottom)); }
}
.drawer-backdrop { z-index: 85; }

/* ---------------------------------------------------------------- bottom sheet primitive (CM.sheet) */
.sheet-root { position: fixed; inset: 0; z-index: 85; pointer-events: none; }
.sheet-overlay {
  position: absolute; inset: 0;
  background: var(--overlay);
  opacity: 0; transition: opacity var(--dur-base) ease-out;
  pointer-events: none;
}
.sheet {
  position: absolute; left: var(--safe-left); right: var(--safe-right); bottom: 0;
  display: flex; flex-direction: column;
  max-height: 96dvh;
  background: var(--sheet-bg);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  box-shadow: var(--shadow-3);
  padding-bottom: var(--safe-bottom);
  touch-action: pan-y;
  overscroll-behavior: contain;
  will-change: transform;
  transform: translateY(110%);
}
.sheet__handle {
  flex-shrink: 0; width: 40px; height: 5px; margin: 8px auto 4px;
  border-radius: 3px; background: var(--surface-3);
}
.sheet__head {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 4px 16px 8px;
}
.sheet__title { font-size: 16px; font-weight: 700; color: var(--text); margin: 0; }
.sheet__close {
  width: 44px; height: 44px; margin-right: -8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text-2); cursor: pointer; border-radius: var(--radius-sm);
}
.sheet__close:active { transform: scale(.94); }
.sheet__body { flex: 1; overflow-y: auto; padding: 6px 16px 16px; overscroll-behavior: contain; touch-action: pan-y; }
.sheet.is-open { transform: translateY(0); }
.sheet.is-full { height: 92dvh; max-height: 92dvh; }
.sheet.is-half { height: 52dvh; }
.sheet-root.is-open .sheet-overlay { opacity: 1; pointer-events: auto; }
.sheet-root.is-open { pointer-events: auto; }
@media (min-width: 861px) {
  .sheet { left: 50%; right: auto; bottom: 16px; width: min(560px, calc(100vw - 48px)); transform: translate(-50%, calc(100% + 24px)); border-radius: var(--sheet-radius); border-bottom: 1px solid var(--border); }
  .sheet.is-open { transform: translate(-50%, 0); }
}

/* Toasts on phones: mobile.css (top of the screen). */
.toasts { z-index: 90; }
.toast { pointer-events: auto; }

/* ---------------------------------------------------------------- dropdown menus on small screens */
.dropdown-menu { max-width: calc(100vw - 32px); max-height: 60vh; overflow-y: auto; }
@media (max-width: 860px) {
  .dropdown-item { min-height: 44px; }
}

/* ---------------------------------------------------------------- empty / offline states */
.empty { text-align: center; color: var(--text-3); padding: 28px 16px; font-size: 13.5px; }
.card.empty { background: var(--surface); }

/* ---------------------------------------------------------------- mobile "filters" launcher */
.mobile-filters-btn { display: none; }
@media (max-width: 860px) {
  .mobile-filters-btn { display: inline-flex; }
  form.card.filters { display: none; }
  .sheet form.filters, .sheet .filters {
    display: grid;
    border: 0; box-shadow: none; background: transparent;
    padding: 0; margin: 0;
  }
}

/* ---------------------------------------------------------------- forms with sticky bottom actions */

/* ---------------------------------------------------------------- alerts sheet rows (CM.shell alerts) */

/* ---------------------------------------------------------------- scroll lock (drawer / sheet open) */
html.scroll-lock, html.scroll-lock body { overflow: hidden; }

/* ================================================================ */
/* Pattern A – rich expandable cards (incidents )                    */
/* ================================================================ */
.card-item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur-base) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.card-item:active { transform: scale(.99); }
.card-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.card-item.is-new { animation: card-slide-in var(--dur-slow) var(--ease-out); }
.card-item__body { padding: 12px 14px; }
.card-item__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.card-item__sev { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; color: var(--text-2); }
.card-item__sev i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.card-item[data-rail="high"] .card-item__sev { color: var(--high); }
.card-item[data-rail="high"] .card-item__sev i { background: var(--high); }
.card-item[data-rail="medium"] .card-item__sev { color: var(--warning-text); }
.card-item[data-rail="medium"] .card-item__sev i { background: var(--medium); }
.card-item[data-rail="low"] .card-item__sev { color: var(--info); }
.card-item[data-rail="low"] .card-item__sev i { background: var(--low); }
.card-item__time { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.card-item__title { font-size: 15px; font-weight: 600; line-height: 1.35; }
.card-item__sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.card-item__meta { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.card-item__handled { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); }
.card-item__handled b { font-weight: 600; color: var(--text); }
.card-item__avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-size: 10px; font-weight: 700; letter-spacing: .02em;
}
.card-item__chev { margin-left: auto; width: 9px; height: 9px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(45deg); transition: transform var(--dur-base) var(--ease-out); }
.card-item.is-open .card-item__chev { transform: rotate(-135deg); }
.card-item__panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 180ms var(--ease-out); }
.card-item.is-open .card-item__panel { grid-template-rows: 1fr; }
.card-item__panel > .card-item__panel-inner { min-height: 0; overflow: hidden; }
.card-item__panel-content { padding: 0 14px 14px; border-top: 1px solid var(--border-light); margin-top: 2px; padding-top: 12px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-bottom: 12px; }
.kv-grid > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kv-grid dt { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }
.kv-grid dd { margin: 0; font-size: 13.5px; color: var(--text); overflow-wrap: anywhere; }
.ai-summary-block { background: var(--primary-soft); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; }
.ai-summary-block p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--text); }
.ai-summary-block .ai-tag { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--primary); margin-bottom: 4px; }
.card-item__actions { display: flex; gap: 8px; }
.card-item__actions .btn { flex: 1; min-height: 44px; justify-content: center; }

/* ---------------------------------------------------------------- skeleton cards / loading */
.skeleton-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.skeleton-card .skeleton.line { height: 12px; }
.skeleton-card .skeleton.line.w40 { width: 40%; }
.skeleton-card .skeleton.line.w70 { width: 70%; }
.skeleton-card .skeleton.line.w55 { width: 55%; }

/* ---------------------------------------------------------------- list states (empty / error / pager) */
.list-empty, .list-error {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 36px 20px; text-align: center;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-lg);
  color: var(--text-2); font-size: 13.5px;
}
.list-empty__icon, .list-error__icon { font-size: 26px; opacity: .8; }
.list-error { border-color: var(--danger); border-style: solid; background: var(--danger-soft); color: var(--text); }
.list-error .btn { margin-top: 4px; }

/* ---------------------------------------------------------------- Pattern B – compact 2-line list */
.list { display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 861px) { .list { display: none; } }
.list-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  min-height: 56px; padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.list-row:active { transform: scale(.99); }
.list-row:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.list-row__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.list-row__dot.ok { background: var(--success); }
.list-row__dot.danger { background: var(--danger); }
.list-row__dot.warning { background: var(--warning); }
.list-row__dot.info { background: var(--info); }
.list-row__main { min-width: 0; }
.list-row__title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row__sub { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row__side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.list-row__time { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.list-row__status { font-size: 11px; color: var(--text-3); text-transform: capitalize; }

/* ---------------------------------------------------------------- sticky filter chip bar */
.chip-bar {
  display: flex; gap: 8px; align-items: center;
  overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  padding: 8px 2px; margin: 0 0 4px;
  scrollbar-width: none;
}
.chip-bar::-webkit-scrollbar { display: none; }
.chip-bar .chip { flex: 0 0 auto; }
.chip-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
  background: rgba(255, 255, 255, .28); border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.chip.is-active .chip-badge { background: rgba(255, 255, 255, .35); }
@media (max-width: 860px) {
  .chip-bar {
    position: sticky; top: calc(var(--safe-top) + var(--topbar-h-sm)); z-index: 20;
    background: var(--bg); padding: 8px var(--content-pad);
    margin: 0 calc(-1 * var(--content-pad)) 6px;
  }
}

/* ---------------------------------------------------------------- "N new incidents" pill */
.new-items-pill {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 12px);
  z-index: 60;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  background: var(--primary); color: var(--primary-ink);
  border: none; border-radius: 999px; box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 600; cursor: pointer;
  animation: rise-in var(--dur-base) var(--ease-out);
}
.new-items-pill:active { transform: translateX(-50%) scale(.97); }
@media (min-width: 861px) { .new-items-pill { bottom: 24px; } }

/* ---------------------------------------------------------------- Pattern C swipe hint */
.swipe-hint {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-3);
  padding: 4px 10px; margin: 0 0 6px;
  background: var(--surface-2); border-radius: 999px;
  animation: rise-in var(--dur-base) var(--ease-out);
}

/* ---------------------------------------------------------------- reduced motion: instant state changes */
@media (prefers-reduced-motion: reduce) {
  .card-item, .card-item__panel, .card-item__chev,
  .table-cards td.cardify-panel, .table-cards .cardify-toggle__btn::after,
  .card-item.is-new { transition: none !important; animation: none !important; }
}
/* incident card: the AI summary as a two-line preview under the title */
.card-item__summary {
  margin: 6px 0 0; font-size: 13.5px; line-height: 1.45; color: var(--text-2);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.card-item[aria-expanded="true"] .card-item__summary { display: none; }  /* the full text is in the panel */
