/* Ranglar Telegram mavzusidan (--tg-theme-*); brauzerda ochilganda zaxira qiymatlar */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111114);
  --hint: var(--tg-theme-hint-color, #8a8a93);
  --sub: var(--tg-theme-subtitle-text-color, #6d6d75);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --accent: var(--tg-theme-button-color, #2a7ae2);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d93a3a);
  --section-head: var(--tg-theme-section-header-text-color, #6d6d75);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --ok: #1f9d55;
  --warn: #c27a00;
  --radius: 14px;
  --tabbar-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #0f0f12; --card: #1c1c21; --text: #f2f2f5; --hint: #8d8d96; --sub: #a3a3ad;
    --link: #5aa1ff; --accent: #4c8dff; --section-head: #9a9aa4;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 12px; flex-wrap: wrap; }
h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--section-head); margin: 20px 4px 8px; }
.stack { display: grid; gap: 8px; }
.admin-link { font-size: 13px; text-decoration: none; vertical-align: middle; margin-left: 6px; font-weight: 600; }
.card { background: var(--card); border-radius: var(--radius); }

/* Segment */
.seg { display: inline-flex; background: var(--card); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; color: var(--sub); font-size: 14px; }
.seg button[aria-selected="true"] { background: var(--soft); color: var(--accent); font-weight: 600; }

/* Kun sarlavhasi va uchrashuv kartasi */
.day-head { font-size: 13px; font-weight: 600; color: var(--section-head); margin: 12px 4px 0; }
.day-head:first-child { margin-top: 0; }
.meet { display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: start; padding: 12px 14px;
  border: 0; width: 100%; text-align: left; background: var(--card); border-radius: var(--radius); }
.meet:active { opacity: 0.7; }
.meet .time { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; padding-top: 1px; }
.meet .name { font-weight: 600; }
.meet .loc { color: var(--sub); font-size: 14px; margin-top: 1px; overflow-wrap: anywhere; }
.meet.cancelled .time, .meet.cancelled .name { text-decoration: line-through; color: var(--hint); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--sub); white-space: nowrap; }
.chip.ok { color: var(--ok); }
.chip.bad { color: var(--danger); }
.chip.warn { color: var(--warn); }

.empty { text-align: center; color: var(--hint); padding: 40px 16px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* Kalendar */
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav span { min-width: 130px; text-align: center; font-weight: 600; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 10px; background: var(--card); font-size: 20px; line-height: 1; color: var(--accent); }
.cal { padding: 10px 8px; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.cal-week span { font-size: 12px; color: var(--hint); padding-bottom: 6px; }
.cal-grid button { border: 0; background: transparent; aspect-ratio: 1 / 1; max-height: 52px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-variant-numeric: tabular-nums; }
.cal-grid button.out { color: var(--hint); opacity: 0.45; }
.cal-grid button.today { color: var(--accent); font-weight: 700; }
.cal-grid button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }
.cal-grid .dots { display: flex; gap: 2px; height: 5px; }
.cal-grid .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-grid button[aria-selected="true"] .dots i { background: var(--accent-text); }

/* Forma */
.form { padding: 4px 14px; }
.field { padding: 10px 0; border-bottom: 1px solid var(--sep); }
.field:last-child { border-bottom: 0; }
.field label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.field select { width: 100%; border: 0; background: transparent; padding: 4px 0; font-size: 16px; outline: none; color: var(--text); }
.field input { width: 100%; border: 0; background: transparent; padding: 4px 0; font-size: 16px; outline: none; min-width: 0; }
.field input::placeholder { color: var(--hint); opacity: 0.7; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field.two .err { grid-column: 1 / -1; }
.phone { display: flex; align-items: center; gap: 6px; }
.phone span { color: var(--sub); font-size: 16px; }
.field .err { display: block; color: var(--danger); font-size: 13px; min-height: 0; }
.field .err:empty { display: none; }
.field.invalid label { color: var(--danger); }
.notice { padding: 12px 14px; margin-bottom: 10px; }
.notice label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; border: 1px solid var(--sep); border-radius: 10px; padding: 8px 10px; background: var(--bg); }

.add-tabs { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; margin-bottom: 12px; }
.add-tabs button { padding: 9px 4px; }
.wide-btn { width: 100%; }
.mic-card { padding: 28px 16px 22px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.mic { width: 104px; height: 104px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text);
  font-size: 42px; display: grid; place-items: center; box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 0.15s ease, background-color 0.15s ease; }
.mic:active { transform: scale(0.96); }
.mic:disabled { opacity: 0.5; }
.mic.recording { background: var(--danger); box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent);
  animation: pulse 1.4s ease-out infinite; }
@keyframes pulse { to { box-shadow: 0 0 0 22px transparent; } }
@media (prefers-reduced-motion: reduce) { .mic.recording { animation: none; } }
.mic-timer { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; min-height: 24px; color: var(--danger); }
.mic-timer:empty { min-height: 0; }
.mic-hint { margin: 0; color: var(--sub); font-size: 14px; max-width: 300px; }
.mic-hint b { color: var(--text); font-weight: 600; }
.text-card { padding: 12px 14px; display: grid; gap: 10px; }
.text-card textarea { width: 100%; border: 1px solid var(--sep); border-radius: 12px; padding: 10px 12px; background: var(--bg);
  color: var(--text); font: inherit; font-size: 16px; resize: vertical; min-height: 104px; outline: none; }
.text-card textarea:focus { border-color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.voice-status { margin: 0 4px 12px; }
.voice-status { font-size: 13px; color: var(--sub); }
.voice-status:empty { display: none; }
.voice-status i { color: var(--hint); }
.preview { padding: 14px; }
.preview .sms { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border-radius: 12px 12px 12px 4px; padding: 10px 12px; }
.preview .meta { color: var(--hint); font-size: 13px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.preview ul { margin: 8px 0 0; padding-left: 18px; }
.preview .warn li { color: var(--warn); }
.preview .miss { color: var(--sub); }

.btn { border: 0; background: var(--accent); color: var(--accent-text); border-radius: 12px; padding: 12px 16px; font-weight: 600; }
.btn.small { padding: 8px 14px; border-radius: 10px; }
.btn.wide { width: 100%; margin-top: 14px; }
.btn.ghost { background: var(--soft); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: default; }
.more-btn { width: 100%; padding: 10px 16px; font-size: 14px; }

/* SMS statistika */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 13px; color: var(--sub); }
.tile .value { font-size: 26px; font-weight: 700; line-height: 1.15; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .value small { font-size: 15px; font-weight: 500; color: var(--hint); }
.tile .meter { height: 4px; border-radius: 2px; background: var(--bg); margin-top: 8px; overflow: hidden; }
.tile .meter i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.chart-card { padding: 14px; margin-top: 8px; }
.chart-title { font-size: 14px; font-weight: 600; margin: 0 0 10px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--sep); stroke-width: 1; }
.chart .axis text { fill: var(--hint); font-size: 10px; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .bar.active { fill: color-mix(in srgb, var(--accent) 75%, var(--text)); }
.chart-tip { position: absolute; transform: translate(-50%, -100%); background: var(--text); color: var(--card);
  font-size: 12px; padding: 4px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap; }
.log { background: var(--card); border-radius: var(--radius); padding: 10px 14px; }
.log .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--sub); }
.log .who { font-weight: 600; color: var(--text); font-size: 15px; margin-top: 2px; }
.log .txt { font-size: 13px; color: var(--sub); margin-top: 4px; overflow-wrap: anywhere; }

/* Pastki menyu */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--sep); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabbar button { border: 0; background: transparent; height: var(--tabbar-h); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--hint); }
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: 0.7; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tabbar button[aria-current="page"] span { filter: none; opacity: 1; }

/* Pastdan chiquvchi oyna */
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow: auto; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto;
  animation: up 0.2s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet-body { animation: none; } }
.sheet h3 { margin: 0 0 4px; font-size: 20px; }
.sheet .when { color: var(--sub); margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin-bottom: 16px; }
.kv dt { color: var(--sub); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv a { color: var(--link); text-decoration: none; }
.actions { display: grid; gap: 8px; }
.heard { font-size: 13px; color: var(--hint); font-style: italic; margin-bottom: 14px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--card); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20;
  max-width: calc(100% - 32px); }
.fatal { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 24px; z-index: 30; gap: 8px; }
.fatal b { font-size: 18px; }
.fatal span { color: var(--sub); }
.skeleton { height: 72px; border-radius: var(--radius); background: var(--card); opacity: 0.6; }
