/* Pegasus CRM design system — SPEC «Дизайн CRM». No frameworks. */

:root {
    --bg: #0f1218;
    --panel: #171c26;
    --panel-2: #1e2531;
    --text: #e6e9ef;
    --muted: #8b94a3;
    --border: #2a3240;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-text: #ffffff;
    --danger: #dc2626;
    --ok: #16a34a;
    --warn: #d97706;
    --info: #0284c7;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 16px rgba(0, 0, 0, .25);
    --ring: 0 0 0 3px rgba(37, 99, 235, .35);
}

[data-theme="light"] {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --panel-2: #f1f4f8;
    --text: #1a2230;
    --muted: #5b6675;
    --border: #d9dfe8;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-text: #ffffff;
    --danger: #dc2626;
    --ok: #16a34a;
    --warn: #b45309;
    --info: #0369a1;
    --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 4px 16px rgba(16, 24, 40, .08);
    --ring: 0 0 0 3px rgba(37, 99, 235, .25);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

code, .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: .92em;
}

h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ── Layout ─────────────────────────────────────────────── */

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar .wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-top: 10px;
    padding-bottom: 10px;
    flex-wrap: wrap;
}

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 20px 0 14px; flex-wrap: wrap; }

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: 15px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .sub { color: var(--muted); font-weight: 400; }
.wordmark { font-weight: 700; letter-spacing: .18em; font-size: 15px; }

.mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
    font-size: 15px;
    flex: none;
}
img.mark { object-fit: cover; background: #050b18; border: 1px solid var(--border); }
.login-logo { width: 220px; max-width: 70vw; border-radius: var(--radius); display: block; }

.nav {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
}

.nav a {
    display: block;
    padding: 8px 14px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}

.nav a:hover { color: var(--text); text-decoration: none; }

.nav a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.content { padding-bottom: 40px; }

/* ── Toolbar / bar ──────────────────────────────────────── */

.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bar .spacer { flex: 1; }

/* ── Buttons ────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.4;
    transition: background .12s ease, border-color .12s ease, filter .12s ease;
}

.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }

.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); filter: none; }

.btn.mini { padding: 3px 9px; font-size: 12.5px; border-radius: 6px; }

.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ── Cards & grid ───────────────────────────────────────── */

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}

.card h2, .card h3 { margin-top: 0; }

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

.stat { display: block; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat .label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: .82rem; margin-top: 2px; }

.stack { display: grid; gap: 16px; }

.cols-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .cols-2 { grid-template-columns: 1fr 1fr; } }

/* ── Tags & badges ──────────────────────────────────────── */

.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    text-decoration: none;
}

a.tag:hover { border-color: var(--accent); color: var(--accent); }
.tag.active { border-color: var(--accent); color: var(--accent); background: rgba(37, 99, 235, .12); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.badge.up { background: rgba(22, 163, 74, .15); color: #4ade80; }
.badge.warn { background: rgba(217, 119, 6, .16); color: #fbbf24; }
.badge.down { background: rgba(220, 38, 38, .16); color: #f87171; }
.badge.info { background: rgba(2, 132, 199, .16); color: #38bdf8; }
.badge.muted { background: var(--panel-2); color: var(--muted); }

[data-theme="light"] .badge.up { color: #15803d; }
[data-theme="light"] .badge.warn { color: #b45309; }
[data-theme="light"] .badge.down { color: #b91c1c; }
[data-theme="light"] .badge.info { color: #0369a1; }

/* ── Tables ─────────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: var(--panel-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Forms ──────────────────────────────────────────────── */

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 13.5px; }
.field .hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }

input, select, textarea {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
}

input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }

input[type="checkbox"], input[type="radio"] { width: auto; margin-right: 6px; }

.checkbox-row { display: flex; align-items: center; gap: 6px; }
.checkbox-row label { margin: 0; font-weight: 400; }

.invalid-feedback { color: #f87171; font-size: .82rem; margin-top: 4px; }
[data-theme="light"] .invalid-feedback { color: #b91c1c; }

input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--danger); }

.form-narrow { max-width: 420px; }

/* ── Alerts / empty states ──────────────────────────────── */

.empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: transparent;
}

.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid var(--border); }
.alert.error { background: rgba(220, 38, 38, .12); border-color: rgba(220, 38, 38, .4); color: #f87171; }
.alert.success { background: rgba(22, 163, 74, .12); border-color: rgba(22, 163, 74, .4); color: #4ade80; }
[data-theme="light"] .alert.error { color: #b91c1c; }
[data-theme="light"] .alert.success { color: #15803d; }

/* ── Toasts ─────────────────────────────────────────────── */

#toasts {
    position: fixed;
    right: 16px;
    bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    max-width: 340px;
}

.toast {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px 14px;
    font-size: 13.5px;
    animation: toast-in .18s ease;
}

.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast.hide { opacity: 0; transform: translateY(6px); transition: opacity .25s ease, transform .25s ease; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* ── Dialog ─────────────────────────────────────────────── */

dialog.confirm {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    box-shadow: var(--shadow);
    padding: 0;
    max-width: 400px;
    width: calc(100% - 32px);
}

dialog.confirm::backdrop { background: rgba(0, 0, 0, .55); }

dialog.confirm .dlg-body { padding: 20px; }
dialog.confirm h3 { margin-bottom: 8px; }
dialog.confirm .dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 16px; }

/* ── User menu / header bits ────────────────────────────── */

.user-menu { position: relative; }
.user-menu > button { background: none; border: none; cursor: pointer; color: var(--text); font: inherit; }
.user-menu .dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 180px;
    padding: 6px;
    z-index: 60;
}
.user-menu.open .dropdown { display: block; }
.user-menu .dropdown a, .user-menu .dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--text);
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
}
.user-menu .dropdown a:hover, .user-menu .dropdown button:hover { background: var(--panel-2); text-decoration: none; }

.search-input { position: relative; flex: 1; min-width: 180px; max-width: 420px; }
.search-input input { padding-left: 32px; }
.search-input .icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

/* ── Footer version bar ─────────────────────────────────── */

.verbar {
    margin-top: 40px;
    padding: 14px 0 22px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .8rem;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Login page ─────────────────────────────────────────── */

.guest-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.guest-card { width: 100%; max-width: 380px; }
.guest-card .brand { justify-content: center; margin-bottom: 18px; font-size: 16px; }

/* ── Print ──────────────────────────────────────────────── */

@media print {
    .topbar, .nav, .verbar, #toasts, .no-print { display: none !important; }
    body { background: #fff; color: #000; font-size: 12px; }
    .card { box-shadow: none; border: 1px solid #ccc; }
    .wrap { max-width: none; padding: 0; }
    a { color: #000; text-decoration: none; }
}
