@import url("/assets/theme-tokens.css");

/* ---------- Основа ---------- */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 var(--tp-font); background: var(--tp-bg); color: var(--tp-text); }
h1, h2, h3, h4 { margin: 0; font-weight: 700; color: var(--tp-text); }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 15px; }
a { color: var(--tp-active-text); }
hr { border: 0; border-top: 1px solid var(--tp-border); margin: 16px 0; }
code, pre, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
::selection { background: var(--tp-active-bg); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--tp-border); border-radius: 8px; }

/* ---------- Каркас страницы приложения ---------- */
.page { max-width: 1400px; margin: 0 auto; padding: 24px; }
.page-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.page-header .subtitle, .subtitle { color: var(--tp-muted); font-size: 13px; margin-top: 2px; }
.hero { background: var(--tp-hero); border: 1px solid var(--tp-border); border-radius: var(--tp-radius-lg); padding: 24px 28px; margin-bottom: 16px; }

.card {
    background: var(--tp-panel-sheen), var(--tp-surface);
    border: 1px solid var(--tp-border);
    border-radius: 16px;
    padding: 18px 20px;
    margin-bottom: 14px;
    box-shadow: var(--tp-card-shadow);
    transition: border-color .2s ease, box-shadow .2s ease;
}
.card-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.card-header h2, .card-header h3 { display: flex; align-items: center; gap: 8px; }
.card-header h3 { font-size: 16px; }

.flex { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.grid { display: grid; gap: 14px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: 14px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .page { padding: 14px; } }
.mt-4 { margin-top: 16px; } .mb-4 { margin-bottom: 16px; } .mt-2 { margin-top: 8px; } .mb-2 { margin-bottom: 8px; }
.text-muted, .muted { color: var(--tp-muted); font-size: 13px; }
.text-right { text-align: right; } .nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.pos { color: var(--tp-success-text); } .neg { color: var(--tp-danger-text); }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--tp-radius);
    border: 1px solid var(--tp-border);
    background: var(--tp-surface);
    color: var(--tp-text);
    font: 600 13px/1.2 var(--tp-font);
    cursor: pointer;
    box-shadow: var(--tp-control-shadow);
    transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease, filter .2s ease, scale .12s ease;
}
:where(button:not(.btn)) { transition: background-color .2s ease, border-color .2s ease, color .2s ease, scale .12s ease; }
:where(button, .btn):focus-visible { outline: 2px solid var(--tp-primary); outline-offset: 2px; }
.btn:hover { background: var(--tp-hover); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: default; }
.btn-primary { background: var(--tp-primary); border-color: var(--tp-primary); color: var(--tp-primary-text); }
.btn-primary:hover { background: var(--tp-primary-hover); border-color: var(--tp-primary-hover); }
.btn-success { background: var(--tp-success); border-color: var(--tp-success); color: #fff; }
.btn-success:hover { filter: brightness(.92); background: var(--tp-success); }
.btn-danger { background: var(--tp-danger); border-color: var(--tp-danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--tp-danger); }
.btn-info { background: var(--tp-info); border-color: var(--tp-info); color: #fff; }
.btn-info:hover { filter: brightness(.92); background: var(--tp-info); }
.btn-secondary { background: var(--tp-surface); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--tp-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:is(.btn-primary, .btn-success, .btn-info) { background-image: var(--tp-accent-sheen); }

@media (hover: hover) and (pointer: fine) {
    .card:hover { box-shadow: var(--tp-card-shadow-hover); }
    .btn:not(:disabled, [aria-disabled="true"]):hover { filter: brightness(1.06); }
}

@media (prefers-reduced-motion: no-preference) {
    :where(button, .btn):not(:disabled, [aria-disabled="true"]):active { scale: .98; }
    .modal { animation: tp-surface-enter .18s ease-out; }
}

@keyframes tp-surface-enter { from { opacity: .72; } to { opacity: 1; } }

/* ---------- Формы ---------- */
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--tp-border); border-radius: var(--tp-radius);
    background: var(--tp-surface); color: var(--tp-text); font: 14px var(--tp-font);
    transition: border-color .2s ease, box-shadow .2s ease;
}
textarea { min-height: 80px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--tp-muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--tp-primary); box-shadow: 0 0 0 3px var(--tp-info-bg); }
input:disabled, select:disabled, textarea:disabled { opacity: .65; cursor: not-allowed; }
input[type=checkbox], input[type=radio] { accent-color: var(--tp-primary); }
.inline-input { width: auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }
.form-group { margin-bottom: 12px; }
.form-group > label, .form-label { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; color: var(--tp-text-2); margin-bottom: 4px; }
.hint { color: var(--tp-muted); font-size: 12px; margin-top: 4px; }
.field-err { color: var(--tp-danger-text); font-size: 12px; margin-top: 4px; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--tp-border); border-radius: 12px; max-height: 70vh; background: var(--tp-surface); }
.data-table, table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--tp-border); vertical-align: top; }
.data-table th { position: sticky; top: 0; background: var(--tp-panel-sheen), var(--tp-surface-2); color: var(--tp-text-2); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.data-table td { transition: background-color .16s ease; }
.data-table tbody tr:not(.is-danger, .is-warning):hover td { background-color: var(--tp-hover); }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td.num, .data-table th.num { text-align: right; }
.data-table tr.is-muted td { color: var(--tp-muted); text-decoration: line-through; }
.data-table tr.is-danger td { background: var(--tp-danger-bg); }
.data-table tr.is-warning td { background: var(--tp-warning-bg); }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 12px; }

/* ---------- Бейджи, сообщения ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--tp-hover); color: var(--tp-text-2); }
.badge-ok { background: var(--tp-success-bg); color: var(--tp-success-text); }
.badge-warn { background: var(--tp-warning-bg); color: var(--tp-warning-text); }
.badge-danger { background: var(--tp-danger-bg); color: var(--tp-danger-text); }
.badge-info { background: var(--tp-info-bg); color: var(--tp-info-text); }
.badge:is(.badge-ok, .badge-warn, .badge-danger, .badge-info) { box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 18%, transparent); }
.msg { padding: 10px 12px; border-radius: var(--tp-radius); margin-bottom: 12px; font-size: 13px; border: 1px solid transparent; }
.msg-ok { background: var(--tp-success-bg); color: var(--tp-success-text); border-color: var(--tp-success); }
.msg-warn { background: var(--tp-warning-bg); color: var(--tp-warning-text); border-color: var(--tp-warning); }
.msg-bad { background: var(--tp-danger-bg); color: var(--tp-danger-text); border-color: var(--tp-danger); }
.msg-info { background: var(--tp-info-bg); color: var(--tp-info-text); border-color: var(--tp-info); }

/* ---------- Плитки показателей ---------- */
.stat { display: flex; align-items: center; gap: 14px; background: var(--tp-panel-sheen), var(--tp-surface); border: 1px solid var(--tp-border); border-radius: var(--tp-radius-lg); padding: 16px 18px; box-shadow: var(--tp-card-shadow); }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--tp-info-bg); color: var(--tp-info-text); font-size: 20px; flex: none; }
.stat-label { color: var(--tp-muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; text-shadow: var(--tp-metric-glow); }

/* ---------- Вкладки-«таблетки» ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tab { padding: 6px 14px; border-radius: var(--tp-radius); border: 1px solid var(--tp-border); background: transparent; color: var(--tp-text); font: 600 13px var(--tp-font); cursor: pointer; }
.tab:hover { background: var(--tp-hover); }
.tab.active, .tab[aria-selected=true] { background: var(--tp-accent-sheen), var(--tp-primary); border-color: var(--tp-primary); color: var(--tp-primary-text); box-shadow: var(--tp-control-shadow); }

/* ---------- Сворачиваемый раздел ---------- */
.section { border: 1px solid var(--tp-border); border-radius: var(--tp-radius); margin-bottom: 8px; overflow: hidden; }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; background: var(--tp-surface-2); cursor: pointer; user-select: none; }
.section-header:hover { background: var(--tp-hover); }
.section-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.section-body { padding: 12px 14px; border-top: 1px solid var(--tp-border); }
.collapse-arrow { transition: transform .2s; font-size: 12px; color: var(--tp-muted); }
.collapse-arrow.open { transform: rotate(90deg); }

/* ---------- Модальные окна ---------- */
.modal-overlay { position: fixed; inset: 0; background: var(--tp-overlay); backdrop-filter: blur(2px); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--tp-surface); color: var(--tp-text); border: 1px solid var(--tp-border); border-radius: 16px; padding: 22px; max-width: 960px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--tp-shadow-lg); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--tp-border); }
.modal-header h3 { font-size: 18px; }
.modal-close { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--tp-muted); width: 32px; height: 32px; border-radius: 8px; }
.modal-close:hover { background: var(--tp-hover); color: var(--tp-text); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ---------- Загрузка ---------- */
.loading-state { text-align: center; padding: 32px; color: var(--tp-muted); }
.spinner { width: 30px; height: 30px; border: 3px solid var(--tp-border); border-top-color: var(--tp-primary); border-radius: 50%; animation: tp-spin .7s linear infinite; margin: 0 auto 12px; }
@keyframes tp-spin { to { transform: rotate(360deg); } }
.progress { height: 8px; border-radius: 999px; background: var(--tp-hover); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--tp-primary); }
