:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e7eaf0;
    --muted: #8b93a4;
    --accent: #4f8cff;
    --green: #33c58a;
    --red: #ff5d6c;
    --amber: #f5b544;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { display: inline-flex; }
.logo { height: 30px; display: block; }
.row-gap { display: flex; gap: 10px; }

.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px;
}

.btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 9px 16px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.mini { padding: 5px 10px; font-size: 13px; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 26px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.stat-card .num { font-size: 28px; font-weight: 700; }
.stat-card .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat-card.accent .num { color: var(--accent); }
.stat-card.green .num { color: var(--green); }
.stat-card.red .num { color: var(--red); }
.stat-card.amber .num { color: var(--amber); }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 8px 16px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 14px;
}
.tab.active { background: var(--surface-2); color: var(--text); border-color: var(--accent); }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody tr[data-det] { cursor: pointer; }
td.product {
    max-width: 360px;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    cursor: pointer;
}
td.product:hover { color: var(--accent); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid transparent;
}
.badge.work { background: rgba(79,140,255,.14); color: var(--accent); }
.badge.done { background: rgba(51,197,138,.14); color: var(--green); }
.badge.cancel { background: rgba(255,93,108,.14); color: var(--red); }
.badge.return { background: rgba(245,181,68,.14); color: var(--amber); }

.rebadge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid rgba(245,181,68,.4);
    background: rgba(245,181,68,.14);
    color: var(--amber);
    vertical-align: middle;
}
.rebadge:hover { background: rgba(245,181,68,.24); }

.hist-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 10px; }
.hist-list li { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.hist-list li .muted { font-size: 12px; }

.overdue { color: var(--red); font-weight: 600; }
.ontime { color: var(--green); }
.muted { color: var(--muted); }

.login-card {
    max-width: 380px;
    margin: 8vh auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

input, select {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.admin-head h1 { font-size: 22px; margin: 0; }

.modal[hidden] { display: none; }
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 16px;
    z-index: 50;
    overflow-y: auto;
}
.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 560px;
}
.modal-box h2 { margin: 0 0 18px; font-size: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.error { color: var(--red); font-size: 13px; min-height: 16px; }

@media (max-width: 560px) {
    .form-grid { grid-template-columns: 1fr; }
    .container { padding: 16px; }
}

/* ---------- рейтинг ---------- */
.rating {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 20px;
}
.rating-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.rating-title { font-size: 17px; font-weight: 700; }
.rating-sub { color: var(--muted); font-size: 13px; }
.rating-metrics { display: flex; gap: 28px; margin: 16px 0 14px; flex-wrap: wrap; }
.metric .pv { font-size: 30px; font-weight: 700; line-height: 1; }
.metric .pl { color: var(--muted); font-size: 13px; margin-top: 4px; }
.metric.good .pv { color: var(--green); }
.metric.warn .pv { color: var(--amber); }
.metric.bad  .pv { color: var(--red); }
.rating-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.rating-bar .seg { display: block; height: 100%; }
.seg.g { background: var(--green); }
.seg.b { background: var(--accent); }
.seg.r { background: var(--red); }
.seg.a { background: var(--amber); }
.seg.x { background: #55606f; }
.rating-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; color: var(--muted); font-size: 13px; }
.rating-legend .d { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.d.g { background: var(--green); } .d.b { background: var(--accent); } .d.r { background: var(--red); } .d.a { background: var(--amber); } .d.x { background: #55606f; }

.stat-card.muted-num .num { color: var(--muted); }

/* ---------- бейджи достоверности / проблемный ---------- */
.badge.problem { background: rgba(255,93,108,.16); color: var(--red); border-color: rgba(255,93,108,.4); }
.conf { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; }
.conf.high { background: rgba(51,197,138,.14); color: var(--green); }
.conf.med  { background: rgba(245,181,68,.14); color: var(--amber); }
.conf.low  { background: rgba(255,93,108,.14); color: var(--red); }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--accent); background: var(--surface-2); }

/* ---------- детали заказа ---------- */
.det-list { display: flex; flex-direction: column; gap: 8px; }
.det-row { display: flex; gap: 12px; font-size: 14px; }
.det-k { color: var(--muted); min-width: 130px; }
.det-v { flex: 1; }
.det-quote { margin-top: 6px; padding: 12px 14px; background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 8px; font-style: italic; }
.det-note { margin-top: 4px; color: var(--muted); font-size: 13px; white-space: pre-line; }

/* ---------- пагинация ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.pager .page-size select { width: auto; display: inline-block; padding: 5px 8px; margin-left: 6px; }
.page-nav { display: flex; align-items: center; gap: 6px; }
.page-cur { min-width: 56px; text-align: center; color: var(--text); }
.btn.mini[disabled] { opacity: .4; cursor: default; }
.btn.mini[disabled]:hover { border-color: var(--border); }

.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form-grid label.check input { width: auto; }
.form-grid textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit; resize: vertical; }
.form-grid textarea:focus { outline: none; border-color: var(--accent); }


/* ---------- мелочи в ячейках ---------- */
.overdue-sm { color: var(--red); font-size: 12px; margin-top: 3px; }
.conf-sm { margin-top: 3px; }

/* ---------- адаптив: таблица -> карточки на узких экранах ---------- */
@media (max-width: 720px) {
    .panel { overflow: visible; }
    table.cards thead { display: none; }
    table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
    table.cards tr { border: 1px solid var(--border); border-radius: 10px; margin: 10px; padding: 6px 12px; }
    table.cards tbody tr:hover { background: var(--surface); }
    table.cards td { border: none; padding: 7px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 14px; white-space: normal; text-align: right; }
    table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: 0 0 auto; }
    table.cards td.product { -webkit-line-clamp: unset; line-clamp: unset; max-width: none; display: flex; }
}


.col-more { width: 34px; text-align: center; }
@media (max-width: 720px) { .col-more { display: none; } }

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