/* ============================================================
   1C User Manager — UI в духе Apple Human Interface Guidelines
   Системная типографика · палитра iOS · матовая навигация
   Светлая и тёмная темы через prefers-color-scheme
   ============================================================ */

/* ---------- Токены ---------- */
:root {
    color-scheme: light dark;

    /* Поверхности */
    --bg: #F2F2F7;
    --surface: #FFFFFF;
    --surface-2: #F5F5F7;
    --fill: rgba(120, 120, 128, 0.08);
    --fill-2: rgba(120, 120, 128, 0.14);
    --fill-3: rgba(120, 120, 128, 0.22);

    /* Текст */
    --label: #1D1D1F;
    --label-2: rgba(60, 60, 67, 0.62);
    --label-3: rgba(60, 60, 67, 0.36);
    --separator: rgba(60, 60, 67, 0.14);

    /* Акцент — systemBlue (заливки настроены под контраст AA) */
    --blue: #0071E3;
    --blue-hover: #0060C2;
    --blue-soft: rgba(0, 122, 255, 0.12);
    --blue-fg: #0069CC;
    --ring: rgba(0, 122, 255, 0.28);

    /* Семантика */
    --red: #E5342B;
    --red-hover: #C92D25;
    --red-soft: rgba(255, 59, 48, 0.11);
    --red-fg: #D70015;
    --green-fg: #1F7A34;
    --green-soft: rgba(52, 199, 89, 0.14);
    --orange-soft: rgba(255, 149, 0, 0.15);
    --orange-soft-hover: rgba(255, 149, 0, 0.24);
    --orange-fg: #9A5B00;

    /* Навигация */
    --nav-bg: rgba(255, 255, 255, 0.72);

    /* Тени */
    --shadow-card: 0 1px 1px rgba(0, 0, 0, 0.03), 0 4px 14px rgba(0, 0, 0, 0.05);
    --shadow-float: 0 2px 8px rgba(0, 0, 0, 0.06), 0 16px 48px rgba(0, 0, 0, 0.16);

    /* Форма */
    --radius-s: 8px;
    --radius: 12px;
    --radius-l: 16px;
    --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0A0A0C;
        --surface: #1C1C1E;
        --surface-2: #2C2C2E;
        --fill: rgba(120, 120, 128, 0.22);
        --fill-2: rgba(120, 120, 128, 0.32);
        --fill-3: rgba(120, 120, 128, 0.44);

        --label: #F5F5F7;
        --label-2: rgba(235, 235, 245, 0.62);
        --label-3: rgba(235, 235, 245, 0.36);
        --separator: rgba(84, 84, 88, 0.45);

        --blue: #0071E3;
        --blue-hover: #1D82F0;
        --blue-soft: rgba(10, 132, 255, 0.2);
        --blue-fg: #79B2FF;
        --ring: rgba(10, 132, 255, 0.38);

        --red: #D7372E;
        --red-hover: #E84B42;
        --red-soft: rgba(255, 69, 58, 0.17);
        --red-fg: #FF827B;
        --green-fg: #5BD877;
        --green-soft: rgba(48, 209, 88, 0.17);
        --orange-soft: rgba(255, 159, 10, 0.17);
        --orange-soft-hover: rgba(255, 159, 10, 0.26);
        --orange-fg: #FFB340;

        --nav-bg: rgba(18, 18, 20, 0.72);

        --shadow-card: 0 1px 1px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.35);
        --shadow-float: 0 2px 10px rgba(0, 0, 0, 0.4), 0 16px 48px rgba(0, 0, 0, 0.5);
    }
}

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

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--label);
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: -0.006em;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--blue-fg); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
    background: var(--fill);
    padding: 1px 6px;
    border-radius: 6px;
}

:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--ring);
}

::selection { background: var(--blue-soft); }

/* ---------- Иконки ---------- */
.icon {
    display: inline-block;
    flex: none;
    width: 1.1em;
    height: 1.1em;
    vertical-align: -0.18em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.btn-primary .icon, .btn-danger .icon { stroke-width: 2; }


/* ---------- Навигация ---------- */
.topnav {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    height: 52px;
    padding: 0 24px;
    background: var(--nav-bg);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--separator);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 27px;
    height: 27px;
    border-radius: 7px;
    background: var(--blue);
    color: #fff;
    flex: none;
}
.brand a { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; color: var(--label); }
.brand a:hover { text-decoration: none; }

.nav-links { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 980px;
    font-size: 13px;
    font-weight: 500;
    color: var(--label-2);
    white-space: nowrap;
}
.nav-links a svg { opacity: 0.85; }
.nav-links a:hover { background: var(--fill); color: var(--label); text-decoration: none; }
.nav-links a.active { background: var(--blue-soft); color: var(--blue-fg); }

.nav-user { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 3px 5px 3px 11px;
    border-radius: 999px;
    background: var(--fill);
}
.user-name { font-size: 12.5px; font-weight: 600; color: var(--label); }
.role-badge {
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--orange-soft);
    color: var(--orange-fg);
}
.inline-form { display: inline; }

/* ---------- Каркас страницы ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 56px; }

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 18px;
}
.page-header h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.page-header .muted { margin: 3px 0 0; word-break: break-all; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}
.back-link:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 12px; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border: none;
    border-radius: 10px;
    background: var(--fill-2);
    color: var(--label);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.006em;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.18s var(--ease), transform 0.1s var(--ease);
}
.btn:hover { background: var(--fill-3); text-decoration: none; }
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red-hover); }
.btn-warn { background: var(--orange-soft); color: var(--orange-fg); }
.btn-warn:hover { background: var(--orange-soft-hover); }

.btn-sm { height: 28px; padding: 0 11px; font-size: 12px; border-radius: 8px; gap: 5px; }

.btn-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    padding: 6px 8px;
    border-radius: 8px;
    color: var(--label-2);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    transition: color 0.18s var(--ease), background-color 0.18s var(--ease);
}
.btn-link:hover { color: var(--label); background: var(--fill); text-decoration: none; }

/* ---------- Таблицы ---------- */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-card);
}
.table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 720px; }
.table th, .table td {
    text-align: left;
    padding: 11px 16px;
    border-bottom: 1px solid var(--separator);
    vertical-align: middle;
}
.table th {
    background: var(--surface-2);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--label-2);
    white-space: nowrap;
}
.table tbody tr { transition: background-color 0.15s var(--ease); }
.table tbody tr:hover { background: var(--fill); }
.table tbody tr:last-child td { border-bottom: none; }

.actions-cell { white-space: nowrap; }
.actions-cell form { display: inline-block; margin-left: 6px; }
.actions-cell form:first-child { margin-left: 0; }

/* ---------- Теги и статусы ---------- */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--fill);
    color: var(--label-2);
    white-space: nowrap;
}
.tag-green { background: var(--green-soft); color: var(--green-fg); }
.tag-red { background: var(--red-soft); color: var(--red-fg); }
.tag-amber { background: var(--orange-soft); color: var(--orange-fg); }
.tag-blue { background: var(--blue-soft); color: var(--blue-fg); }

/* ---------- Формы ---------- */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-stack > label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--label-2);
}

input[type="text"], input[type="password"], input[type="search"], select {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--separator);
    border-radius: 10px;
    background: var(--surface);
    color: var(--label);
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
input::placeholder { color: var(--label-3); }
input:hover, select:hover { border-color: var(--label-3); }
input:focus, select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 4px var(--ring);
}

select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 32px;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888890' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
}

fieldset {
    border: none;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 14px 16px 16px;
    margin: 0;
}
legend {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--label-2);
    padding: 0 0 8px;
}

.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 12px; }
.check-item {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 400;
    color: var(--label);
}
fieldset label:not(.check-item) {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 400;
    color: var(--label);
}

input[type="checkbox"], input[type="radio"] {
    width: 16px;
    height: 16px;
    margin: 0;
    flex: none;
    accent-color: var(--blue);
}

/* ---------- Диалоги ---------- */
.dialog {
    border: none;
    border-radius: var(--radius-l);
    padding: 22px;
    width: min(460px, calc(100vw - 32px));
    background: var(--surface);
    color: var(--label);
    box-shadow: var(--shadow-float);
}
.dialog::backdrop {
    background: rgba(0, 0, 0, 0.35);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    backdrop-filter: blur(8px) saturate(120%);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- Карточки ---------- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 18px 20px;
    margin-top: 18px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }

/* ---------- Уведомления ---------- */
.alert {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13.5px;
}
.alert svg { flex: none; margin-top: 1px; }
.alert-error { background: var(--red-soft); color: var(--red-fg); }
.alert .small { opacity: 0.78; }

.row-detail td { padding: 0 16px 14px; background: var(--surface); }
.row-detail .alert { margin-bottom: 0; }

/* ---------- Панель инструментов и поиск ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.search-form { display: flex; gap: 8px; }
.search-field { position: relative; width: 280px; max-width: 100%; }
.search-field svg {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--label-3);
    pointer-events: none;
}
.search-field input { padding-left: 33px; height: 34px; }

.mass-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.mass-summary .tag { font-size: 12.5px; padding: 4px 12px; }

/* ---------- Индикация загрузки ---------- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    flex: none;
    border: 2px solid var(--blue-soft);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Вход ---------- */
.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(900px 420px at 50% -80px, var(--blue-soft), transparent 70%), var(--bg);
}
.login-card {
    width: min(380px, 100%);
    background: var(--surface);
    border-radius: 20px;
    box-shadow: var(--shadow-float);
    padding: 34px 30px 30px;
    text-align: center;
}
.login-logo {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 13px;
    background: var(--blue);
    color: #fff;
    margin: 0 auto 14px;
}
.login-logo svg { width: 26px; height: 26px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.login-card > .muted { margin: 0 0 20px; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; height: 42px; font-size: 14.5px; margin-top: 4px; }
.login-card .alert { text-align: left; }

/* ---------- Пустые состояния ---------- */
.empty-cell { padding: 44px 16px !important; text-align: center; color: var(--label-2); }
.empty-cell svg { width: 36px; height: 36px; display: block; margin: 0 auto 10px; opacity: 0.45; stroke-width: 1.3; }

/* ---------- Утилиты ---------- */
.muted { color: var(--label-2); }
.small { font-size: 12px; }
.center { text-align: center; }
.error-text { color: var(--red-fg); }

/* ---------- Адаптив ---------- */
@media (max-width: 720px) {
    .topnav { padding: 0 16px; gap: 12px; }
    .container { padding: 20px 16px 40px; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .btn { justify-content: center; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-field { width: 100%; }
}

@media (max-width: 560px) {
    .brand a { display: none; }
    .user-chip { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ---------- Доступность: уменьшенное движение ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
