/* =====================================================================
   Rahbar kabineti — Telegram Mini App
   Ranglar Telegram mavzusidan olinadi (--tg-theme-*), Telegram'dan
   tashqarida ochilganda (lokal sinov) quyidagi zaxira qiymatlar ishlaydi.
   ===================================================================== */
:root {
    --bg: var(--tg-theme-secondary-bg-color, #f2f3f5);
    --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
    --text: var(--tg-theme-text-color, #15171a);
    --hint: var(--tg-theme-hint-color, #7d8590);
    --accent: var(--tg-theme-button-color, #2f7bf5);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --link: var(--tg-theme-link-color, var(--accent));
    --danger: var(--tg-theme-destructive-text-color, #e5484d);
    --separator: var(--tg-theme-section-separator-color, rgba(127, 127, 127, 0.18));
    --header: var(--tg-theme-section-header-text-color, var(--hint));

    --good: #1f9d55;
    --bad: #e5484d;
    --warn: #d98a00;
    --good-soft: rgba(31, 157, 85, 0.12);
    --bad-soft: rgba(229, 72, 77, 0.12);
    --warn-soft: rgba(217, 138, 0, 0.14);
    --neutral-soft: rgba(127, 127, 127, 0.14);

    --radius: 14px;
    --radius-sm: 10px;
    --gap: 12px;
    --pad: 16px;
    color-scheme: light;
}

:root.dark {
    --good: #3ccf7c;
    --bad: #ff6b6f;
    --warn: #f5b13d;
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not(.light) {
        --bg: var(--tg-theme-secondary-bg-color, #101214);
        --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1b1e22));
        --text: var(--tg-theme-text-color, #eceef0);
        --hint: var(--tg-theme-hint-color, #8b939d);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }

.app {
    max-width: 640px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ─── Sarlavha ───────────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: flex-start;
    gap: var(--gap);
    padding: 18px var(--pad) 8px;
}
.topbar-text { flex: 1; min-width: 0; }
.title { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.subtitle { margin-top: 4px; color: var(--hint); font-size: 14px; }
.topbar-actions { display: flex; gap: 4px; flex-shrink: 0; }

.content { padding: 0 var(--pad); display: flex; flex-direction: column; gap: var(--gap); }

/* ─── Ikonkalar ──────────────────────────────────────────────────── */
.icon { display: inline-flex; width: 22px; height: 22px; flex-shrink: 0; }
.icon svg { width: 100%; height: 100%; }
.icon.tiny { width: 14px; height: 14px; }
.icon.muted { color: var(--hint); width: 18px; height: 18px; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px;
    border: 0; border-radius: 50%;
    background: var(--surface); color: var(--accent);
}
.icon-btn:active { opacity: 0.7; }

/* ─── Kartalar va ro'yxatlar ─────────────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); }

.list { overflow: hidden; }
.list-item {
    display: flex; align-items: center; gap: 12px;
    width: 100%;
    padding: 11px 14px;
    border: 0; background: transparent; text-align: left;
    position: relative;
}
.list-item + .list-item::before {
    content: ""; position: absolute; top: 0; right: 0; left: 62px;
    border-top: 1px solid var(--separator);
}
.list-item.static + .list-item.static::before { left: 14px; }
button.list-item:active { background: var(--neutral-soft); }
.list-icon {
    display: flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 12px;
    background: var(--neutral-soft); color: var(--accent); flex-shrink: 0;
}
.list-body { flex: 1; min-width: 0; }
.list-title { font-weight: 600; overflow-wrap: anywhere; }
.list-sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.list-aside { font-size: 13px; flex-shrink: 0; }
.list-footer:not(:empty) { margin-top: var(--gap); }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }

.muted { color: var(--hint); }
.text-good { color: var(--good); }
.text-bad { color: var(--bad); }
.text-warn { color: var(--warn); }
.text-accent { color: var(--accent); }

.time { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; color: var(--text); }

/* ─── Avatar ─────────────────────────────────────────────────────── */
.avatar {
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; overflow: hidden;
    background: var(--neutral-soft); color: var(--hint);
    font-weight: 600; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 40px; height: 40px; font-size: 14px; }
.avatar-md { width: 52px; height: 52px; }
.avatar-lg { width: 112px; height: 112px; font-size: 34px; }

.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar-wrap::after {
    content: ""; position: absolute; right: 0; bottom: 0;
    width: 11px; height: 11px; border-radius: 50%;
    border: 2px solid var(--surface); background: var(--hint);
}
.dot-present::after { background: var(--good); }
.dot-late::after { background: var(--warn); }
.dot-absent::after { background: var(--bad); }
.dot-excused::after { background: var(--accent); }

/* ─── Badge / chip ───────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
    background: var(--neutral-soft); color: var(--text);
}
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 12px; border-radius: 999px;
    border: 0; background: var(--surface); color: var(--text);
    white-space: nowrap; font-size: 14px;
}
.chip.active { background: var(--accent); color: var(--accent-text); }
.chip-count { font-size: 12px; opacity: 0.75; font-variant-numeric: tabular-nums; }

/* ─── Sana paneli ────────────────────────────────────────────────── */
.datebar { display: flex; align-items: center; gap: 8px; }
.date-input { flex: 1; min-width: 0; text-align: center; }

/* ─── Statistika ─────────────────────────────────────────────────── */
.stats { display: flex; flex-direction: column; gap: 8px; }
.stats .state { padding: 20px 0; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stats-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.stats-row::-webkit-scrollbar { display: none; }
.stats-row .stat { min-width: 112px; flex: 1 0 auto; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stats-row .stat-value { font-size: 18px; }
.stat-total { font-size: 14px; font-weight: 500; color: var(--hint); }
.stat-label { color: var(--hint); font-size: 13px; margin-top: 2px; }
.stat-good .stat-value { color: var(--good); }
.stat-bad .stat-value { color: var(--bad); }
.stat-warn .stat-value { color: var(--warn); }
.inline-error { color: var(--bad); font-size: 14px; padding: 4px 2px; }

/* ─── Guruhlar ───────────────────────────────────────────────────── */
.people { display: flex; flex-direction: column; gap: var(--gap); }
.group { display: flex; flex-direction: column; gap: 6px; }
.group-title {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 4px 0;
    font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em;
    color: var(--header);
}
.group-count { font-variant-numeric: tabular-nums; opacity: 0.8; }
.group-absent .group-title { color: var(--bad); }
.group-late .group-title { color: var(--warn); }
.group-present .group-title { color: var(--good); }

/* ─── Profil ─────────────────────────────────────────────────────── */
.profile { display: flex; flex-direction: column; align-items: center; padding: 20px var(--pad); text-align: center; gap: 10px; }
.profile-name { font-size: 19px; font-weight: 700; overflow-wrap: anywhere; }
.facts { width: 100%; margin: 4px 0 0; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.fact { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.fact dt { color: var(--hint); flex-shrink: 0; }
.fact dd { margin: 0; text-align: right; overflow-wrap: anywhere; font-weight: 500; }
.photo-status { font-size: 13px; }

.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.action-tile {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 14px 8px; border: 0; border-radius: var(--radius);
    background: var(--surface); color: var(--accent);
    font-size: 13px; font-weight: 600; text-align: center;
}
.action-tile span:last-child { color: var(--text); }
.action-tile:active { opacity: 0.7; }

.notice { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.notice-title { font-size: 18px; font-weight: 700; }

.tab-hint { color: var(--hint); font-size: 13px; padding: 0 4px 6px; }
.tab-body { display: flex; flex-direction: column; gap: var(--gap); }
.date-cell { width: 52px; flex-shrink: 0; }
.date-day { font-weight: 700; font-variant-numeric: tabular-nums; }
.date-wd { color: var(--hint); font-size: 12px; }
.event-icon { display: flex; align-items: center; justify-content: center; width: 32px; flex-shrink: 0; }

/* ─── Segmented (til / tablar) ───────────────────────────────────── */
.segmented { display: flex; padding: 3px; border-radius: 12px; background: var(--surface); gap: 2px; }
.segment {
    flex: 1; padding: 8px 6px; border: 0; border-radius: 9px;
    background: transparent; color: var(--hint); font-size: 14px; font-weight: 600;
}
.segment.active { background: var(--accent); color: var(--accent-text); }
.section-label { color: var(--header); font-size: 13px; font-weight: 600; text-transform: uppercase; padding: 8px 4px 0; }
.center-block { display: flex; justify-content: center; }
.center-block .segmented { width: 100%; }

/* ─── Forma ──────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 10px; }
.card.form { padding: var(--pad); }
.label { font-size: 13px; color: var(--hint); font-weight: 600; margin-top: 2px; }
.input {
    width: 100%; padding: 12px 14px;
    border: 1px solid var(--separator); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text);
    outline: none; -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--accent); }
.input-code { font-size: 24px; letter-spacing: 0.4em; text-align: center; font-variant-numeric: tabular-nums; }
.input.search { background: var(--surface); }
.input-group { display: flex; align-items: stretch; }
.input-group .input { flex: 1; min-width: 0; }
.input-group .input:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-group .input:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-prefix, .input-addon {
    display: flex; align-items: center; padding: 0 12px;
    border: 1px solid var(--separator); background: var(--neutral-soft); color: var(--hint);
}
.input-prefix { border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); font-variant-numeric: tabular-nums; }
.input-addon { border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.hint { color: var(--hint); font-size: 13px; }
.form-error { color: var(--bad); font-size: 14px; min-height: 0; }
.form-error:empty { display: none; }

.password-display {
    padding: 16px; border-radius: var(--radius-sm);
    background: var(--neutral-soft);
    font: 700 26px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: 0.06em; text-align: center; user-select: all; overflow-wrap: anywhere;
}

.photo-preview:not(:empty) { display: flex; justify-content: center; }
.photo-preview img { max-width: 220px; max-height: 260px; border-radius: var(--radius); object-fit: cover; }

/* ─── Tugmalar ───────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 12px 16px; border: 0; border-radius: var(--radius-sm);
    font-weight: 600; font-size: 15px;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--neutral-soft); color: var(--accent); }
.btn-danger { background: var(--bad-soft); color: var(--danger); }
.btn-link { background: transparent; color: var(--link); padding: 8px; }
.btn:not(:disabled):active { opacity: 0.75; }
.spaced { margin-top: 8px; }

/* ─── Holatlar ───────────────────────────────────────────────────── */
.state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; padding: 40px 16px; text-align: center; color: var(--hint);
}
.state-fatal { min-height: 80vh; }
.state-text { max-width: 320px; }
.spinner {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid var(--neutral-soft); border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Bottom sheet ───────────────────────────────────────────────── */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 20;
    display: flex; align-items: flex-end; justify-content: center;
    background: rgba(0, 0, 0, 0); transition: background 0.2s;
}
.sheet-backdrop.open { background: rgba(0, 0, 0, 0.4); }
.sheet {
    width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto;
    padding: 8px var(--pad) calc(var(--pad) + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0; background: var(--surface);
    transform: translateY(100%); transition: transform 0.2s ease-out;
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--separator); margin: 0 auto 10px; }
.sheet-title { font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.sheet .input { background: var(--bg); }

/* ─── Toast ──────────────────────────────────────────────────────── */
.toasts {
    position: fixed; left: 0; right: 0; top: calc(10px + env(safe-area-inset-top)); z-index: 30;
    display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
    padding: 0 var(--pad);
}
.toast {
    max-width: 480px; padding: 10px 14px; border-radius: 12px;
    background: rgba(30, 32, 36, 0.94); color: #fff; font-size: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    transition: opacity 0.3s, transform 0.3s;
}
.toast-error { background: #c9363b; }
.toast-success { background: #1b8a4b; }
.toast.hide { opacity: 0; transform: translateY(-8px); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation-duration: 1.5s !important; }
}
