/* ── Avora Design System v3 ─────────────────────────────────────── */

/* ── Design Tokens (dark default) ── */
:root {
  --bg:         #0a0a0a;
  --surface:    #1c1c1e;
  --surface2:   #2c2c2e;
  --surface3:   #3a3a3c;
  --text:       #f5f5f7;
  --text2:      #cccccc;
  --label:      #86868b;
  --accent:     #00e5ff;
  --accent2:    #00b8cc;
  --accent-text: #000000;   /* text on accent background */
  --ok:         #34c759;
  --warn:       #ff9f0a;
  --err:        #ff3b30;
  --line:       rgba(255,255,255,.1);
  --radius:     16px;
  --radius-sm:  12px;
  --shadow:     0 2px 16px rgba(0,0,0,.4);
  --shadow-sm:  0 1px 6px rgba(0,0,0,.25);

  /* legacy compat */
  --muted:   #888888;
  --panel:   #1e1e1e;
  --primary: #00e5ff;
}

/* ── Light Theme ── */
:root[data-theme="light"] {
  --bg:         #f2f2f7;
  --surface:    #ffffff;
  --surface2:   #e8e8ed;
  --surface3:   #d1d1d6;
  --text:       #1c1c1e;
  --text2:      #333333;
  --label:      #8e8e93;
  --accent:     #007aff;
  --accent2:    #0055cc;
  --accent-text: #ffffff;
  --ok:         #28a745;
  --warn:       #f59e0b;
  --err:        #dc2626;
  --line:       rgba(0,0,0,.1);
  --shadow:     0 2px 16px rgba(0,0,0,.1);
  --shadow-sm:  0 1px 6px rgba(0,0,0,.08);
  --muted:      #6b7280;
  --panel:      #ffffff;
  --primary:    #007aff;
}


/* ── Base — iOS pull-to-refresh + tap highlight ── */
*, *::before, *::after { box-sizing: border-box; }

/* Prevent iOS Safari pull-to-refresh on all pages */
html {
  height: 100%;
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  overscroll-behavior-y: none;      /* prevent pull-to-refresh globally */
  -webkit-tap-highlight-color: transparent;
  animation: pageFade .2s ease-out;
}
@keyframes pageFade { from { opacity: 0; } to { opacity: 1; } }

/* ── Typography ── */
p, td, li { font-size: 16px; line-height: 1.6; }
small, .time, .msg-time { font-size: 13px !important; color: var(--label); }
.card-val, .stat-val { font-size: 32px !important; font-weight: 800 !important; }
button, .btn { font-size: 16px; }
input, select, textarea { font-size: 16px; }

/* ── Cards ── */
.card {
  background: var(--surface) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-sm) !important;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: max(28px, env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  color: #fff;
  padding: 11px 22px; border-radius: 14px;
  font-size: 15px; font-weight: 500;
  white-space: nowrap; opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 9999; pointer-events: none;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { color: var(--ok); }
.toast.error   { color: var(--err); }
:root[data-theme="light"] .toast {
  background: rgba(30,30,30,.92);
}

/* ── Buttons ── */
button, .btn {
  position: relative;
  overflow: hidden;
  transition: opacity .2s, transform .12s, background .2s, box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer; font-family: inherit; font-size: 16px;
  border-radius: var(--radius-sm);
}
button:active, .btn:active { transform: scale(.96); opacity: .88; }
button:disabled, .btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.btn.loading {
  position: relative; color: transparent !important; pointer-events: none;
}
.btn.loading::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 16px; height: 16px;
  border: 2px solid rgba(128,128,128,.3);
  border-top-color: var(--accent);
  border-radius: 50%; animation: spin .5s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* ── Forms ── */
input, select, textarea {
  font-size: 16px; font-family: inherit;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  outline: none; line-height: 1.5;
  transition: border-color .25s, box-shadow .25s, background .25s;
}
input::placeholder, textarea::placeholder { color: var(--label); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(0,229,255,.18), 0 2px 12px rgba(0,229,255,.08) !important;
  background: var(--surface) !important;
}
:root[data-theme="light"] input:focus,
:root[data-theme="light"] select:focus,
:root[data-theme="light"] textarea:focus {
  box-shadow: 0 0 0 3px rgba(0,122,255,.18), 0 2px 12px rgba(0,122,255,.08) !important;
}
select option { background: var(--surface); color: var(--text); }

/* Floating label */
.field-wrap { position: relative; }
.field-wrap input:focus + label,
.field-wrap input:not(:placeholder-shown) + label {
  transform: translateY(-22px) scale(0.85);
  color: var(--accent);
}
.field-wrap label {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--label); font-size: 15px; pointer-events: none;
  transition: transform .2s, color .2s, font-size .2s;
  transform-origin: left center;
}

/* ── Skeleton ── */
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
  border-radius: 8px; pointer-events: none;
}
.skeleton-text   { height: 14px; margin-bottom: 8px; border-radius: 6px; }
.skeleton-title  { height: 20px; width: 60%; margin-bottom: 12px; border-radius: 6px; }
.skeleton-avatar { width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; }
.skeleton-card   { height: 80px; border-radius: var(--radius); margin-bottom: 12px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Loading State ── */
.state-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 20px; color: var(--label); gap: 12px;
}
.state-loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
.state-loading-text { font-size: 14px; }

/* ── Empty State ── */
.state-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center; color: var(--label);
}
.state-empty-icon {
  font-size: 44px; margin-bottom: 12px; line-height: 1;
  opacity: .7;
}
.state-empty-title {
  font-size: 16px; font-weight: 600; color: var(--text2);
  margin-bottom: 6px;
}
.state-empty-sub {
  font-size: 14px; color: var(--label); line-height: 1.5;
  max-width: 260px;
}
.state-empty-action {
  margin-top: 16px; padding: 10px 24px;
  border-radius: 99px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: var(--accent-text); font-size: 14px; font-weight: 700;
}

/* ── Error State ── */
.state-error {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center;
}
.state-error-icon { font-size: 40px; margin-bottom: 12px; }
.state-error-title {
  font-size: 16px; font-weight: 600; color: var(--err); margin-bottom: 6px;
}
.state-error-sub {
  font-size: 14px; color: var(--label); line-height: 1.5; margin-bottom: 16px;
}
.state-error-retry {
  padding: 10px 24px; border-radius: 99px;
  border: 1px solid var(--err); background: transparent;
  color: var(--err); font-size: 14px; font-weight: 600; cursor: pointer;
}
.state-error-retry:active { background: rgba(255,59,48,.08); }

/* ── Page-level error banner ── */
.error-banner {
  background: rgba(255,59,48,.1); border: 1px solid rgba(255,59,48,.25);
  border-radius: var(--radius-sm); padding: 12px 16px;
  color: var(--err); font-size: 14px; line-height: 1.5;
  display: none; margin-bottom: 12px;
}
.error-banner.show { display: block; }

/* ── Success banner ── */
.success-banner {
  background: rgba(52,199,89,.1); border: 1px solid rgba(52,199,89,.25);
  border-radius: var(--radius-sm); padding: 12px 16px;
  color: var(--ok); font-size: 14px; line-height: 1.5;
  display: none; margin-bottom: 12px;
}
.success-banner.show { display: block; }

/* ── Page transitions ── */
.page-exit { animation: pageExit .15s ease-in forwards; }
@keyframes pageExit { to { opacity: 0; transform: translateY(4px); } }

/* ── Card interactions ── */
.card-hover {
  transition: transform .2s ease, box-shadow .2s ease;
  cursor: pointer;
}
.card-hover:active {
  transform: scale(.98);
  box-shadow: 0 1px 6px rgba(0,0,0,.3) !important;
}

/* ── Message bubble entrance ── */
.bubble-in {
  animation: bubbleIn .22s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: scale(.88) translateY(6px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}

/* ── Status badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge-ok   { background: rgba(52,199,89,.15);  color: var(--ok); }
.badge-warn { background: rgba(255,159,10,.15); color: var(--warn); }
.badge-err  { background: rgba(255,59,48,.15);  color: var(--err); }
.badge-info { background: rgba(0,229,255,.12);  color: var(--accent); }
:root[data-theme="light"] .badge-ok   { background: rgba(40,167,69,.12); }
:root[data-theme="light"] .badge-warn { background: rgba(245,158,11,.12); }
:root[data-theme="light"] .badge-err  { background: rgba(220,38,38,.10); }
:root[data-theme="light"] .badge-info { background: rgba(0,122,255,.10); }

/* ── Offline Banner ── */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--err); color: #fff;
  font-size: 14px; font-weight: 600; text-align: center; padding: 8px;
  z-index: 8888; transform: translateY(-100%); transition: transform .3s ease;
}
.offline-banner.show { transform: translateY(0); }

/* ── Utility ── */
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.text-muted  { color: var(--label); }
.text-accent { color: var(--accent); }
.text-ok     { color: var(--ok); }
.text-err    { color: var(--err); }
.text-warn   { color: var(--warn); }
.fw-bold { font-weight: 700; }
.fw-black { font-weight: 900; }

/* ── Responsive ── */
@media (max-width: 390px) {
  /* iPhone SE / mini */
  body { font-size: 15px; }
  .card { border-radius: 12px !important; }
  h1 { font-size: clamp(22px, 6vw, 32px) !important; }
}

@media (max-width: 500px) {
  .stats-bar { flex-wrap: wrap; height: auto !important; padding: 8px 16px; gap: 10px 20px; }
  .grid { grid-template-columns: 1fr !important; }
  table { font-size: 14px; }
  th, td { padding: 10px 8px; }
  .wrap { padding: 0 12px; }
  .hide-mobile { display: none !important; }
}

@media (min-width: 768px) {
  /* iPad and up */
  .show-mobile { display: none !important; }
  .wrap, .main { max-width: 680px; margin-left: auto; margin-right: auto; }
}

@media (min-width: 1024px) {
  .wrap, .main { max-width: 900px; }
}

/* ── Safe area helpers ── */
.safe-top    { padding-top:    env(safe-area-inset-top,    0px); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0px); }

/* ── Page Nav (sticky header, used across pages) ── */
.nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.nav-back {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface2); border: none; color: var(--text);
  font-size: 18px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.nav-back:active { transform: scale(.9); }
.nav-title { flex: 1; font-size: 17px; font-weight: 700; }

/* ── Context Menu & Emoji Bar (shared by chat, team-chat, app) ── */
#_ctxOverlay { position: fixed; inset: 0; z-index: 9998; display: none; }
#_ctxBg {
  position: fixed; inset: 0; z-index: 9990;
  background: rgba(0,0,0,0); backdrop-filter: blur(0px); -webkit-backdrop-filter: blur(0px);
  display: none; transition: background .2s, backdrop-filter .2s, -webkit-backdrop-filter .2s;
}
#_ctxBg.on { background: rgba(0,0,0,.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
#_emojiBar {
  display: flex; align-items: center;
  background: rgba(30,30,32,.97); border-radius: 50px; padding: 6px 10px; gap: 2px;
  pointer-events: all; box-shadow: 0 4px 24px rgba(0,0,0,.4);
  animation: _ctxIn .18s cubic-bezier(.34,1.56,.64,1);
}
._emoji-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .12s, background .12s;
}
._emoji-btn:active { transform: scale(1.3); background: rgba(255,255,255,.1); }
._emoji-more {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.12); color: #aaa; font-size: 18px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
#_ctxMenu {
  position: fixed; z-index: 9999;
  background: rgba(30,30,32,.97); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 14px; padding: 4px; display: none; flex-direction: column;
  min-width: 180px; box-shadow: 0 8px 32px rgba(0,0,0,.5);
  border: 1px solid rgba(255,255,255,.08);
  pointer-events: all;
  animation: _ctxIn .18s cubic-bezier(.34,1.56,.64,1);
}
@keyframes _ctxIn { from { opacity: 0; transform: scale(.88); } to { opacity: 1; transform: scale(1); } }
._ctx-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-radius: 10px; color: #e5e5e5; font-size: 15px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
._ctx-item:active { background: rgba(255,255,255,.1); }
._ctx-item.danger { color: #ff453a; }
._ctx-sep { height: 1px; background: rgba(255,255,255,.08); margin: 2px 8px; }
._ctx-own { display: none; }
/* Prevent iOS native text-select on chat bubbles & context menu */
.msg,.bbl,#_ctxMenu,#_emojiBar,._ctx-item,._emoji-btn {
  -webkit-user-select: none !important; user-select: none !important;
  -webkit-touch-callout: none !important;
}
#_ctxMenu * { -webkit-user-select: none !important; user-select: none !important; }

/* ═══════════════════════════════════════════════════════════════════
   AVORA UNIFIED CHAT BUBBLE SYSTEM
   Used by: app.html (AI chat), chat.html (contacts/friends)
   Boris principle: AI chat = friend chat = same template
   ═══════════════════════════════════════════════════════════════════ */

/* Row container */
.bbl-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 2px;
  animation: bblIn .25s cubic-bezier(.34,1.56,.64,1) both;
}
.bbl-row.self {
  flex-direction: row-reverse;
}
@keyframes bblIn {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

/* Avatar */
.bbl-ava {
  width: 34px; height: 34px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  cursor: pointer;
}
.bbl-ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bbl-row.self .bbl-ava { order: 2; }

/* Wrap (bubble + meta) */
.bbl-wrap {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  gap: 3px;
}
.bbl-row.self .bbl-wrap { align-items: flex-end; }

/* Bubble */
.bbl {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
/* AI / incoming */
.bbl.ai {
  background: var(--surface2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
/* User / outgoing */
.bbl.user {
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 4px;
}
:root[data-theme="light"] .bbl.user { background: var(--accent); }

/* Media bubbles */
.bbl.media { padding: 4px; background: transparent !important; }
.bbl.media img { max-width: 220px; border-radius: 14px; display: block; }

/* Meta (time + tick) */
.bbl-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--label);
  padding: 0 2px;
}
.bbl-status { color: var(--accent); font-size: 12px; }

/* Date separator */
.bbl-date-sep {
  text-align: center;
  font-size: 12px;
  color: var(--label);
  padding: 8px 0;
  pointer-events: none;
}

/* Typing indicator */
.bbl-typing {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 2px;
}
.bbl-typing-dots {
  background: var(--surface2);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 10px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.bbl-typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--label);
  animation: bblTypeBounce 1.2s infinite;
}
.bbl-typing-dot:nth-child(2) { animation-delay: .18s; }
.bbl-typing-dot:nth-child(3) { animation-delay: .36s; }
@keyframes bblTypeBounce {
  0%,60%,100% { transform: translateY(0); }
  30%          { transform: translateY(-5px); }
}

/* ─── End unified bubble system ─── */
