/* iXRome — mobile first, тёмная и светлая темы */

/* ---------- Токены: тёмная тема по умолчанию ---------- */
:root {
    --bg:        #000000;
    --bg-soft:   #0b0b0d;
    --surface:   #121216;
    --surface-2: #1a1a20;
    --border:    #26262e;
    --border-2:  #33333d;
    --text:      #f2f2f5;
    --text-dim:  #9b9ba6;
    --accent:    #6f7bff;
    --accent-ink:#ffffff;
    --danger-bg: #2a1215;
    --danger-br: #5a2027;
    --danger-tx: #ff9aa5;
    --shadow:    0 18px 48px rgba(0, 0, 0, .55);
    --radius:    16px;
    color-scheme: dark;
}

/* Системная светлая тема, если пользователь не выбрал тёмную вручную */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg:        #f4f5f8;
        --bg-soft:   #ffffff;
        --surface:   #ffffff;
        --surface-2: #f1f2f6;
        --border:    #e1e3ea;
        --border-2:  #cfd2dc;
        --text:      #14151a;
        --text-dim:  #5f6472;
        --accent:    #3b49d6;
        --accent-ink:#ffffff;
        --danger-bg: #fdecee;
        --danger-br: #f3c2c8;
        --danger-tx: #a11d2b;
        --shadow:    0 14px 36px rgba(20, 21, 26, .12);
        color-scheme: light;
    }
}

/* Явный выбор светлой темы — побеждает всегда */
:root[data-theme="light"] {
    --bg:        #f4f5f8;
    --bg-soft:   #ffffff;
    --surface:   #ffffff;
    --surface-2: #f1f2f6;
    --border:    #e1e3ea;
    --border-2:  #cfd2dc;
    --text:      #14151a;
    --text-dim:  #5f6472;
    --accent:    #3b49d6;
    --accent-ink:#ffffff;
    --danger-bg: #fdecee;
    --danger-br: #f3c2c8;
    --danger-tx: #a11d2b;
    --shadow:    0 14px 36px rgba(20, 21, 26, .12);
    color-scheme: light;
}

/* ---------- База ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a { color: var(--accent); }

/* ---------- Переключатель темы ---------- */
.theme-switch {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    z-index: 20;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-dim);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.theme-switch:hover { color: var(--text); border-color: var(--border-2); }
.theme-switch svg { width: 20px; height: 20px; fill: currentColor; }
.theme-switch .ico-sun  { display: none; }
.theme-switch .ico-moon { display: block; }

:root[data-theme="light"] .theme-switch .ico-sun  { display: block; }
:root[data-theme="light"] .theme-switch .ico-moon { display: none; }

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) .theme-switch .ico-sun  { display: block; }
    :root:not([data-theme="dark"]) .theme-switch .ico-moon { display: none; }
}

/* На странице входа кнопка в потоке страницы, не перекрывает карточку */
.is-auth .theme-switch { position: absolute; }

/* ---------- Экран авторизации ---------- */
.auth {
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.auth::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(60% 45% at 50% 0%, rgba(111, 123, 255, .18), transparent 70%);
}

.card {
    position: relative;
    width: 100%;
    max-width: 400px;
    padding: 28px 20px 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.card__head { text-align: center; margin-bottom: 22px; }

.logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-bottom: 14px;
    border-radius: 14px;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    font-size: 20px;
    letter-spacing: .5px;
}

.logo--sm {
    width: 32px;
    height: 32px;
    margin: 0;
    border-radius: 9px;
    font-size: 13px;
}

.card__title { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.2px; }
.card__sub   { margin: 6px 0 0; font-size: 14px; color: var(--text-dim); }

.alert {
    margin: 0 0 16px;
    padding: 11px 13px;
    border: 1px solid var(--danger-br);
    border-radius: 11px;
    background: var(--danger-bg);
    color: var(--danger-tx);
    font-size: 14px;
}

/* ---------- Поля ---------- */
.field { display: block; margin-bottom: 15px; }

.field__label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
}

.field__wrap { position: relative; display: block; }

.field__input {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--border-2);
    border-radius: 11px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 16px; /* 16px — иначе iOS зумит при фокусе */
    font-family: inherit;
    appearance: none;
}

.field__input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(111, 123, 255, .25);
}

.field__wrap .field__input { padding-right: 50px; }

.field__eye {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-dim);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.field__eye svg { fill: none; stroke: currentColor; stroke-width: 1.7; }
.field__eye.is-on { color: var(--accent); }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 50px;
    margin-top: 6px;
    padding: 13px 18px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: var(--accent);
    color: var(--accent-ink);
    font: 600 16px/1 inherit;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }

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

.btn--sm { min-height: 40px; margin: 0; padding: 9px 14px; font-size: 14px; }

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

/* ---------- Шапка панели ---------- */
.top {
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--border);
    background: var(--bg-soft);
    padding-top: env(safe-area-inset-top);
}

.top__in {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 11px 16px;
}

.top__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top__name  { font-weight: 600; font-size: 16px; white-space: nowrap; }
.top__right { display: flex; align-items: center; gap: 10px; }

.top__user {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    color: var(--text-dim);
}

/* Кнопка темы в шапке, а не фиксированная — чтобы не налезала на контент */
.top .theme-switch {
    position: static;
    width: 40px;
    height: 40px;
}

/* ---------- Контент панели ---------- */
.wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 22px 16px calc(32px + env(safe-area-inset-bottom));
}

.h1   { margin: 0 0 6px; font-size: 24px; font-weight: 650; letter-spacing: -.3px; }
.lead { margin: 0 0 22px; color: var(--text-dim); font-size: 15px; }

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.tile {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.tile__t { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.tile__d { margin: 0 0 12px; font-size: 14px; color: var(--text-dim); }

.tag {
    display: inline-block;
    padding: 4px 9px;
    border: 1px solid var(--border-2);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-dim);
    font-size: 12px;
}

/* ---------- Планшет / десктоп ---------- */
@media (min-width: 480px) {
    .card { padding: 34px 30px 26px; }
    .top__user { max-width: 200px; }
}

@media (min-width: 680px) {
    .grid { grid-template-columns: 1fr 1fr; gap: 14px; }
    .h1   { font-size: 28px; }
    .wrap { padding-top: 30px; }
    .tile { padding: 18px; }
}

@media (min-width: 1000px) {
    .grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ======================================================================
   Навигация: на мобильном — нижний таб-бар как в приложениях,
   на десктопе те же пункты встают в шапку.
   ====================================================================== */

/* --- Мобильный таб-бар (по умолчанию) --- */
.nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    display: flex;
    align-items: stretch;
    border-top: 1px solid var(--border);
    background: var(--bg-soft);
    padding-bottom: env(safe-area-inset-bottom);
}

.nav__i {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 56px;
    padding: 7px 2px;
    color: var(--text-dim);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.nav__i.is-active { color: var(--accent); }
.nav__i:active    { background: var(--surface-2); }

.nav__ico {
    width: 23px;
    height: 23px;
    fill: currentColor;
    flex: none;
}

.nav__t {
    font-size: 10.5px;
    line-height: 1.1;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Контент не должен уезжать под таб-бар */
.has-nav .wrap {
    padding-bottom: calc(56px + 24px + env(safe-area-inset-bottom));
}

/* В шапке на мобильном имя пользователя лишнее — места мало */
.top__user { display: none; }

/* --- Десктоп: пункты уезжают в шапку, таб-бар выключаем --- */
@media (min-width: 860px) {
    .nav {
        position: static;
        border-top: 0;
        background: none;
        padding-bottom: 0;
        gap: 2px;
        margin: 0 auto;
    }

    .nav__i {
        flex: 0 0 auto;
        flex-direction: row;
        gap: 8px;
        min-height: 40px;
        padding: 8px 12px;
        border-radius: 10px;
        font-size: 15px;
    }

    .nav__i:hover { color: var(--text); background: var(--surface-2); }

    .nav__i.is-active {
        color: var(--accent);
        background: var(--surface-2);
    }

    .nav__ico { width: 19px; height: 19px; }
    .nav__t   { font-size: 15px; }

    .has-nav .wrap { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
    .top__user     { display: inline; }
}

/* ---------- Плитки-ссылки и пустые разделы ---------- */
.tile {
    display: block;
    color: inherit;
    text-decoration: none;
}

.tile:active { background: var(--surface-2); }

@media (min-width: 860px) {
    .tile { transition: border-color .15s ease; }
    .tile:hover { border-color: var(--border-2); }
}

.top__brand {
    color: inherit;
    text-decoration: none;
}

.empty {
    padding: 34px 18px;
    border: 1px dashed var(--border-2);
    border-radius: 14px;
    background: var(--surface);
    text-align: center;
}

.empty__t { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.empty__d { margin: 0; font-size: 14px; color: var(--text-dim); }

/* ======================================================================
   Обмен файлами /share
   ====================================================================== */

.notice {
    margin: 0 0 16px;
    padding: 11px 13px;
    border: 1px solid var(--border-2);
    border-radius: 11px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
}

.link {
    color: var(--accent);
    text-decoration: underline;
    cursor: pointer;
}

/* ---------- Зона загрузки ---------- */
.drop {
    position: relative;
    display: block;
    margin: 0 0 18px;
    padding: 26px 16px 20px;
    border: 1.5px dashed var(--border-2);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: center;
}

.drop.is-over {
    border-color: var(--accent);
    background: var(--surface-2);
}

.drop__input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    border: 0;
}

.drop__ico {
    width: 34px;
    height: 34px;
    margin-bottom: 10px;
    fill: var(--text-dim);
}

.drop.is-over .drop__ico { fill: var(--accent); }

.drop__t { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.drop__d { margin: 0; font-size: 14px; color: var(--text-dim); line-height: 1.6; }

.drop__lim {
    margin: 14px 0 0;
    font-size: 12px;
    color: var(--text-dim);
}

kbd {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border-2);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font: 500 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Очередь загрузки ---------- */
.queue {
    margin: 0 0 18px;
    display: grid;
    gap: 8px;
}

.qrow {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "name size"
        "bar  bar"
        "stat stat";
    gap: 5px 10px;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    font-size: 14px;
}

.qrow__n {
    grid-area: name;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.qrow__s  { grid-area: size; color: var(--text-dim); font-size: 13px; }
.qrow__st { grid-area: stat; color: var(--text-dim); font-size: 12px; }

.qrow__bar {
    grid-area: bar;
    display: block;
    height: 4px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}

.qrow__bar i {
    display: block;
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    transition: width .15s linear;
}

.qrow.is-done .qrow__bar i { background: #27a567; }
.qrow.is-done .qrow__st    { color: #27a567; }

.qrow.is-err { border-color: var(--danger-br); background: var(--danger-bg); }
.qrow.is-err .qrow__st { color: var(--danger-tx); }

/* ---------- Заголовок списка ---------- */
.listhead {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 12px;
}

.h1--sm { margin: 0; font-size: 19px; }

.listhead__n {
    padding: 2px 9px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-dim);
    font-size: 13px;
}

/* ---------- Список файлов ---------- */
.flist {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

.frow {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 11px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.frow__thumb {
    flex: none;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--surface-2);
    overflow: hidden;
    text-decoration: none;
}

.frow__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.frow__thumb--ext {
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .3px;
}

.frow__main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.frow__name {
    color: var(--text);
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.frow__name:hover { color: var(--accent); }
.frow__meta { color: var(--text-dim); font-size: 12.5px; }

.frow__act {
    flex: none;
    display: flex;
    gap: 2px;
}

.iconbtn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--text-dim);
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.iconbtn svg { width: 19px; height: 19px; fill: currentColor; }
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.iconbtn--del:hover { color: var(--danger-tx); }

@media (min-width: 680px) {
    .drop    { padding: 40px 24px 26px; }
    .drop__t { font-size: 18px; }
    .frow    { padding: 12px 14px; gap: 14px; }

    .qrow {
        grid-template-columns: 1fr 150px 90px;
        grid-template-areas: "name bar stat";
        align-items: center;
        gap: 14px;
    }

    .qrow__s { display: none; }
}

.tag--on {
    border-color: rgba(39, 165, 103, .45);
    background: rgba(39, 165, 103, .14);
    color: #3cc07f;
}
