/* ─────────────────────────────────────────────────────────
 * BUTTON
 * ───────────────────────────────────────────────────────── */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-8);
  min-height: var(--tap-min);
  padding: 0 var(--s-20);
  font-size: var(--fs-17);
  font-weight: 600;
  border-radius: var(--r-12);
  background: var(--accent);
  color: var(--text-inverse);
  transition: transform var(--t-fast) var(--ease-ios), background var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
  background: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--block { width: 100%; }

.btn--secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn--secondary:active:not(:disabled) {
  background: var(--bg-primary);
}

.btn--ghost {
  background: transparent;
  color: var(--accent);
}

.btn--ghost:active:not(:disabled) {
  background: var(--accent-soft);
}

.btn--loading { pointer-events: none; }
.btn--loading .btn__label { opacity: 0; }
.btn--loading::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─────────────────────────────────────────────────────────
 * FIELD (label + input + error)
 * ───────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.field__label {
  font-size: var(--fs-13);
  font-weight: 500;
  color: var(--text-secondary);
  padding-left: var(--s-4);
}

.field__wrap {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  height: 52px;
  padding: 0 var(--s-16);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-12);
  transition: border-color var(--t-fast), background var(--t-fast);
}

.field__wrap:focus-within {
  border-color: var(--accent);
}

.field__wrap--error {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.field__icon {
  flex-shrink: 0;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
}

.field__wrap:focus-within .field__icon {
  color: var(--accent);
}

.field__input {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-17);
  color: var(--text-primary);
  background: transparent;
}

.field__input::placeholder {
  color: var(--text-tertiary);
}

.field__action {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: var(--r-8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.field__action:active {
  background: var(--bg-primary);
}

.field__error {
  font-size: var(--fs-13);
  color: var(--danger);
  padding-left: var(--s-4);
  min-height: 18px;
  line-height: 1.3;
}

/* ─────────────────────────────────────────────────────────
 * CHECKBOX
 * ───────────────────────────────────────────────────────── */
.check {
  display: inline-flex;
  align-items: center;
  gap: var(--s-8);
  cursor: pointer;
  min-height: var(--tap-min);
  padding: var(--s-4);
  position: relative;
}

.check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.check__box {
  flex-shrink: 0;
  width: 20px; height: 20px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-4);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  transition: all var(--t-fast);
}

.check input:checked + .check__box {
  background: var(--accent);
  border-color: var(--accent);
}

.check input:checked + .check__box::after {
  content: '';
  width: 6px; height: 11px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.check__label {
  font-size: var(--fs-15);
  color: var(--text-primary);
}

/* ─────────────────────────────────────────────────────────
 * TOAST
 * ───────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--safe-top) + var(--s-16));
  left: var(--s-16);
  right: var(--s-16);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: var(--s-8);
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border-radius: var(--r-12);
  padding: var(--s-12) var(--s-16);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-15);
  font-weight: 500;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--s-12);
  animation: toast-in 220ms var(--ease-spring);
  border-left: 3px solid var(--accent);
}

.toast--error   { border-left-color: var(--danger); }
.toast--success { border-left-color: var(--success); }
.toast--warning { border-left-color: var(--warning); }

.toast--out { animation: toast-out 180ms var(--ease-ios) forwards; }

@keyframes toast-in {
  from { transform: translateY(-120%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

@keyframes toast-out {
  to { transform: translateY(-120%); opacity: 0; }
}

/* ─────────────────────────────────────────────────────────
 * MISC
 * ───────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: var(--s-32);
  color: var(--text-secondary);
  gap: var(--s-8);
}

/* Shake — for invalid form submissions */
.shake { animation: shake 380ms cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* Page transition (used by route swapper) */
.page-enter {
  animation: page-in var(--t-base) var(--ease-ios);
}
@keyframes page-in {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─────────────────────────────────────────────────────────
 * APP SHELL: tab-page layout, header, tab strip, bottom-nav
 * ───────────────────────────────────────────────────────── */
.tab-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.tab-page__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--s-16));
  -webkit-overflow-scrolling: touch;
}

.app-header {
  min-height: var(--header-h);
  padding-top: var(--safe-top);
  padding-left: var(--s-16);
  padding-right: var(--s-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-12);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.app-header h1 {
  flex: 1;
  font-size: var(--fs-22);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.icon-btn {
  width: 40px; height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border-radius: var(--r-12);
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active:not(:disabled) {
  background: var(--bg-primary);
  color: var(--accent);
  transform: scale(0.94);
}
.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.icon-btn--accent { color: var(--accent); }
.icon-btn--danger { color: var(--danger); }

.tab-strip {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--s-4);
  gap: var(--s-4);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.tab-strip::-webkit-scrollbar { display: none; }

.tab-strip__item {
  flex-shrink: 0;
  padding: var(--s-12) var(--s-16);
  font-size: var(--fs-15);
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color var(--t-fast), border-color var(--t-fast);
  min-height: 44px;
  white-space: nowrap;
}
.tab-strip__item.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.search-bar {
  padding: var(--s-8) var(--s-16);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.search-bar__input {
  width: 100%;
  height: 40px;
  padding: 0 var(--s-12);
  background: var(--bg-primary);
  border-radius: var(--r-12);
  font-size: var(--fs-15);
}

/* ─────────────────────────────────────────────────────────
 * AVATAR
 * ───────────────────────────────────────────────────────── */
.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: visible;
  flex-shrink: 0;
}
.avatar > img,
.avatar > span:not(.avatar__ch) {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar__ch {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
}
.avatar__ch--whatsapp  { background: var(--ch-whatsapp); }
.avatar__ch--instagram { background: var(--ch-instagram); }
.avatar__ch--facebook  { background: var(--ch-facebook); }
.avatar__ch--telegram  { background: var(--ch-telegram); }
.avatar__ch--live-chat { background: var(--ch-livechat); }

/* ─────────────────────────────────────────────────────────
 * VIEW STACK (router) — tabs crossfade, details slide
 * ───────────────────────────────────────────────────────── */
.views-stack {
  position: relative;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

.views-stack > .view {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* Tab views — instant swap. The bottom-nav indicator slide is the visual
   feedback; content itself should appear with zero delay. */
.views-stack > .view--tab {
  display: none;
}
.views-stack > .view--tab.is-visible {
  display: block;
}

/* Detail views — iOS-style horizontal slide */
.views-stack > .view--detail {
  transform: translateX(100%);
  transition: transform 320ms var(--ease-ios);
  background: var(--bg-primary);
  z-index: 5;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.04);
}
.views-stack > .view--detail.is-visible {
  transform: translateX(0);
}
.views-stack > .view--detail.is-leaving {
  transform: translateX(100%);
  pointer-events: none;
}

/* Auth view — neutral, no animation */
.views-stack > .view--auth {
  opacity: 1;
}

/* ─────────────────────────────────────────────────────────
 * BOTTOM NAV — floating pill with sliding indicator
 * ───────────────────────────────────────────────────────── */
bottom-nav { display: contents; }
bottom-nav[hidden] { display: none; }

.bottom-nav {
  position: fixed;
  left: var(--s-12);
  right: var(--s-12);
  bottom: calc(var(--safe-bottom) + var(--s-8));
  height: var(--nav-h);
  z-index: 100;

  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px;

  background: rgba(255, 255, 255, 0.78);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  backdrop-filter: saturate(180%) blur(28px);
  border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: 32px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08),
              0 1px 3px rgba(0, 0, 0, 0.06);
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .bottom-nav { background: var(--bg-card); }
}

.bottom-nav__indicator {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 6px;
  width: calc((100% - 12px) / 4);
  background: rgba(0, 0, 0, 0.06);
  border-radius: 24px;
  transition: transform 220ms var(--ease-ios);
  z-index: 0;
  pointer-events: none;
}
.bottom-nav[data-active="chat"]          .bottom-nav__indicator { transform: translateX(0); }
.bottom-nav[data-active="customers"]     .bottom-nav__indicator { transform: translateX(100%); }
.bottom-nav[data-active="notifications"] .bottom-nav__indicator { transform: translateX(200%); }
.bottom-nav[data-active="profile"]       .bottom-nav__indicator { transform: translateX(300%); }

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--text-primary);
  transition: color var(--t-fast), transform 120ms var(--ease-ios);
  position: relative;
  z-index: 1;
  border-radius: 24px;
}
.bottom-nav__item:active {
  transform: scale(0.92);
}
.bottom-nav__item.is-active {
  color: var(--accent);
}

.bottom-nav__icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 26px;
}
.bottom-nav__icon-svg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.bottom-nav__icon svg { width: 24px; height: 24px; }

.bottom-nav__label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.bottom-nav__badge {
  position: absolute;
  top: -4px; right: -8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--danger);
  color: white;
  font-size: 9px;
  font-weight: 700;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 2px solid rgba(255, 255, 255, 0.9);
}

/* ─────────────────────────────────────────────────────────
 * LIST ITEM (shared by chat list, customers, notifications)
 * ───────────────────────────────────────────────────────── */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  padding: var(--s-12) var(--s-16);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--t-fast);
  min-height: 68px;
  position: relative;
}
.list-item:active {
  background: var(--bg-primary);
}
.list-item__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.list-item__name {
  font-size: var(--fs-15);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item__preview {
  font-size: var(--fs-13);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item__preview--unread {
  color: var(--text-primary);
  font-weight: 500;
}
.list-item__right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s-4);
}
.list-item__time {
  font-size: var(--fs-11);
  color: var(--text-tertiary);
}

.unread-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─────────────────────────────────────────────────────────
 * CHIP / TAG
 * ───────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-4);
  padding: 2px var(--s-8);
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-11);
  font-weight: 600;
}

/* ─────────────────────────────────────────────────────────
 * SKELETON LOADER
 * ───────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--border-subtle) 0%, #f5f5f5 50%, var(--border-subtle) 100%);
  background-size: 200% 100%;
  border-radius: var(--r-8);
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─────────────────────────────────────────────────────────
 * BOTTOM SHEET / CONFIRM DIALOG
 * ───────────────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 200;
  animation: fade-in 200ms var(--ease-ios);
}
.sheet-overlay--out { animation: fade-out 220ms var(--ease-ios) forwards; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-card);
  border-radius: var(--r-20) var(--r-20) 0 0;
  padding: var(--s-8) var(--s-8) calc(var(--safe-bottom) + var(--s-8));
  z-index: 201;
  animation: sheet-in 320ms var(--ease-spring);
  max-height: 80vh;
  overflow-y: auto;
}
.sheet--out { animation: sheet-out 220ms var(--ease-ios) forwards; }

.sheet__handle {
  width: 40px; height: 4px;
  background: var(--border-strong);
  border-radius: var(--r-full);
  margin: 8px auto var(--s-12);
}
.sheet__item {
  display: flex;
  align-items: center;
  gap: var(--s-12);
  padding: var(--s-16);
  font-size: var(--fs-17);
  color: var(--text-primary);
  border-radius: var(--r-12);
  min-height: var(--tap-min);
  width: 100%;
  text-align: left;
  background: transparent;
}
.sheet__item:active {
  background: var(--bg-primary);
}
.sheet__item--danger { color: var(--danger); }
.sheet__item__icon {
  width: 24px; height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.confirm-sheet {
  position: fixed;
  left: var(--s-16); right: var(--s-16); bottom: calc(var(--safe-bottom) + var(--s-16));
  background: var(--bg-card);
  border-radius: var(--r-20);
  padding: var(--s-24) var(--s-16) var(--s-16);
  z-index: 201;
  animation: sheet-in 320ms var(--ease-spring);
  max-width: 480px;
  margin: 0 auto;
}
.confirm-sheet__title {
  font-size: var(--fs-17);
  font-weight: 600;
  margin: 0 0 var(--s-8);
  text-align: center;
}
.confirm-sheet__msg {
  font-size: var(--fs-15);
  color: var(--text-secondary);
  margin: 0 0 var(--s-16);
  text-align: center;
}
.confirm-sheet__actions {
  display: flex;
  gap: var(--s-12);
}
.confirm-sheet__actions .btn { flex: 1; }

.btn--danger { background: var(--danger); }
.btn--danger:active:not(:disabled) { background: #D62D24; }

@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to   { opacity: 0; } }
@keyframes sheet-in  { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes sheet-out { to   { transform: translateY(100%); } }
