/* TSD Admin — референс: светлая панель, оранжевый акцент, карточки */
:root {
    color-scheme: light;
    --bg-page: #f0f1f4;
    --bg-sidebar: #ffffff;
    --card: #ffffff;
    --text: #1a1d26;
    --text-soft: #4b5563;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --orange: #ff6b00;
    --orange-hover: #e85f00;
    --orange-soft: #fff4ed;
    --orange-ring: rgba(255, 107, 0, 0.22);
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --off: #b45309;
    --off-bg: #ffedd5;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06), 0 10px 28px rgba(15, 23, 42, 0.06);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 272px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg-page);
    color: var(--text);
    line-height: 1.45;
    font-size: 15px;
}

.auth-layout {
    min-height: calc(100vh - 48px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px 48px;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
}

/* —— Sidebar —— */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 20px 14px 16px;
    z-index: 40;
}

.brand {
    font-weight: 800;
    font-size: 1.35rem;
    letter-spacing: -0.03em;
    margin: 0 8px 20px;
    color: var(--text);
}

.brand span {
    color: var(--orange);
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    overflow-y: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.menu-item:hover {
    background: #f9fafb;
    color: var(--text);
}

.menu-item.active {
    background: var(--orange-soft);
    color: var(--orange);
    border-color: rgba(255, 107, 0, 0.25);
}

.menu-item.active .menu-ico {
    color: var(--orange);
}

.menu-ico {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: #9ca3af;
}

.menu-item:hover .menu-ico,
.menu-item.active .menu-ico {
    color: inherit;
}

.sidebar-help {
    margin-top: 12px;
    padding: 12px 12px 12px 40px;
    border-radius: var(--radius-sm);
    background: #f9fafb;
    border: 1px solid var(--border);
    font-size: 12px;
    line-height: 1.45;
    color: var(--muted);
    position: relative;
}

.sidebar-help::before {
    content: "?";
    position: absolute;
    left: 12px;
    top: 12px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #e5e7eb;
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* —— Main column —— */
.content-area {
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: 100%;
    overflow-x: hidden;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 28px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

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

.topbar-heading {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}

.topbar-sub {
    margin: 4px 0 0;
    font-size: 13px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #fafafa;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--orange) 0%, #ff8533 100%);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-caret {
    font-size: 10px;
    color: var(--muted);
    margin-left: 2px;
}

.page {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding: 20px 28px 32px;
    animation: pageFade 0.22s ease;
}

.page.page-admin {
    max-width: none;
    padding: 20px 28px 40px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 28px;
    box-shadow: var(--shadow-card);
    width: 100%;
    min-width: 0;
}

.card:hover {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 14px 36px rgba(15, 23, 42, 0.08);
}

.auth-card {
    max-width: 440px;
    margin: 48px auto;
}

h1 {
    margin: 0 0 8px;
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

h2, h3 {
    margin: 0 0 8px;
    font-weight: 600;
}

.muted {
    color: var(--muted);
}

.row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.tabs-inline {
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
    padding: 4px;
    background: #f3f4f6;
    border-radius: var(--radius-sm);
    width: fit-content;
}

.tabs-inline a {
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-soft);
}

.tabs-inline a:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.7);
}

.tabs-inline a.active {
    background: #fff;
    color: var(--orange);
    box-shadow: var(--shadow-sm);
}

.form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 18px 0;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    align-items: end;
    gap: 12px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-soft);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
input[type="email"],
textarea,
select {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--orange);
    box-shadow: 0 0 0 3px var(--orange-ring);
}

.checkbox {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--orange);
    cursor: pointer;
}

/* —— Buttons —— */
button,
.button-primary {
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    background: var(--orange);
    color: #fff;
    transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 6px rgba(255, 107, 0, 0.35);
}

button:hover:not(:disabled),
.button-primary:hover {
    background: var(--orange-hover);
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

button.button-secondary {
    background: #fff;
    color: var(--orange);
    border: 2px solid var(--orange);
    box-shadow: none;
}

button.button-secondary:hover:not(:disabled) {
    background: var(--orange-soft);
    transform: translateY(-1px);
}

button.ghost,
.button-ghost,
a.ghost {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border-strong);
    box-shadow: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

a.ghost {
    margin-left: 0;
}

button.ghost:hover,
.button-ghost:hover,
a.ghost:hover {
    background: #f9fafb;
    border-color: var(--orange);
    color: var(--orange);
    transform: translateY(-1px);
}

.btn-sm {
    padding: 7px 12px;
    font-size: 13px;
}

/* —— Tables —— */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 14px;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f9fafb;
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

tbody tr:hover td {
    background: #fafafa;
}

pre.json-cell {
    margin: 8px 0 0;
    padding: 10px;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-width: 520px;
    max-height: 280px;
    overflow: auto;
    font-size: 12px;
    white-space: pre;
}

.center {
    text-align: center;
}

.badge {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge.ok {
    color: var(--ok);
    background: var(--ok-bg);
}

.badge.off {
    color: var(--off);
    background: var(--off-bg);
}

.doc-numbers-cell {
    min-width: 280px;
    max-width: 520px;
    vertical-align: top;
}

.doc-numbers-wrap {
    padding: 4px 0;
}

.doc-numbers-meta {
    font-size: 12px;
    color: var(--muted, #64748b);
    margin-bottom: 8px;
    font-weight: 500;
}

.doc-numbers-warn {
    color: #b45309;
    font-weight: 600;
}

.doc-numbers-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
}

.doc-numbers-chips--details {
    margin-bottom: 12px;
    max-height: 320px;
    overflow-y: auto;
    padding: 8px;
    background: #f8fafc;
    border-radius: var(--radius-sm, 8px);
    border: 1px solid #e2e8f0;
}

.doc-number-chip {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
    white-space: nowrap;
}

.doc-number-chip:nth-child(6n + 1) {
    color: #1e40af;
    background: #dbeafe;
    border-color: #93c5fd;
}

.doc-number-chip:nth-child(6n + 2) {
    color: #166534;
    background: #dcfce7;
    border-color: #86efac;
}

.doc-number-chip:nth-child(6n + 3) {
    color: #9a3412;
    background: #ffedd5;
    border-color: #fdba74;
}

.doc-number-chip:nth-child(6n + 4) {
    color: #6b21a8;
    background: #f3e8ff;
    border-color: #d8b4fe;
}

.doc-number-chip:nth-child(6n + 5) {
    color: #9f1239;
    background: #ffe4e6;
    border-color: #fda4af;
}

.doc-number-chip:nth-child(6n + 6) {
    color: #0f766e;
    background: #ccfbf1;
    border-color: #5eead4;
}

.info-callout {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    font-size: 14px;
    line-height: 1.5;
    margin: 16px 0 20px;
}

.info-callout::before {
    content: "i";
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #3b82f6;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    font-style: normal;
    display: flex;
    align-items: center;
    justify-content: center;
}

.alerts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    animation: slideDown 0.22s ease;
}

.alert {
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 14px;
    border: 1px solid transparent;
}

.alert.success {
    color: #166534;
    background: #dcfce7;
    border-color: #86efac;
}

.alert.error {
    color: #991b1b;
    background: #fee2e2;
    border-color: #fca5a5;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    font-size: 14px;
    color: var(--muted);
}

.pagination a {
    color: var(--orange);
    text-decoration: none;
    font-weight: 600;
}

.pagination a:hover {
    text-decoration: underline;
}

@keyframes pageFade {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: relative;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .menu {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .page.page-admin {
        padding: 16px 14px 28px;
    }

    .topbar {
        flex-wrap: wrap;
        padding: 12px 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
