:root {
  color-scheme: dark;
  --bg: #05070c;
  --panel: rgba(17, 18, 24, 0.72);
  --panel-strong: rgba(26, 24, 20, 0.88);
  --text: #fff8e6;
  --muted: #b9b2a3;
  --line: rgba(255, 184, 31, 0.22);
  --primary: #f5aa16;
  --primary-strong: #ffd166;
  --accent: #28f0d3;
  --danger: #ff5c5c;
  --danger-bg: rgba(255, 92, 92, 0.14);
  --shadow: 0 22px 55px rgba(0, 0, 0, 0.42);
  --glow: 0 0 28px rgba(245, 170, 22, 0.22);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -12%, rgba(245, 170, 22, 0.34), transparent 34%),
    radial-gradient(circle at 4% 8%, rgba(40, 240, 211, 0.12), transparent 26%),
    linear-gradient(180deg, #07080d 0%, #0d0c09 44%, #040509 100%);
  color: var(--tg-theme-text-color, var(--text));
  font-family: Vazirmatn, Tahoma, Arial, sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: linear-gradient(180deg, black, transparent 78%);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.glass-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.025)),
    var(--panel);
  box-shadow: var(--shadow), var(--glow);
  backdrop-filter: blur(18px);
}

.topbar {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
}

.brand-logo {
  width: 72px;
  height: 72px;
  border: 1px solid rgba(255, 209, 102, 0.34);
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 28px rgba(245, 170, 22, 0.34);
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: #ffffff;
  font-size: 1.28rem;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.05rem;
}

.status-pill {
  min-width: 94px;
  max-width: 132px;
  padding: 8px 10px;
  border: 1px solid rgba(40, 240, 211, 0.28);
  border-radius: 8px;
  background: rgba(40, 240, 211, 0.08);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
}

.notice {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid rgba(255, 92, 92, 0.48);
  border-radius: 8px;
  background: var(--danger-bg);
  color: #ffd6d6;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
  padding: 5px;
  border: 1px solid rgba(255, 184, 31, 0.18);
  border-radius: 8px;
  background: rgba(5, 7, 12, 0.82);
  backdrop-filter: blur(14px);
}

.tab {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  background: linear-gradient(135deg, #ffb81f, #f59e0b);
  color: #090909;
  box-shadow: 0 0 24px rgba(245, 170, 22, 0.36);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 12px;
}

.profile-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border: 1px solid rgba(255, 209, 102, 0.52);
  border-radius: 50%;
  background: radial-gradient(circle, #ffd166 0%, #f59e0b 54%, #0b0b0c 56%);
  color: #05070c;
  font-weight: 900;
}

.profile-strip p,
.metric span,
.security-card p {
  color: var(--muted);
}

.profile-strip p {
  margin-bottom: 0;
  font-size: 0.86rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 92px;
  padding: 14px;
}

.metric strong {
  color: var(--primary-strong);
  font-size: 1.12rem;
}

.collapsible {
  padding: 0;
  overflow: clip;
}

summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: 0 14px;
  color: #ffffff;
  cursor: pointer;
  font-weight: 900;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 209, 102, 0.32);
  border-radius: 50%;
  color: var(--primary-strong);
  content: "+";
  display: grid;
  place-items: center;
}

details[open] > summary {
  border-bottom: 1px solid rgba(255, 184, 31, 0.14);
}

details[open] > summary::after {
  content: "-";
}

.info-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 4px 14px 12px;
}

.info-list div {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.info-list div:last-child {
  border-bottom: 0;
}

.info-list dt,
.info-list dd {
  margin: 0;
}

.info-list dt {
  color: var(--muted);
  font-weight: 800;
}

.info-list dd {
  overflow-wrap: anywhere;
}

.code-form,
.panel-form,
.security-card > p {
  display: grid;
  gap: 12px;
  padding: 14px;
}

label {
  color: #ffffff;
  font-weight: 800;
}

.field-hint {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.inline-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(255, 184, 31, 0.24);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.34);
  color: var(--text);
  padding: 12px;
  outline: none;
}

select option {
  background: #111111;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 128px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(245, 170, 22, 0.16), 0 0 26px rgba(245, 170, 22, 0.18);
}

.file-field {
  display: grid;
  gap: 6px;
}

.file-field span {
  color: var(--muted);
  font-size: 0.82rem;
}

.file-field.disabled {
  opacity: 0.58;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffba24, #f59e0b);
  color: #060708;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 0 22px rgba(245, 170, 22, 0.22);
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.secondary {
  border: 1px solid rgba(255, 184, 31, 0.25);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  box-shadow: none;
}

.danger {
  background: linear-gradient(135deg, #ff6565, #c92f2f);
  color: #ffffff;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.full-width {
  width: calc(100% - 28px);
  margin: 0 14px 14px;
}

.small {
  min-height: 34px;
  padding-inline: 10px;
  font-size: 0.82rem;
}

.neutral {
  border-color: rgba(245, 170, 22, 0.34);
  background: rgba(245, 170, 22, 0.12);
  color: var(--primary-strong);
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-title,
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-title span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  min-height: 38px;
  border: 1px solid rgba(255, 184, 31, 0.24);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 0 12px;
  font-size: 0.88rem;
  box-shadow: none;
}

.tag-chip.selected {
  border-color: var(--primary);
  background: linear-gradient(135deg, #ffd166, #f59e0b);
  color: #070707;
}

.check-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin-top: 3px;
  accent-color: var(--primary);
}

.result-box {
  margin: 0 14px 14px;
  padding: 14px;
  border: 1px solid rgba(40, 240, 211, 0.26);
  border-radius: 8px;
  background: rgba(40, 240, 211, 0.08);
  color: var(--accent);
}

.admin-panel,
.inbox-panel,
.admin-target-panel {
  display: grid;
  gap: 12px;
}

.admin-target-panel.nested {
  border: 1px solid rgba(40, 240, 211, 0.18);
  border-radius: 8px;
  background: rgba(40, 240, 211, 0.04);
}

.admin-target-panel.nested > *:not(summary) {
  margin-inline: 14px;
}

.admin-target-panel.nested > :last-child {
  margin-bottom: 14px;
}

.compact {
  box-shadow: none;
}

.message-list {
  display: grid;
  gap: 10px;
  padding: 14px 14px 0;
}

.message-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid rgba(255, 184, 31, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.message-item.clickable {
  cursor: pointer;
}

.message-item.clickable:hover {
  border-color: var(--primary);
}

.message-item div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.message-item p {
  margin-bottom: 0;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-item time,
.empty {
  color: var(--muted);
  font-size: 0.82rem;
}

.file-badge {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(40, 240, 211, 0.1);
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 14px;
}

.active-page {
  border-color: var(--primary);
  background: linear-gradient(135deg, #ffba24, #f59e0b);
  color: #060708;
}

.reply-dialog {
  width: min(92vw, 560px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.reply-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
}

.reply-box {
  display: grid;
  gap: 12px;
  padding: 16px;
  color: var(--text);
}

.close-btn {
  justify-self: start;
}

.selected-message {
  box-shadow: none;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  width: min(calc(100% - 32px), 688px);
  margin: 0 auto;
  padding: 12px 14px;
  border: 1px solid rgba(255, 184, 31, 0.3);
  border-radius: 8px;
  background: rgba(5, 7, 12, 0.92);
  color: var(--primary-strong);
  box-shadow: var(--shadow), var(--glow);
  text-align: center;
  backdrop-filter: blur(16px);
}

@media (max-width: 520px) {
  .topbar {
    grid-template-columns: 58px 1fr;
  }

  .brand-logo {
    width: 58px;
    height: 58px;
  }

  .status-pill {
    grid-column: 1 / -1;
    max-width: none;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 10px;
  }

  .tabs {
    gap: 4px;
  }

  .tab {
    min-height: 40px;
    font-size: 0.8rem;
  }

  .inline-field,
  .actions,
  .info-list div {
    grid-template-columns: 1fr;
  }

  summary {
    min-height: 50px;
  }
}
