/* Kurucu Inbox — premium dark glass */
:root {
  --bg: #070b12;
  --bg-elev: #0c121c;
  --panel: rgba(18, 26, 40, 0.82);
  --panel-solid: #101826;
  --glass: rgba(255, 255, 255, 0.045);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text: #f3f6fb;
  --text-soft: #c5d0e0;
  --hint: #7d8da3;
  --accent: #6b8cff;
  --accent-2: #8b5cf6;
  --accent-grad: linear-gradient(135deg, #6b8cff 0%, #8b5cf6 100%);
  --accent-text: #ffffff;
  --mine: linear-gradient(145deg, #2a4a8c 0%, #3d5fad 55%, #4a6bc4 100%);
  --theirs: rgba(255, 255, 255, 0.06);
  --ok: #34d399;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --blur: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --header-h: 56px;
  --composer-pad: 0px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Telegram theme bridge when available */
body.tg-theme {
  --bg: var(--tg-theme-bg-color, #070b12);
  --panel-solid: var(--tg-theme-secondary-bg-color, #101826);
  --text: var(--tg-theme-text-color, #f3f6fb);
  --hint: var(--tg-theme-hint-color, #7d8da3);
  --accent: var(--tg-theme-button-color, #6b8cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 480px at 12% -10%, rgba(107, 140, 255, 0.18), transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(139, 92, 246, 0.12), transparent 50%),
    radial-gradient(600px 360px at 50% 110%, rgba(52, 211, 153, 0.06), transparent 55%);
  z-index: 0;
}

.hidden {
  display: none !important;
}

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

/* ─── Top bar ─── */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--header-h);
  padding: calc(8px + var(--safe-t)) 14px 10px;
  background: color-mix(in srgb, var(--panel-solid) 88%, transparent);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.top h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.03em;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top .subline {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--hint);
  letter-spacing: 0;
  margin-top: 1px;
}

.badge-role {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: rgba(107, 140, 255, 0.16);
  color: #a8c0ff;
  flex-shrink: 0;
}

.badge-role.girl {
  background: rgba(244, 114, 182, 0.14);
  color: #f9a8d4;
}

.badge-role.owner {
  background: rgba(251, 191, 36, 0.14);
  color: #fcd34d;
}

.icon-btn {
  border: 0;
  background: var(--glass);
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  border: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.icon-btn:active {
  opacity: 0.75;
}

/* ─── Search ─── */
.search-wrap {
  padding: 8px 12px 0;
  flex-shrink: 0;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  padding: 10px 14px;
}

.search svg {
  width: 16px;
  height: 16px;
  opacity: 0.45;
  flex-shrink: 0;
}

.search input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  outline: none;
  min-width: 0;
}

.search input::placeholder {
  color: var(--hint);
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px 6px;
  flex-shrink: 0;
}

.tab {
  flex: 1;
  border: 0;
  border-radius: var(--radius-pill);
  padding: 10px 6px;
  font-size: 12px;
  font-weight: 650;
  background: transparent;
  color: var(--hint);
  cursor: pointer;
  position: relative;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}

.tab.on {
  background: var(--accent-grad);
  color: var(--accent-text);
  box-shadow: 0 4px 16px rgba(107, 140, 255, 0.28);
}

.tab .tb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 800;
  background: rgba(0, 0, 0, 0.25);
}

.tab.on .tb {
  background: rgba(255, 255, 255, 0.22);
}

/* ─── Stats ─── */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px 0;
  flex-shrink: 0;
}

.stat {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat span {
  color: var(--hint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.stat b {
  display: block;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.03em;
  margin-top: 4px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ─── List ─── */
#list-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 12px calc(16px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 12px;
  margin-bottom: 8px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  cursor: pointer;
  transition: transform 0.15s var(--ease), opacity 0.15s, border-color 0.15s;
  animation: rowIn 0.28s var(--ease) both;
}

.row:active {
  transform: scale(0.985);
  opacity: 0.9;
}

@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(145deg, #3d5a9f, #1a2a4a);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 750;
  font-size: 15px;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(107, 140, 255, 0.15), 0 4px 12px rgba(0, 0, 0, 0.25);
  letter-spacing: -0.02em;
}

.avatar.girl {
  background: linear-gradient(145deg, #c0266e, #5b21b6);
}

.avatar.block {
  background: linear-gradient(145deg, #7f1d1d, #450a0a);
  font-size: 18px;
}

.avatar.has-photo {
  color: transparent;
  box-shadow: 0 0 0 2px rgba(107, 140, 255, 0.25), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.owner-hint {
  margin: 8px 12px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(107, 140, 255, 0.08);
  border: 1px solid rgba(107, 140, 255, 0.18);
  color: var(--text-soft);
  font-size: 12.5px;
  line-height: 1.45;
  flex-shrink: 0;
}

.owner-hint b {
  color: var(--text);
  font-weight: 700;
}

.sheet-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.sheet-status-txt {
  font-size: 13px;
  color: var(--hint);
  line-height: 1.4;
}

.sheet-note {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--hint);
  line-height: 1.45;
  text-align: center;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0 12px;
  text-align: left;
}

.detail-grid .d {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 12px 12px 10px;
}

.detail-grid .d span {
  display: block;
  font-size: 10px;
  font-weight: 650;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-grid .d b {
  display: block;
  margin-top: 6px;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: -0.02em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.chip-ok {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.15);
  color: #6ee7b7;
}

.chip-warn {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.15);
  color: #fcd34d;
}

/* Owner FAB + form */
.fab {
  position: fixed;
  right: calc(16px + var(--safe-r));
  bottom: calc(20px + var(--safe-b));
  z-index: 40;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
  box-shadow: 0 8px 28px rgba(107, 140, 255, 0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab:active {
  transform: scale(0.96);
}

.field {
  text-align: left;
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}

.field input:focus {
  border-color: rgba(107, 140, 255, 0.5);
}

.field .hint {
  margin-top: 5px;
  font-size: 11px;
  color: var(--hint);
  line-height: 1.35;
}

.action-row {
  display: flex;
  gap: 8px;
  margin: 10px 0 4px;
}

.action-row .sheet-btn {
  flex: 1;
  padding: 12px 8px;
  font-size: 13px;
}

.manage-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.pos-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--hint);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.profile-card {
  text-align: center;
  padding: 4px 0 8px;
}

.profile-card-av {
  width: 72px !important;
  height: 72px !important;
  margin: 0 auto 12px;
  font-size: 22px !important;
}

.profile-card-name {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.profile-card-sub {
  font-size: 12px;
  color: var(--hint);
  margin-bottom: 10px;
}

.profile-card-id {
  margin: 0 auto 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  display: inline-block;
  max-width: 100%;
  word-break: break-all;
}

.profile-card-id code {
  font-size: 13px;
  color: var(--text-soft);
}

.meta {
  flex: 1;
  min-width: 0;
}

.meta .name {
  font-weight: 650;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: -0.02em;
}

.meta .sub {
  color: var(--hint);
  font-size: 13px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta .time {
  color: var(--hint);
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
  margin-left: auto;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill {
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  padding: 0 7px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(107, 140, 255, 0.4);
  flex-shrink: 0;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.55);
  flex-shrink: 0;
}

.dot.off {
  background: var(--hint);
  box-shadow: none;
  opacity: 0.45;
}

/* ─── Empty / error / auth ─── */
.empty,
.err,
.auth-gate {
  text-align: center;
  padding: 48px 24px;
  color: var(--hint);
  font-size: 14px;
  line-height: 1.55;
}

.empty .ico,
.auth-gate .ico {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.9;
  filter: grayscale(0.2);
}

.empty b,
.auth-gate b {
  display: block;
  color: var(--text-soft);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.err {
  color: #fca5a5;
}

/* ─── Skeleton ─── */
.skel {
  height: 72px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 25%,
    rgba(255, 255, 255, 0.07) 37%,
    rgba(255, 255, 255, 0.03) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.2s ease infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

/* ─── Chat ─── */
#screen-chat,
#screen-list {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

#chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

#msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.day {
  align-self: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
  background: rgba(0, 0, 0, 0.28);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  margin: 8px 0 6px;
  letter-spacing: 0.02em;
}

.bubble {
  max-width: 78%;
  padding: 10px 13px 6px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
  animation: bubIn 0.2s var(--ease) both;
}

@keyframes bubIn {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.bubble.mine {
  align-self: flex-end;
  background: var(--mine);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(42, 74, 140, 0.35);
}

.bubble.theirs {
  align-self: flex-start;
  background: var(--theirs);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 5px;
}

.bubble .media-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 650;
  opacity: 0.9;
  padding: 4px 0 2px;
}

.bubble .time {
  display: block;
  text-align: right;
  font-size: 10px;
  opacity: 0.7;
  margin-top: 3px;
  font-weight: 500;
}

.bubble.mine .time {
  color: rgba(255, 255, 255, 0.75);
}

.bubble.theirs .time {
  color: var(--hint);
}

.composer {
  display: flex;
  gap: 8px;
  padding: 8px 10px calc(10px + var(--safe-b) + var(--composer-pad));
  background: color-mix(in srgb, var(--panel-solid) 90%, transparent);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-top: 1px solid var(--glass-border);
  align-items: flex-end;
  flex-shrink: 0;
  transition: padding-bottom 0.12s linear;
}

.composer input {
  flex: 1;
  border: 0;
  border-radius: 22px;
  padding: 12px 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-size: 15px;
  outline: none;
  min-width: 0;
}

.composer input:disabled {
  opacity: 0.55;
}

.composer button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-grad);
  color: var(--accent-text);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(107, 140, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.15s;
}

.composer button:disabled {
  opacity: 0.4;
  transform: scale(0.96);
  cursor: default;
}

.composer button.busy {
  opacity: 0.7;
}

.chat-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-danger,
.btn-link {
  border: 0;
  font-size: 12px;
  font-weight: 650;
  padding: 7px 11px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-danger {
  background: var(--danger-bg);
  color: #fca5a5;
}

.btn-link {
  background: rgba(107, 140, 255, 0.14);
  color: #a8c0ff;
}

.blocked-banner {
  background: var(--danger-bg);
  color: #fca5a5;
  text-align: center;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 550;
  border-bottom: 1px solid rgba(248, 113, 113, 0.15);
  flex-shrink: 0;
}

/* ─── Toast ─── */
#toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: min(360px, calc(100% - 32px));
}

.toast {
  background: rgba(15, 22, 35, 0.94);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 550;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  animation: toastIn 0.25s var(--ease);
  text-align: center;
}

.toast.err {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.toast.ok {
  border-color: rgba(52, 211, 153, 0.3);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ─── Bottom sheet ─── */
#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s var(--ease);
}

#sheet-backdrop.on {
  opacity: 1;
  pointer-events: auto;
}

#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  max-width: 520px;
  margin: 0 auto;
  background: var(--panel-solid);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--glass-border);
  border-bottom: 0;
  padding: 12px 16px calc(20px + var(--safe-b));
  transform: translateY(110%);
  transition: transform 0.28s var(--ease);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
}

#sheet.on {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  margin: 0 auto 14px;
}

.sheet-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  text-align: center;
}

.sheet-body {
  color: var(--hint);
  font-size: 13px;
  text-align: center;
  line-height: 1.45;
  margin-bottom: 16px;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-btn {
  border: 0;
  border-radius: 14px;
  padding: 14px;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}

.sheet-btn.primary {
  background: var(--accent-grad);
  color: #fff;
}

.sheet-btn.danger {
  background: var(--danger-bg);
  color: #fca5a5;
}

.sheet-btn.ghost {
  background: var(--glass);
  color: var(--text-soft);
  border: 1px solid var(--glass-border);
}

/* ─── Screen transitions ─── */
#screen-list.hidden,
#screen-chat.hidden {
  display: none !important;
}
