/* ============================================================
 * FO — Дизайн-токены (U1)
 * iOS-native style · light/dark/auto · индиго акцент
 * ============================================================
 *
 * Используем семантические имена (--label, --bg, --separator), а не
 * сырые цвета. Это позволяет потом легко перекрашивать всё приложение.
 * Старые имена переменных (--primary, --muted, --border, --bg-card)
 * сохранены как алиасы — admin.css и app.css продолжают работать без
 * правок, но при переписывании конкретных экранов лучше использовать
 * новые семантические токены.
 */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
html { color-scheme: light dark; scroll-behavior: smooth; }

/* View Transitions API — плавные переходы между экранами (если браузер поддерживает) */
@supports (view-transition-name: none) {
    ::view-transition-old(root), ::view-transition-new(root) {
        animation-duration: .25s;
        animation-timing-function: cubic-bezier(.4,0,.2,1);
    }
}

body {
    font-family: var(--font);
    font-size: var(--text-base);
    line-height: 1.45;
    color: var(--label);
    background: var(--bg);
    /* Сглаживание в Safari/Chrome */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---- ТОКЕНЫ: LIGHT (по умолчанию) ---- */
:root {
    /* Шрифт. SF Pro для Apple, далее Inter (если установлен), системные fallback'и */
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
            "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

    /* Шкала размеров текста (iOS-like) */
    --text-xs:   12px;
    --text-sm:   13px;
    --text-base: 16px;
    --text-md:   17px;   /* iOS body */
    --text-lg:   20px;
    --text-xl:   22px;   /* title3 */
    --text-2xl:  28px;   /* title2 */
    --text-3xl:  34px;   /* large title */

    /* Палитра — light (iOS systemX) */
    --bg:          #f2f2f7;   /* systemGroupedBackground */
    --bg-elev:     #ffffff;   /* secondarySystemGroupedBackground */
    --bg-card:     #ffffff;
    --bg-overlay:  rgba(15,23,42,0.55);   /* затемнение под модалкой */

    --label:       #000000;
    --label-2:     #3c3c43;          /* secondaryLabel */
    --label-3:     rgba(60,60,67,0.6);  /* tertiaryLabel */
    --label-4:     rgba(60,60,67,0.3);  /* quaternaryLabel */
    --label-on-accent: #ffffff;

    --separator:        rgba(60,60,67,0.18);
    --separator-opaque: #c6c6c8;

    /* Акценты */
    --accent:    #6366f1;   /* индиго */
    --accent-h:  #4f46e5;   /* hover */
    --accent-2:  #818cf8;   /* light variant */
    --accent-bg: rgba(99,102,241,0.10);

    --danger:    #ff3b30;   /* iOS red */
    --danger-h:  #d70015;
    --danger-bg: rgba(255,59,48,0.10);

    --success:   #34c759;   /* iOS green */
    --success-h: #248a3d;
    --success-bg: rgba(52,199,89,0.12);

    --warning:   #ff9500;   /* iOS orange */
    --warning-h: #c93400;
    --warning-bg: rgba(255,149,0,0.12);

    /* Радиусы */
    --r-xs: 6px;
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 18px;
    --r-xl: 22px;
    --r-full: 999px;

    /* Тени (мягкие, iOS-like) */
    --shadow-1:  0 1px 2px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-2:  0 4px 14px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
    --shadow-3:  0 12px 32px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.06);
    --shadow-sheet: 0 -8px 32px rgba(0,0,0,0.12);

    /* Размеры тач-таргетов */
    --tap-min: 44px;          /* iOS HIG минимум */
    --tap-cta: 56px;          /* основная CTA */
    --tap-big: 64px;          /* «у нас даже слепой попадёт» */

    /* ---- LEGACY-алиасы (для admin.css/app.css до их переписи) ---- */
    --primary:   var(--accent);
    --primary-h: var(--accent-h);
    --muted:     var(--label-3);
    --border:    var(--separator);
}

/* ---- ТОКЕНЫ: DARK (системная либо ручная) ---- */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:          #000000;
        --bg-elev:     #1c1c1e;     /* secondarySystemGroupedBackground */
        --bg-card:     #1c1c1e;
        --bg-overlay:  rgba(0,0,0,0.75);

        --label:       #ffffff;
        --label-2:     #ebebf5;
        --label-3:     rgba(235,235,245,0.6);
        --label-4:     rgba(235,235,245,0.3);

        --separator:        rgba(84,84,88,0.40);
        --separator-opaque: #38383a;

        --accent:    #818cf8;      /* в темноте чуть ярче */
        --accent-h:  #6366f1;
        --accent-2:  #a5b4fc;
        --accent-bg: rgba(129,140,248,0.16);

        --danger:    #ff453a;
        --danger-bg: rgba(255,69,58,0.16);

        --success:   #30d158;
        --success-bg: rgba(48,209,88,0.16);

        --warning:   #ff9f0a;
        --warning-bg: rgba(255,159,10,0.16);

        --shadow-1:  0 1px 2px rgba(0,0,0,0.40);
        --shadow-2:  0 4px 14px rgba(0,0,0,0.50);
        --shadow-3:  0 12px 32px rgba(0,0,0,0.60);
        --shadow-sheet: 0 -8px 32px rgba(0,0,0,0.60);
    }
}

/* ---- РУЧНОЙ override: data-theme="dark" ---- */
:root[data-theme="dark"] {
    --bg:          #000000;
    --bg-elev:     #1c1c1e;
    --bg-card:     #1c1c1e;
    --bg-overlay:  rgba(0,0,0,0.75);

    --label:       #ffffff;
    --label-2:     #ebebf5;
    --label-3:     rgba(235,235,245,0.6);
    --label-4:     rgba(235,235,245,0.3);

    --separator:        rgba(84,84,88,0.40);
    --separator-opaque: #38383a;

    --accent:    #818cf8;
    --accent-h:  #6366f1;
    --accent-2:  #a5b4fc;
    --accent-bg: rgba(129,140,248,0.16);

    --danger:    #ff453a;
    --danger-bg: rgba(255,69,58,0.16);

    --success:   #30d158;
    --success-bg: rgba(48,209,88,0.16);

    --warning:   #ff9f0a;
    --warning-bg: rgba(255,159,10,0.16);

    --shadow-1:  0 1px 2px rgba(0,0,0,0.40);
    --shadow-2:  0 4px 14px rgba(0,0,0,0.50);
    --shadow-3:  0 12px 32px rgba(0,0,0,0.60);
    --shadow-sheet: 0 -8px 32px rgba(0,0,0,0.60);
}

/* ---- РУЧНОЙ override: data-theme="light" — оставляем default ---- */

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }

.container { max-width: 720px; margin: 0 auto; padding: 16px; }
.center-screen {
    display: flex; align-items: center; justify-content: center;
    min-height: 100dvh; padding: 16px;
}
/* На низких viewport (мобила с открытой клавиатурой, ландшафт) прижимаем карточку
   к верху — иначе flex-centering + 100dvh выдавливает форму за экран и появляется скролл. */
@media (max-height: 700px) {
    .center-screen { align-items: flex-start; padding-top: 24px; }
}
.card {
    background: var(--bg-card);
    border-radius: var(--r-md);
    padding: 24px;
    box-shadow: var(--shadow-1);
    width: 100%;
    max-width: 420px;
    color: var(--label);
}
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; letter-spacing: -0.01em; color: var(--label); }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
.muted { color: var(--label-3); font-size: var(--text-sm); }

label { display: block; font-size: var(--text-sm); color: var(--label-3); margin: 12px 0 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="tel"],
input[type="email"], input[type="date"], textarea, select {
    width: 100%;
    font: inherit; color: var(--label);
    background: var(--bg-elev);
    border: 1px solid var(--separator);
    border-radius: var(--r-sm);
    padding: 11px 12px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}
textarea { min-height: 70px; resize: vertical; }

.btn {
    position: relative; overflow: hidden;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 18px;
    min-height: var(--tap-min);
    font-size: var(--text-base); font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--label-on-accent);
    box-shadow: 0 1px 2px rgba(99,102,241,0.18);
    transition: background .18s ease, transform .12s ease, box-shadow .25s ease, filter .15s;
}
.btn:hover { background: var(--accent-h); box-shadow: 0 6px 18px rgba(99,102,241,0.28); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.985); box-shadow: 0 1px 2px rgba(99,102,241,0.2); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-bg); }
.btn-block { width: 100%; }
.btn-secondary {
    background: var(--bg-elev); color: var(--label); border-color: var(--separator);
    box-shadow: var(--shadow-1);
}
.btn-secondary:hover { background: var(--bg); border-color: var(--separator-opaque); box-shadow: var(--shadow-2); }
.btn-danger { background: var(--danger); box-shadow: 0 1px 2px rgba(255,59,48,0.2); }
.btn-danger:hover { background: var(--danger-h); box-shadow: 0 6px 18px rgba(255,59,48,0.3); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; filter: grayscale(.2); }

/* Ripple-like при клике */
.btn::after {
    content: ''; position: absolute; inset: 0;
    background: radial-gradient(circle at center, rgba(255,255,255,.45), transparent 60%);
    opacity: 0; pointer-events: none;
    transition: opacity .4s ease;
}
.btn:active::after { opacity: 1; transition: opacity .05s; }

/* Универсальный fadeInUp */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes pop {
    0%   { transform: scale(.85); opacity: 0; }
    60%  { transform: scale(1.04); opacity: 1; }
    100% { transform: scale(1); }
}
.fade-in-up { animation: fadeInUp .35s ease both; }
.fade-in    { animation: fadeIn .25s ease both; }

/* Карточка появляется с подъёмом */
.card { animation: fadeInUp .4s ease both; }

.error {
    background: var(--danger-bg); color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--r-sm);
    padding: 10px 12px; margin: 10px 0;
    font-size: var(--text-base);
}
.ok {
    background: var(--success-bg); color: var(--success-h);
    border: 1px solid var(--success);
    border-radius: var(--r-sm);
    padding: 10px 12px; margin: 10px 0;
    font-size: var(--text-base);
}
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.spacer { height: 12px; }

/* ===== Кнопка-иконка (общая для app/admin) ===== */
.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none;
    width: 38px; height: 38px; padding: 0;
    color: var(--label-2); border-radius: var(--r-sm);
    transition: background .15s, color .15s, transform .12s;
    cursor: pointer;
    flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg); color: var(--label); }
.btn-icon:active { transform: scale(.92); }
.btn-icon svg { display: block; }

/* Опасный акцент (выход) */
.btn-icon-danger { color: var(--label-3); }
.btn-icon-danger:hover { background: var(--danger-bg); color: var(--danger); transform: rotate(-6deg); }
.btn-icon-danger:active { transform: rotate(-6deg) scale(.94); }

/* ===== Skeleton / shimmer для лоадеров ===== */
.skeleton {
    background: linear-gradient(90deg, var(--bg) 0%, var(--separator) 50%, var(--bg) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    border-radius: var(--r-sm);
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-line { height: 14px; margin: 6px 0; }
.skeleton-card { height: 64px; margin-bottom: 10px; }

/* ===== Spinner ===== */
.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid var(--separator);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Чипы с поп-анимацией ===== */
.chip { animation: pop .25s ease both; transition: transform .15s; }
.chip:hover { transform: translateY(-1px); }

/* ===== Переключатель темы в шапке (использует .btn-icon как базу) ===== */
.theme-toggle svg { display: block; }
.theme-toggle[data-theme-state="light"] .ico-moon,
.theme-toggle[data-theme-state="light"] .ico-system,
.theme-toggle[data-theme-state="dark"]  .ico-sun,
.theme-toggle[data-theme-state="dark"]  .ico-system,
.theme-toggle[data-theme-state="auto"]  .ico-sun,
.theme-toggle[data-theme-state="auto"]  .ico-moon { display: none; }
/* Анимация смены состояния — лёгкое вращение */
.theme-toggle svg { transition: transform .35s cubic-bezier(.4,1.4,.6,1); }
.theme-toggle:active svg { transform: rotate(30deg) scale(.85); }

/* ============================================================ */
/*  Brand-блок на страницах входа/регистрации                  */
/* ============================================================ */
.auth-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: -6px 0 18px;
}
.auth-brand img {
    width: 56px; height: 56px;
    border-radius: 12px;
    display: block;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
.auth-brand-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--label);
    line-height: 1;
    letter-spacing: -.005em;
}
.auth-brand-sub {
    font-size: 13px;
    font-weight: 500;
    color: var(--label-3);
    margin-top: 4px;
}
