/* =============================================
   TECH APP - shell: tokens, top bar, timer bar, bottom tabs, buttons,
   fields, toasts, login. One hand on a phone: big targets, high contrast,
   safe areas respected.
   ============================================= */

:root {
    --app-bg: #f4f6f9;
    --app-surface: #fff;
    --app-surface-2: #f8f9fb;
    --app-line: #e8edf3;
    --app-text: #0f1a2b;
    --app-text-2: #4a5870;
    --app-text-3: #7b879a;
    --app-ink: #0f1a2b;
    --app-accent: #0052cc;
    --app-accent-soft: #e8f0fc;
    --app-red: #dc2626;
    --app-warn: #a15c00;
    --app-warn-soft: #fff4e0;
    --app-ok: #15803d;
    --app-ok-soft: #eaf7ef;
    --app-radius: 14px;
    --app-shadow: 0 1px 2px rgba(15, 26, 43, 0.05), 0 2px 10px rgba(15, 26, 43, 0.05);
    --app-top: env(safe-area-inset-top, 0px);
    --app-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.app {
    margin: 0;
    min-height: 100vh;
    background: var(--app-bg);
    color: var(--app-text);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}
a { color: var(--app-accent); }
button { font: inherit; }
.app-icon { display: inline-flex; flex: none; }
.app-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.app-muted { color: var(--app-text-3); }
.app-small { font-size: 0.82rem; }
:focus-visible { outline: 3px solid rgba(0, 82, 204, 0.35); outline-offset: 2px; }

/* ── Top bar ── */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-height: calc(54px + var(--app-top));
    padding: var(--app-top) 0.5rem 0;
    background: var(--app-ink);
    color: #fff;
}
.app-bar__title { flex: 1; min-width: 0; margin: 0 0.4rem; overflow: hidden; font-size: 1.05rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.app-bar__back, .app-bar__btn {
    display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
    border: 0; border-radius: 12px; background: none; color: #fff; cursor: pointer; list-style: none;
}
.app-bar__btn::-webkit-details-marker { display: none; }
.app-bar__back[hidden] { display: none; }
.app-bar__back:active, .app-bar__btn:active { background: rgba(255, 255, 255, 0.12); }
.app-bar__sync {
    padding: 0.2rem 0.6rem; border-radius: 999px; background: rgba(255, 255, 255, 0.14);
    font-size: 0.75rem; font-weight: 600; cursor: pointer;
}
.app-bar__sync.is-error { background: var(--app-red); }
.app-menu { position: relative; }
.app-menu__panel {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; padding: 0.4rem;
    border-radius: 12px; background: var(--app-surface); color: var(--app-text); box-shadow: 0 10px 30px rgba(15, 26, 43, 0.2);
}
.app-menu__who { display: block; padding: 0.5rem 0.75rem; color: var(--app-text-3); font-size: 0.85rem; }
.app-menu__item {
    display: block; width: 100%; padding: 0.75rem; border: 0; border-radius: 8px; background: none;
    color: var(--app-text); text-align: left; text-decoration: none; cursor: pointer;
}
.app-menu__item:active { background: var(--app-bg); }
.app-menu__item--danger { color: var(--app-red); }

/* ── Timer bar ── */
.app-timer {
    position: sticky;
    top: calc(54px + var(--app-top));
    z-index: 19;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem 0.55rem 1rem;
    background: var(--app-red);
    color: #fff;
}
.app-timer[hidden] { display: none; }
.app-timer__dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: app-pulse 1.6s ease-in-out infinite; }
.app-timer__what { display: flex; flex: 1; flex-direction: column; min-width: 0; line-height: 1.2; }
.app-timer__clock { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.app-timer__what small { overflow: hidden; opacity: 0.9; text-overflow: ellipsis; white-space: nowrap; }
@keyframes app-pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .app-timer__dot { animation: none; } }

/* ── Content ── */
.app-main { max-width: 640px; margin: 0 auto; padding: 1rem 1rem calc(88px + var(--app-bottom)); outline: none; }

/* ── Bottom tabs ── */
.app-tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    padding: 0.35rem 0.5rem calc(0.35rem + var(--app-bottom));
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -1px 0 var(--app-line), 0 -6px 20px rgba(15, 26, 43, 0.06);
    backdrop-filter: blur(10px);
}
.app-tabs__tab {
    display: flex; flex-direction: column; align-items: center; gap: 0.1rem; padding: 0.35rem 0;
    color: var(--app-text-3); font-size: 0.72rem; font-weight: 600; text-decoration: none;
}
.app-tabs__tab.is-on { color: var(--app-accent); }
.app-tabs__tab--main svg { width: 46px; height: 46px; margin-top: -1.4rem; padding: 10px; border-radius: 50%; background: var(--app-accent); color: #fff; box-shadow: 0 6px 16px rgba(0, 82, 204, 0.35); }

/* ── Buttons ── */
.app-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
    min-height: 46px; padding: 0 1.1rem; border: 0; border-radius: 12px;
    background: var(--app-surface); color: var(--app-text); font-weight: 600; text-decoration: none; cursor: pointer;
    box-shadow: var(--app-shadow);
    transition: transform 0.08s ease;
}
.app-btn:active { transform: scale(0.98); }
.app-btn:disabled { opacity: 0.55; }
.app-btn--primary { background: var(--app-accent); color: #fff; }
.app-btn--secondary { background: var(--app-surface); color: var(--app-accent); }
.app-btn--ghost { background: transparent; box-shadow: none; color: var(--app-text-2); }
.app-btn--timer { background: var(--app-ok); color: #fff; }
.app-btn--stop { min-height: 38px; padding: 0 0.9rem; background: #fff; color: var(--app-red); box-shadow: none; }
.app-btn--big { min-height: 56px; font-size: 1.05rem; }
.app-btn--wide { width: 100%; margin-bottom: 0.75rem; }
.app-link { padding: 0.4rem 0; border: 0; background: none; color: var(--app-accent); font-weight: 600; text-decoration: none; cursor: pointer; }
.app-link--danger { color: var(--app-red); }

/* ── Fields ── */
.app-input {
    width: 100%; min-height: 48px; padding: 0.65rem 0.85rem;
    border: 1px solid var(--app-line); border-radius: 12px; background: var(--app-surface);
    color: var(--app-text); font: inherit; font-size: 16px;   /* 16px: no zoom on iOS */
}
textarea.app-input { resize: vertical; }
.app-input:focus { border-color: var(--app-accent); outline: none; box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.15); }
.app-field { display: flex; flex-direction: column; gap: 0.45rem; margin: 0 0 1.1rem; }
.app-form__row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 0.75rem; }
.app-field label, .app-field > span:not(.app-label) { color: var(--app-text-2); font-size: 0.9rem; }
.app-label { color: var(--app-text-3); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }

/* ── Toasts ── */
.app-toasts { position: fixed; left: 1rem; right: 1rem; bottom: calc(84px + var(--app-bottom)); z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; pointer-events: none; }
.app-toast {
    max-width: 420px; padding: 0.75rem 1rem; border-radius: 12px; background: var(--app-ink); color: #fff;
    font-size: 0.92rem; box-shadow: 0 10px 30px rgba(15, 26, 43, 0.25); transition: opacity 0.3s ease, transform 0.3s ease;
}
.app-toast--error { background: var(--app-red); }
.app-toast--info { background: #334155; }
.app-toast.is-out { opacity: 0; transform: translateY(8px); }

.app-loading { display: grid; place-items: center; min-height: 40vh; }
.app-spin { width: 28px; height: 28px; border: 3px solid var(--app-line); border-top-color: var(--app-accent); border-radius: 50%; animation: app-spin 0.8s linear infinite; }
@keyframes app-spin { to { transform: rotate(360deg); } }

/* ── Login ── */
body.app--login { display: grid; place-items: center; min-height: 100vh; background: var(--app-ink); }
.app-login { width: min(380px, 100% - 2rem); padding: calc(2rem + var(--app-top)) 0 2rem; color: #fff; }
.app-login__logo { display: block; margin: 0 auto 1rem; }
.app-login__title { margin: 0 0 1.5rem; font-size: 1.2rem; font-weight: 600; text-align: center; opacity: 0.85; }
.app-login__form { display: flex; flex-direction: column; gap: 1rem; padding: 1.4rem; border-radius: 18px; background: var(--app-surface); color: var(--app-text); }
.app-login__form .app-field { margin: 0; }
.app-login__form .app-field span { font-size: 0.85rem; font-weight: 600; }
.app-login__form input { width: 100%; min-height: 50px; padding: 0.7rem 0.9rem; border: 1px solid var(--app-line); border-radius: 12px; font: inherit; font-size: 16px; }
.app-login__error { margin: 0; padding: 0.7rem 0.9rem; border-radius: 10px; background: #fdecec; color: var(--app-red); font-size: 0.9rem; }
.app-login__hint { margin: 0; color: var(--app-text-3); font-size: 0.82rem; text-align: center; }
