:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-text: #1f2430;
    --color-muted: #6b7280;
    --color-border: #e3e5ea;
    --color-accent: #2563eb;
    --color-accent-contrast: #ffffff;
    --color-error: #d92d20;
    --color-error-bg: #fdecea;
    --color-ok: #12805c;
    --color-ok-bg: #e6f6ef;
    --radius: 8px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
}

[x-cloak] { display: none !important; }

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

/* ---- Навигация ---- */
.topnav {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 24px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 20px;
    height: 56px;
}

.topnav__brand {
    font-weight: 600;
    white-space: nowrap;
}

.topnav__tabs {
    display: flex;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
}

.topnav__tab {
    padding: 8px 12px;
    border-radius: var(--radius);
    color: var(--color-muted);
    text-decoration: none;
    white-space: nowrap;
    font-size: 14px;
}

.topnav__tab:hover {
    background: var(--color-bg);
}

.topnav__tab--active {
    color: var(--color-text);
    background: var(--color-bg);
    font-weight: 600;
}

.topnav__right {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
}

.topnav__settings {
    text-decoration: none;
    font-size: 14px;
    color: var(--color-muted);
    white-space: nowrap;
}

.topnav__user { position: relative; }

.topnav__user-btn {
    background: none;
    border: none;
    font: inherit;
    color: var(--color-text);
    cursor: pointer;
    padding: 8px;
}

.topnav__menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    min-width: 160px;
    overflow: hidden;
}

.topnav__menu a,
.topnav__menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    background: none;
    border: none;
    font: inherit;
    color: var(--color-text);
    text-decoration: none;
    cursor: pointer;
}

.topnav__menu a:hover,
.topnav__menu button:hover {
    background: var(--color-bg);
}

/* ---- Общая разметка страницы ---- */
.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 48px;
}

.stub {
    text-align: center;
    padding: 80px 20px;
    color: var(--color-muted);
}

.stub__note {
    font-size: 15px;
}

.panel__block {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.panel__block h2 {
    margin-top: 0;
    font-size: 16px;
}

/* ---- Формы ---- */
.form-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 420px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field__label {
    font-size: 13px;
    color: var(--color-muted);
}

.field__input {
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--color-surface);
    color: var(--color-text);
}

.field__hint {
    font-size: 12px;
    color: var(--color-muted);
}

.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font: inherit;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}

.btn--primary {
    background: var(--color-accent);
    color: var(--color-accent-contrast);
}

.btn--secondary {
    background: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text);
}

.btn--small {
    padding: 5px 10px;
    font-size: 13px;
}

.btn--block {
    display: block;
    width: 100%;
}

.inline-form {
    display: inline-block;
}

.settings-check {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.table__actions {
    display: flex;
    gap: 8px;
}

/* ---- Уведомления ---- */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 14px;
}

.alert--error {
    background: var(--color-error-bg);
    color: var(--color-error);
}

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

/* ---- Вход ---- */
.auth-wrap {
    min-height: calc(100vh - 48px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.auth-card__title {
    margin: 0 0 6px;
    font-size: 20px;
    text-align: center;
}

/* ---- Таблицы ---- */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th,
.table td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    color: var(--color-muted);
    font-weight: 500;
}

/* ---- Toasts ---- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.toast {
    background: var(--color-text);
    color: var(--color-surface);
    padding: 10px 16px;
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    font-size: 14px;
    max-width: 320px;
}

@media (max-width: 640px) {
    .topnav {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 12px;
    }
    .topnav__tabs {
        order: 3;
        width: 100%;
    }
}

/* ---- Себестоимость ---- */
.tiles {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.tile {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    text-decoration: none;
    color: inherit;
    display: block;
}

.tile__value {
    font-size: 22px;
    font-weight: 600;
}

.tile__label {
    font-size: 13px;
    color: var(--color-muted);
    margin-top: 2px;
}

.tile--warn .tile__value {
    color: var(--color-error);
}

.tile--active {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px var(--color-accent);
}

.catalog-status {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 13px;
    color: var(--color-muted);
}

.costs-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 20px 0;
}

.costs-controls #costs-search {
    flex: 1;
    min-width: 200px;
}

.table-wrap {
    overflow-x: auto;
}

.costs-table__empty {
    text-align: center;
    color: var(--color-muted);
    padding: 24px;
}

.cost-row--empty {
    box-shadow: inset 3px 0 0 var(--color-error);
}

.cost-row__photo img,
.photo-placeholder {
    display: block;
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    background: var(--color-bg);
    object-fit: cover;
}

.cost-value {
    text-decoration: none;
    color: var(--color-text);
    font-weight: 500;
    border-bottom: 1px dashed var(--color-muted);
}

.cost-edit-form {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.field__input--small {
    padding: 6px 8px;
    width: 90px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
}

.history-row td {
    padding: 0 8px;
    border-bottom: none;
}

.history-table {
    width: 100%;
    font-size: 13px;
    border-collapse: collapse;
    margin: 4px 0 12px;
}

.history-table th,
.history-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
}

.tag {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 999px;
}

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

@media (max-width: 720px) {
    .tiles {
        grid-template-columns: repeat(2, 1fr);
    }

    .costs-table thead {
        display: none;
    }

    .costs-table, .costs-table tbody, .costs-table tr, .costs-table td {
        display: block;
        width: 100%;
    }

    .costs-table tr.cost-row {
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 10px;
        background: var(--color-surface);
    }

    .costs-table tr.history-row {
        border: none;
        margin-top: -8px;
    }

    .costs-table td {
        border-bottom: none;
        padding: 4px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }

    .costs-table td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        color: var(--color-muted);
        font-size: 12px;
    }
}

/* ---- Модалка импорта ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 16px;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal h2 {
    margin-top: 0;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.import-summary {
    margin-top: 16px;
}

.import-summary ul {
    margin: 6px 0 0;
    padding-left: 20px;
}

code {
    background: var(--color-bg);
    padding: 1px 5px;
    border-radius: 4px;
}
