:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --sub: #6b6b6f;
  --line: rgba(0,0,0,0.08);
  --blue: #007aff;
  --red: #ff3b30;
  --green: #34c759;
  --orange: #ff9500;
  --shadow: 0 8px 26px rgba(0,0,0,0.12);
  --shadowSoft: 0 10px 30px rgba(0,0,0,0.10);
  --radius: 16px;

  /* iOS safe areas */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);

  /* 📌 ВЫСОТА ТАББАРА СНИЗУ */
  --tabbar-h: 48px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  height: 100dvh;
  height: 100svh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

/* AUTH */
.auth {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.authCard {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadowSoft);
  padding: 18px;
}
.authTitle {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.authSub {
  margin-top: 4px;
  color: var(--sub);
}

.seg {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background: rgba(0,0,0,0.05);
  border-radius: 12px;
}
.segBtn {
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
}
.segBtn.on {
  background: var(--card);
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}

.field { margin-top: 14px; }
.field label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 12px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  font-size: 16px;
  background: #fbfbfd;
}
.field input:focus {
  border-color: rgba(0,122,255,0.45);
  box-shadow: 0 0 0 4px rgba(0,122,255,0.12);
}
.hint { margin-top: 6px; font-size: 12px; color: var(--sub); }

button, input, textarea { font-family: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
input, textarea { -webkit-appearance: none; appearance: none; }

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(0,122,255,0.14);
}

.hidden { display: none !important; }

.primary {
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--blue);
  color: white;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 6px 16px rgba(0,122,255,0.20);
}
.primary:active { transform: translateY(1px); }
.authCard .primary { margin-top: 16px; }

.secondary {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.9);
  color: var(--text);
  font-weight: 800;
  font-size: 16px;
}
.secondary:active { transform: translateY(1px); }

.msg { margin-top: 10px; font-size: 13px; color: var(--sub); min-height: 18px; }

/* SHELL LAYOUT */
.shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top bar - теперь сверху */
.topbar {
  padding: calc(10px + var(--safe-top)) 16px 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.topTitle {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.topRight {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
  font-size: 16px;
}
.topRight:active { transform: translateY(1px); }

/* 📌 КОНТЕНТ - занимает все свободное место */
.content {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 8px 12px 8px;
}

/* 📌 ТАББАР СНИЗУ - фиксированный */
.tabbar {
  flex-shrink: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 2px 2px calc(2px + var(--safe-bottom)) 2px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 1000;
}

.tab {
  border: 0;
  background: transparent;
  padding: 2px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--sub);
}
.tab .ico { 
  font-size: 18px;
  line-height: 1;
}
.tab .lbl { 
  font-size: 8px;
  font-weight: 500;
  margin-top: -1px;
  color: currentColor;
}
.tab.on { 
  color: var(--blue); 
}
.tab:active { 
  opacity: 0.7;
  transform: none;
}

/* CARDS */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}
.card + .card { margin-top: 10px; }

.cardTitle {
  padding: 12px 14px 8px 14px;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--sub);
  font-weight: 800;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, rgba(0,0,0,0.02), transparent);
}

.empty {
  padding: 14px 14px;
  color: var(--sub);
  font-size: 14px;
}

.list { padding: 0; }

.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  align-items: center;
  min-width: 0;
}
.row:last-child { border-bottom: 0; }
.rowMain { min-width: 0; }
.rowTitle { font-weight: 700; font-size: 15px; }
.rowTitle, .rowSub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rowSub { font-size: 12px; color: var(--sub); margin-top: 2px; }

.rowRight {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: rgba(0,0,0,0.06);
  border: 1px solid var(--line);
  background-size: cover;
  background-position: center;
  flex: 0 0 auto;
}
.avatar.big {
  width: 48px;
  height: 48px;
  border-radius: 16px;
}

.btnMini {
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.03);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
}
.btnMini:active { transform: translateY(1px); }

.callBtn {
  width: 36px;
  height: 32px;
  border-radius: 10px;
  border: 0;
  background: rgba(0,122,255,0.12);
  color: var(--blue);
  font-size: 15px;
  font-weight: 900;
}
.callBtn:active { transform: translateY(1px); }

.search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.02);
}
.search input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfbfd;
  outline: none;
  font-size: 15px;
}
.search input:focus {
  border-color: rgba(0,122,255,0.45);
  box-shadow: 0 0 0 4px rgba(0,122,255,0.12);
}

.btn {
  border: 0;
  background: rgba(0,122,255,0.12);
  color: var(--blue);
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 13px;
}
.btnRed { background: rgba(255,59,48,0.12); color: var(--red); }
.btnGreen { background: rgba(52,199,89,0.14); color: var(--green); }

.badge {
  display: inline-block;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(0,0,0,0.06);
  color: var(--sub);
  font-size: 11px;
}

/* INPUTS */
.inputRow {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}
.inputRow input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  font-size: 15px;
  background: #fbfbfd;
}

.keyInput {
  width: calc(100% - 24px);
  margin: 10px 12px 0 12px;
  padding: 12px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  font-size: 15px;
  background: #fbfbfd;
}
.keyInput:focus {
  border-color: rgba(0,122,255,0.45);
  box-shadow: 0 0 0 4px rgba(0,122,255,0.12);
}

.keyActions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px 12px 12px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(10px);
  display: grid;
  align-items: end;
  z-index: 80;
}
.sheet {
  background: rgba(255,255,255,0.92);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 12px;
  box-shadow: 0 -18px 40px rgba(0,0,0,0.25);
  border-top: 1px solid rgba(255,255,255,0.35);
}
.sheetHead {
  display: grid;
  justify-items: center;
  padding: 6px 0 10px 0;
}
.sheetTitle { font-weight: 900; font-size: 17px; letter-spacing: -0.01em; }
.sheetSub { margin-top: 4px; color: rgba(0,0,0,0.55); font-size: 12px; text-align: center; }
.sheetActions {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

/* Toast */
.toast {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
  z-index: 90;
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 10px 12px;
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.24);
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
}

.danger {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--red);
  color: white;
  font-weight: 900;
  font-size: 15px;
}
.danger:active { transform: translateY(1px); }

.kpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.kbtn {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 0;
  font-size: 20px;
  font-weight: 800;
}
.kcall {
  margin-top: 10px;
  width: 100%;
  border: 0;
  background: var(--green);
  color: white;
  font-weight: 900;
  border-radius: 14px;
  padding: 12px 0;
  font-size: 16px;
}

/* CALL */
.call {
  position: fixed;
  inset: 0;
  background: #000;
  color: white;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  z-index: 50;
}
.callHeader {
  padding-top: calc(16px + var(--safe-top));
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 8px;
}
.callPeer { font-size: 26px; font-weight: 900; letter-spacing: -0.03em; }
.callState { margin-top: 4px; color: rgba(255,255,255,0.7); font-size: 14px; }

.callBody { position: relative; overflow: hidden; }
.remoteVideo { width: 100%; height: 100%; object-fit: cover; }
.localPreview {
  position: absolute;
  right: 12px;
  top: calc(12px + var(--safe-top));
  width: 30vw;
  max-width: 160px;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: #111;
}

.callControls {
  display: grid;
  grid-template-columns: repeat(5, 1fr) 1.2fr;
  gap: 8px;
  padding: 10px 10px calc(16px + var(--safe-bottom)) 10px;
  background: rgba(0,0,0,0.35);
  border-top: 1px solid rgba(255,255,255,0.12);
}
.round {
  border: 0;
  border-radius: 14px;
  background: rgba(255,255,255,0.14);
  color: white;
  padding: 12px 0;
  font-size: 16px;
  font-weight: 900;
}
.hang {
  border: 0;
  border-radius: 14px;
  background: var(--red);
  color: white;
  padding: 12px 0;
  font-size: 16px;
  font-weight: 900;
}

.fileBtn { display: grid; place-items: center; position: relative; }
.fileBtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.sharedArea, .canvasArea {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(10px + 140px + var(--safe-bottom));
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  padding: 10px;
  backdrop-filter: blur(14px);
}
.sharedHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.sharedTitle { font-weight: 900; font-size: 14px; }
.chip {
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.12);
  color: white;
  padding: 6px 8px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
}
.sharedInfo { font-size: 12px; color: rgba(255,255,255,0.75); margin-bottom: 6px; }
.sharedMedia { width: 100%; }

.canvasArea textarea {
  width: 100%;
  height: 160px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(0,0,0,0.3);
  color: white;
  padding: 8px;
  font-size: 13px;
  outline: none;
  resize: none;
}

/* Presence dot */
.avatarWrap {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
}
.avatarWrap .avatar { width: 44px; height: 44px; }
.statusDot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 2px solid rgba(0,0,0,0.9);
  background: #ff3b30;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.statusDot.stOnline { background: #34c759; }
.statusDot.stBusy { background: #ffcc00; }
.statusDot.stOffline { background: #ff3b30; }

/* Session gate */
#sessionOverlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index: 9999;
  padding: 16px;
}
#sessionOverlay .sessionBox{
  width: min(480px, 100%);
  background: rgba(30,30,32,.96);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
#sessionOverlay .sessionTitle{
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}
#sessionOverlay .sessionText{
  color: rgba(255,255,255,.78);
  font-size: 13px;
  margin-bottom: 12px;
  line-height: 1.35;
}

/* Desktop frame */
@media (min-width: 920px) {
  .shell {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

/* Small phones */
@media (max-width: 420px) {
  .callPeer { font-size: 22px; }
  .callControls { grid-template-columns: repeat(3, 1fr); }
  .hang { grid-column: 1 / -1; }
  .localPreview { max-width: 120px; width: 34vw; }
  
  .tabbar {
    --tabbar-h: 44px;
  }
  
  .tab .ico { 
    font-size: 16px; 
  }
  .tab .lbl { 
    font-size: 7px; 
  }
}

@media (max-width: 360px) {
  .topTitle { font-size: 20px; }
  .rowRight { gap: 4px; }
  .btnMini { padding: 6px 8px; font-size: 12px; }
  
  .tab .ico { 
    font-size: 15px; 
  }
  .tab .lbl { 
    font-size: 6px; 
  }
}
