/* Telegram Mini App uslubi.
   Ranglar Telegram beradigan CSS o'zgaruvchilaridan olinadi, shuning uchun
   sahifa foydalanuvchining mavzusiga (yorug'/qorong'i) o'zi moslashadi. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #0f172a);
  --hint: var(--tg-theme-hint-color, #707b8a);
  --card: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --accent: var(--tg-theme-button-color, #38bdf8);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e5484d;
  --radius: 14px;
  --gap: 12px;
}

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

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* --- to'liq ekranli holatlar --- */

.screen {
  min-height: 85vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 20px;
  gap: 10px;
}

.screen h2 { margin: 4px 0; font-size: 20px; }
.big { font-size: 46px; line-height: 1; }
.hint { color: var(--hint); font-size: 14px; margin: 0; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--card);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- sarlavha --- */

header { padding: 16px 16px 8px; }

.title-row { display: flex; align-items: flex-start; gap: 8px; }

h1 {
  flex: 1;
  margin: 0;
  font-size: 21px;
  line-height: 1.25;
  word-break: break-word;
}

.stats { color: var(--hint); font-size: 13px; margin: 6px 0 0; }

/* --- ro'yxat --- */

#list { padding: 8px 16px 0; display: flex; flex-direction: column; gap: 10px; }

.item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.item.header-item {
  background: var(--fg);
  color: var(--bg);
  align-items: center;
}

.item-body { flex: 1; min-width: 0; }

.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .65;
  display: block;
  margin-bottom: 2px;
}

.item-title {
  font-weight: 600;
  word-break: break-word;
}

.item-sub {
  font-size: 13px;
  color: var(--hint);
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item.header-item .item-sub { color: var(--bg); opacity: .7; }

.thumb {
  width: 64px; height: 64px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg);
  flex: 0 0 auto;
}

.no-image {
  width: 64px; height: 64px;
  border-radius: 10px;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex: 0 0 auto;
}

.tools { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }

.tools button {
  width: 30px; height: 26px;
  border: 0; border-radius: 7px;
  background: transparent;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
  opacity: .75;
}
.tools button:active { opacity: 1; background: rgba(127,127,127,.22); }
.tools button:disabled { opacity: .22; }

.row2 { display: flex; gap: 4px; }

/* --- bo'sh holat --- */

.empty { padding: 28px 24px; text-align: center; }
.empty p { margin: 6px 0; }

.spacer { height: 96px; }

/* --- pastdagi panel --- */

.bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid rgba(127,127,127,.2);
}

.action {
  flex: 1;
  border: 0;
  border-radius: 11px;
  padding: 13px 8px;
  background: var(--card);
  color: var(--fg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.action:active { filter: brightness(.93); }
.action.small { flex: 0 0 52px; font-size: 20px; line-height: 1; }

button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  border-radius: 11px;
  padding: 13px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* --- matn oynasi --- */

.sheet {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end;
  z-index: 40;
}

.sheet-box {
  width: 100%;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}

.sheet-box h3 { margin: 0; font-size: 17px; }

textarea, input[type=text] {
  width: 100%;
  background: var(--card);
  color: var(--fg);
  border: 0;
  border-radius: 11px;
  padding: 12px;
  font: inherit;
  resize: vertical;
}

input[type=text] { max-width: 340px; }

.sheet-buttons { display: flex; gap: 8px; }
.sheet-buttons button { flex: 1; border: 0; border-radius: 11px; padding: 13px; font: inherit; font-weight: 600; background: var(--card); color: var(--fg); cursor: pointer; }
.sheet-buttons button.primary { background: var(--accent); color: var(--accent-fg); }

/* --- bildirishnoma --- */

.toast {
  position: fixed;
  left: 16px; right: 16px; bottom: 84px;
  background: var(--fg);
  color: var(--bg);
  padding: 12px 14px;
  border-radius: 11px;
  font-size: 14px;
  text-align: center;
  z-index: 50;
  animation: rise .18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* Tashxis matni (Telegram ichida ochilmaganda) */
.diag {
  margin: 14px 0 0;
  padding: 12px;
  background: var(--card);
  border-radius: 10px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--hint);
  text-align: left;
  white-space: pre-wrap;
  max-width: 320px;
}

/* Telegram MainButton ishlamaganda sahifaning o'z tugmasi */
.build-fallback {
  display: block;
  width: calc(100% - 32px);
  margin: 4px 16px 0;
}
