/**
 * Flowo 2.2 - Chat List Screen Styles v3.0 (Stage 19.6)
 * Slot-Based Architecture + Design Tokens + Screen States (UX Laws Baseline)
 * 
 * Changes from v1.0:
 * - Added Screen States: loading (.skel), reconnect (.dead-banner),
 *   error (.err-box), success (.ok-box), retry (.btn-retry).
 * - Extended .empty-state with icon + subtext (UX-03 skeletons, UX-11 recovery).
 * - Added prefers-reduced-motion respect (UX-09).
 * - Added compact density adaptation (UX-08).
 */

/* ============================================================
 * 1. LAYOUT SLOTS (Grid Architecture)
 * ============================================================ */
.chat-list-screen {
  display: grid;
  grid-template-areas: 
    "header"
    "list";
  grid-template-rows: auto 1fr;
  height: 100%;
  width: 100%;
  background-color: var(--color-bg-primary);
}

.chat-list-header {
  grid-area: header;
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--color-border-default);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-list-container {
  grid-area: list;
  overflow-y: auto;
  padding: var(--spacing-sm);
  /* Scrollbar styling for native feel */
  scrollbar-width: thin;
  scrollbar-color: var(--color-text-secondary) transparent;
}

/* ============================================================
 * 2. CHAT ITEM COMPONENT (Slot-Based Grid)
 * ============================================================ */
.chat-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: var(--spacing-md);
  align-items: center;
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-xs);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
  position: relative;
}

.chat-item:hover {
  background-color: var(--color-bg-secondary);
}

.chat-item:active {
  transform: scale(0.99);
}

/* Platform Marker (Slot-based positioning) */
.platform-marker {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  opacity: 0.8;
}

.platform-wa { background-color: var(--color-brand-wa); }
.platform-tg { background-color: var(--color-brand-tg); }
.platform-max { background-color: var(--color-brand-max); }

/* Avatar with Native Fallback */
.chat-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: white;
  background-color: var(--color-bg-tertiary);
  box-shadow: var(--shadow-sm);
}

.chat-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0; /* Prevents text overflow issues in Grid */
}

.chat-name {
  font-weight: 600;
  font-size: var(--font-size-md);
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-last-message {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--spacing-xs);
}

.chat-time {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.chat-badge {
  background-color: var(--color-text-accent);
  color: white;
  font-size: var(--font-size-xs);
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-xl);
  min-width: 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

/* ============================================================
 * 3. SCREEN STATES (UX Laws Baseline 19.6)
 * Ported from flowo-rig-v5.1.html etalon, adapted to project tokens.
 * ============================================================ */

/* --- 3.1 Empty State (UX-03 baseline) --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 40vh;
  padding: var(--spacing-lg);
  color: var(--color-text-secondary);
  font-size: var(--font-size-md);
  gap: var(--spacing-md);
  text-align: center;
  animation: state-fade-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.empty-state .state-icon {
  font-size: 52px;
  line-height: 1;
  opacity: 0.7;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.15));
}

.empty-state .state-text {
  font-size: var(--font-size-md);
  color: var(--color-text-primary);
  font-weight: 600;
}

.empty-state .state-subtext {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  max-width: 340px;
  line-height: 1.6;
}

/* --- 3.2 Loading: Skeletons (UX-03, Assertion A5) --- */
.skeleton-loader {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  padding: 0 var(--spacing-sm);
}

.skel {
  height: 68px;
  border-radius: var(--radius-md);
  background: linear-gradient(
    90deg,
    var(--color-bg-secondary) 0%,
    var(--color-bg-tertiary) 50%,
    var(--color-bg-secondary) 100%
  );
  background-size: 220% 100%;
  animation: skel-shim calc(1.3s / var(--motion, 1)) linear infinite;
}

.skel:nth-child(1) { width: 100%; }
.skel:nth-child(2) { width: 92%; }
.skel:nth-child(3) { width: 84%; }

@keyframes skel-shim {
  to { background-position: -220% 0; }
}

@keyframes state-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- 3.3 Reconnect Banner (эталон .dead-banner.warn, UX-05 honest connection) --- */
.dead-banner {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 13px var(--spacing-md);
  flex-wrap: wrap;
  border-bottom: 1px solid var(--color-border-warning, rgba(255, 176, 32, 0.45));
  background: var(--color-bg-warning, rgba(255, 176, 32, 0.11));
  animation: state-fade-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.dead-banner.warn {
  border-bottom-color: var(--color-border-warning, rgba(255, 176, 32, 0.45));
  background: var(--color-bg-warning, rgba(255, 176, 32, 0.11));
}

.dead-banner.error {
  border-bottom-color: var(--color-border-danger, rgba(255, 77, 94, 0.45));
  background: var(--color-bg-danger, rgba(255, 77, 94, 0.12));
}

.dead-banner.info {
  border-bottom-color: var(--color-border-info, rgba(56, 189, 248, 0.45));
  background: var(--color-bg-info, rgba(56, 189, 248, 0.10));
}

.dead-banner .bi {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  flex: none;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  background: var(--color-bg-warning, rgba(255, 176, 32, 0.25));
  color: var(--color-text-warning, #FFB020);
}

.dead-banner.error .bi {
  background: var(--color-bg-danger, rgba(255, 77, 94, 0.25));
  color: var(--color-text-danger, #FF4D5E);
}

.dead-banner.info .bi {
  background: var(--color-bg-info, rgba(56, 189, 248, 0.25));
  color: var(--color-text-info, #38BDF8);
}

.dead-banner .bt {
  flex: 1;
  min-width: 180px;
  font-size: var(--font-size-sm);
}

.dead-banner .bt b {
  display: block;
  color: var(--color-text-primary);
  font-weight: 600;
}

.dead-banner .bt small {
  display: block;
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  margin-top: 3px;
}

.dead-banner .btn-retry {
  margin-left: auto;
}

/* --- 3.4 Inline Error Box (эталон .err-box, UX-11) --- */
.err-box {
  border: 1px solid var(--color-border-danger, rgba(255, 77, 94, 0.45));
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  background: var(--color-bg-danger, rgba(255, 77, 94, 0.10));
}

.err-box b {
  display: block;
  color: var(--color-text-danger, #FF4D5E);
  font-size: var(--font-size-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.err-box p {
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  line-height: 1.5;
}

/* --- 3.5 Success Box (эталон .ok-box) --- */
.ok-box {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 6px 0;
}

.ok-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--color-bg-success, rgba(34, 197, 94, 0.18));
  border: 1px solid var(--color-border-success, rgba(34, 197, 94, 0.50));
  color: var(--color-text-success, #22C55E);
  animation: ok-pop calc(0.5s / var(--motion, 1)) cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes ok-pop {
  from { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.12); }
}

/* --- 3.6 Retry Button (UX-11 error recovery) --- */
.btn-retry {
  margin-top: 8px;
  padding: 9px 13px;
  border: 1px solid var(--color-border-danger, rgba(255, 77, 94, 0.45));
  background: var(--color-bg-danger, rgba(255, 77, 94, 0.16));
  color: var(--color-text-danger, #FF4D5E);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: var(--font-size-xs);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.18s ease, transform 0.1s ease;
}

.btn-retry:hover {
  background: var(--color-bg-danger, rgba(255, 77, 94, 0.26));
}

.btn-retry:active {
  transform: scale(0.97);
}

/* ============================================================
 * 4. ACCESSIBILITY: prefers-reduced-motion (UX-09)
 * ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .skel,
  .dead-banner,
  .ok-ring,
  .empty-state,
  .btn-retry {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================================
 * 5. DENSITY: compact mode adaptation (UX-08)
 * ============================================================ */
[data-density="compact"] .chat-item {
  grid-template-columns: 44px 1fr auto;
  padding: var(--spacing-sm);
  margin-bottom: 2px;
}

[data-density="compact"] .chat-avatar {
  width: 44px;
  height: 44px;
  font-size: var(--font-size-md);
}

[data-density="compact"] .empty-state {
  min-height: 28vh;
  padding: var(--spacing-md);
}

[data-density="compact"] .skel {
  height: 52px;
}

[data-density="compact"] .dead-banner {
  padding: 9px var(--spacing-sm);
}
