/* ============================================================
 * Time Control — Telegram Mini App
 * File: webapp/styles.css  (v=6)
 * Единая тёмная палитра, карточки без рамок, кнопки 48px,
 * радиусы 12/16/20, bottom sheet с backdrop-blur,
 * toast / skeleton / empty.
 * ============================================================ */

:root {
    --bg: #0E1412;
    --surface: #161E1B;
    --surface-2: #1E2825;
    --border: rgba(255, 255, 255, .08);
    --accent: #4ADE80;
    --accent-ink: #052E16;
    --text: #E8EDEA;
    --muted: #8A9691;
    --danger: #F87171;
    --warn: #FBBF24;
    --r-lg: 20px;
    --r-md: 16px;
    --r-sm: 12px;
    --pad: 16px;
    --ease-out: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }

/* Атрибут hidden всегда сильнее любых display-правил автора */
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
    margin: 0;
    font-family: -apple-system, "SF Pro Text", Inter, system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-weight: 700; line-height: 1.25; margin: 0; }
h2 { font-size: 20px; margin: 6px 0 12px; }
h3 { font-size: 16px; }

#app {
    max-width: 640px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   ШАПКА: лого-марка + название фирмы + роль/дата
   ============================================================ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px var(--pad) 10px;
    background: var(--bg);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.logo-mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-titles { min-width: 0; }

.app-header__org {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}

.app-header__meta {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lang-select {
    background: var(--surface-2);
    color: var(--text);
    border: none;
    border-radius: var(--r-sm);
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
}

/* ============================================================
   КАРТОЧКИ (без рамок)
   ============================================================ */
.card {
    background: var(--surface);
    border-radius: var(--r-md);
    padding: var(--pad);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

.card--tap {
    cursor: pointer;
    transition: transform .15s var(--ease-out);
    -webkit-user-select: none;
    user-select: none;
}
.card--tap:active { transform: scale(.98); }

.card-title { font-weight: 600; margin-bottom: 4px; }
.card-sub {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    font-size: 13px;
    color: var(--muted);
}
.card-hours {
    margin-left: auto;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.card__enter { margin-top: 10px; }

/* ============================================================
   СТАТИСТИКА
   ============================================================ */
.stat-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}
.stat-row--2 { grid-template-columns: repeat(2, 1fr); }

.stat {
    background: var(--surface);
    border-radius: var(--r-md);
    padding: 14px 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat__value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat__label {
    font-size: 12px;
    color: var(--muted);
}

/* ============================================================
   БЕЙДЖИ СТАТУСОВ
   ============================================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: rgba(138, 150, 145, .16);
    color: var(--muted);
}

.badge--active {
    background: rgba(74, 222, 128, .14);
    color: var(--accent);
}

.badge--done {
    background: rgba(74, 222, 128, .22);
    color: var(--accent);
}

.badge--draft { background: rgba(138, 150, 145, .16); color: var(--muted); }
.badge--cancelled { background: rgba(248, 113, 113, .14); color: var(--danger); }
.badge--wait {
    background: rgba(251, 191, 36, .14);
    color: var(--warn);
}
.badge--reporter {
    background: rgba(96, 165, 250, .16);
    color: #60A5FA;
    text-transform: none;
    letter-spacing: 0;
}
.badge--warn {
    background: rgba(251, 191, 36, .14);
    color: var(--warn);
    text-transform: none;
    letter-spacing: 0;
}

/* ============================================================
   v4: сегодня / история / деньги / дашборд / матрица / карточка
   ============================================================ */
.dash-warn { color: var(--danger); }
.dash-warn-text {
    color: var(--danger);
    font-size: 13px;
    margin: 0 0 12px;
}
.dash-no-hours { color: var(--danger); }
.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.matrix {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.matrix th, .matrix td {
    border: 1px solid var(--border, rgba(255, 255, 255, .08));
    padding: 6px 8px;
    text-align: center;
    white-space: nowrap;
}
.matrix thead th { font-weight: 600; color: var(--muted); }
.matrix tbody th { font-weight: 500; text-align: left; }
.matrix-cell--empty { color: var(--muted); opacity: .5; }

/* ============================================================
   КНОПКИ (48px)
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    padding: 0 20px;
    border: none;
    border-radius: var(--r-sm);
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: transform .15s var(--ease-out), opacity .15s;
    -webkit-user-select: none;
    user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }

.btn--primary {
    background: var(--accent);
    color: var(--accent-ink);
}

.btn--ghost {
    background: var(--surface-2);
    color: var(--text);
}

.btn--danger {
    background: rgba(248, 113, 113, .14);
    color: var(--danger);
}

.btn--block { width: 100%; }

.btn-small {
    height: 36px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    border: none;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
}

.btn-back {
    background: transparent;
    color: var(--accent);
    height: auto;
    padding: 6px 0;
    justify-content: flex-start;
}

/* ============================================================
   СПИСКИ И СТРОКИ
   ============================================================ */
.list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.row-line {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 0;
    font-family: inherit;
    color: inherit;
    text-align: left;
}

.row-line--btn {
    background: var(--surface);
    border: none;
    border-radius: var(--r-md);
    padding: 12px var(--pad);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
    transition: transform .15s var(--ease-out);
}
.row-line--btn:active { transform: scale(.98); }

.row-line__name {
    font-size: 16px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-line__meta {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: #052E16;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.muted { color: var(--muted); }
.my-hours {
    font-size: 12px;
    text-align: center;
    margin: 16px 0 0;
}

/* ============================================================
   BOTTOM SHEET (backdrop-blur)
   ============================================================ */
.sheet__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 40;
    animation: fade-in .2s var(--ease-out);
}

.sheet {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--surface-2);
    border-radius: 24px 24px 0 0;
    padding: var(--pad);
    padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
    z-index: 41;
    animation: sheet-up .25s var(--ease-out);
}

.sheet__handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 0 auto 12px;
}

.sheet__title { font-size: 18px; margin-bottom: 6px; }
.sheet__h3 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); }

.sheet__totals {
    border-top: 1px solid var(--border);
    margin-top: 10px;
    padding-top: 6px;
}

.sheet__actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}

@keyframes sheet-up {
    from { transform: translate(-50%, 100%); }
    to   { transform: translate(-50%, 0); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ============================================================
   ПОЛЯ ФОРМЫ
   ============================================================ */
.form { display: flex; flex-direction: column; gap: 12px; }

.form-field { display: block; }

.form-label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}

.form input[type="text"],
.form input[type="date"],
.form input[type="number"],
.form input[type="tel"],
.form textarea,
.form select,
.form-field select {
    width: 100%;
    height: 48px;
    padding: 0 14px;
    background: var(--surface-2);
    border: 2px solid transparent;
    border-radius: var(--r-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    outline: none;
    transition: border-color .15s;
    -webkit-appearance: none;
    appearance: none;
}

.form textarea { height: auto; padding: 12px 14px; resize: vertical; }

.form input:focus,
.form select:focus,
.form textarea:focus { border-color: var(--accent); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.form-error {
    color: var(--danger);
    font-size: 14px;
    margin: 0;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 2px;
    font-size: 15px;
    cursor: pointer;
}
.check-item input[type="checkbox"],
.check-item input[type="radio"] {
    accent-color: var(--accent);
    width: 18px;
    height: 18px;
}

/* ============================================================
   ЧИПЫ (выбор сотрудника / локации / быстрые часы)
   ============================================================ */
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border-radius: 999px;
    background: var(--surface-2);
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, color .15s, transform .15s var(--ease-out);
    -webkit-user-select: none;
    user-select: none;
}
.chip:active { transform: scale(.97); }

.chip--on {
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}

/* ============================================================
   СЕГМЕНТЫ (вкладки отчётов) — pill 44px
   ============================================================ */
.segment {
    display: flex;
    gap: 6px;
    background: var(--surface);
    border-radius: 999px;
    padding: 4px;
    margin-bottom: 12px;
}

.segment__btn {
    flex: 1;
    height: 44px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.segment__btn.is-active {
    background: var(--accent);
    color: var(--accent-ink);
}

/* ============================================================
   СЕТКА 2x2 НА ГЛАВНОЙ
   ============================================================ */
.grid2x2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
}

.grid2x2__wide { grid-column: 1 / -1; height: 52px; }
.grid2x2__cell { height: 52px; }

/* ============================================================
   ЭКРАН ВВОДА ЧАСОВ
   ============================================================ */
.he-date {
    width: 100%;
    height: 56px;
    border: none;
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 18px;
    font-weight: 600;
    text-align: left;
    padding: 0 var(--pad);
    cursor: pointer;
}

.he-same {
    background: var(--surface);
    border-radius: var(--r-md);
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
}

.he-quick {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.he-row { padding: 10px 0; }

.he-input-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.he-input {
    width: 96px;
    height: 52px;
    text-align: center;
    font-size: 28px;
    font-weight: 600;
    font-family: inherit;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: var(--r-sm);
    color: var(--text);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.he-input:focus { border-color: var(--accent); }

.he-unit {
    font-size: 12px;
    color: var(--muted);
    align-self: flex-end;
    padding-bottom: 8px;
}

.he-val {
    font-size: 28px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 96px;
    text-align: center;
}
.he-val--grey { color: var(--muted); }

.he-sticky {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
    margin-top: 12px;
}

.he-save { height: 56px; font-size: 17px; }

/* ============================================================
   НИЖНЯЯ НАВИГАЦИЯ
   ============================================================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 640px;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 10;
}

.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 2px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-family: inherit;
    font-size: 10px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.bottom-nav__icon {
    width: 24px;
    height: 24px;
}

.bottom-nav__item.is-active { color: var(--accent); }

/* ============================================================
   ПУСТОЕ СОСТОЯНИЕ
   ============================================================ */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 48px 16px;
    text-align: center;
    color: var(--muted);
}

.empty__text { font-size: 14px; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    background: var(--surface-2);
    color: var(--text);
    border-radius: var(--r-sm);
    padding: 12px 18px;
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
    z-index: 50;
    animation: toast-in .25s var(--ease-out);
}

.toast--error { color: var(--danger); }
.toast--success { color: var(--accent); }

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, -12px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================================
   SKELETON (shimmer)
   ============================================================ */
.skeleton {
    background: linear-gradient(
        100deg,
        var(--surface) 40%,
        var(--surface-2) 50%,
        var(--surface) 60%
    );
    background-size: 200% 100%;
    border-radius: var(--r-sm);
    animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
    from { background-position: 120% 0; }
    to   { background-position: -80% 0; }
}

.skeleton--card { height: 76px; border-radius: var(--r-md); }

/* ============================================================
   КОНТЕНТ / ЭКРАНЫ
   ============================================================ */
.app-content {
    flex: 1;
    padding: var(--pad);
    padding-bottom: calc(90px + env(safe-area-inset-bottom));
}

.screen[hidden] { display: none; }

.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.screen-header h2 { margin: 6px 0; }

.screen-message {
    text-align: center;
    color: var(--muted);
    padding: 12px 8px;
}

.loader {
    width: 32px;
    height: 32px;
    margin: 48px auto 12px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   АДАПТИВ
   ============================================================ */
@media (max-width: 380px) {
    .stat-row,
    .stat-row--2 { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
    .card-sub { gap: 6px; }
}
