:root {
    --blue: #1e6bff;
    --blue-dark: #1553cc;
    --navy: #0e1b3d;
    --text: #1b2437;
    --muted: #6b7488;
    --line: #e3e7ef;
    --bg: #f4f6fa;
    --card: #fff;
    --red: #d6323a;
    --green: #17925a;
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
}

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

h1 { font-size: 22px; margin: 0; color: var(--navy); }
h1:focus { outline: none; }
h2 { font-size: 16px; margin: 0 0 12px; color: var(--navy); }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }

/* Каркас */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex: none;
    background: var(--navy);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 20px 12px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand { display: block; font-weight: 600; font-size: 16px; color: #fff; padding: 0 10px 18px; }
.brand:hover { text-decoration: none; }
.brand span { display: block; font-weight: 400; font-size: 12px; opacity: .6; }
.brand.dark { color: var(--navy); padding: 0 0 8px; font-size: 20px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar nav a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 8px;
    color: #c9d2e6;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .08); text-decoration: none; }
.sidebar nav a.active { background: var(--blue); color: #fff; }
.nav-group { padding: 16px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .45; }
.count { background: #ff5a5f; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }

.logout { display: flex; align-items: center; gap: 8px; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .12); }
.logout .who { flex: 1; overflow: hidden; text-overflow: ellipsis; opacity: .8; }
.logout .btn { color: #fff; border-color: rgba(255, 255, 255, .3); }
.logout .btn:hover { background: rgba(255, 255, 255, .1); }

main { flex: 1; min-width: 0; padding: 24px 28px 64px; max-width: 1240px; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { flex: 1; }
.back { display: inline-block; margin-bottom: 6px; color: var(--muted); }

/* Карточки и таблицы */

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card > h2 .muted { font-weight: 400; font-size: 13px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr.link:hover { background: #f8faff; cursor: pointer; }
.table-card { padding: 4px 8px; overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.thumb { width: 56px; height: 42px; border-radius: 6px; object-fit: cover; background: #e9edf5; display: block; flex: none; }
.thumb.big { width: 120px; height: 84px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; background: #eef1f6; color: #4a556b; }
.badge.blue { background: #e6efff; color: #1553cc; }
.badge.green { background: #e2f6ec; color: #11734a; }
.badge.purple { background: #efe8ff; color: #5b34c2; }
.badge.yellow { background: #fff4d1; color: #8a6100; }
.badge.red { background: #fde8e9; color: #b3232a; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: inherit; display: block; }
.stat:hover { border-color: var(--blue); text-decoration: none; }
.stat b { display: block; font-size: 26px; color: var(--navy); line-height: 1.1; }
.stat span { color: var(--muted); }
.stat.accent b { color: var(--blue); }

/* Формы */

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: 1 / -1; }

.field { display: block; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field > small { display: block; color: var(--muted); margin-top: 3px; font-size: 12px; }

input, select, textarea {
    width: 100%;
    font: inherit;
    color: inherit;
    padding: 7px 10px;
    border: 1px solid #cfd6e4;
    border-radius: 7px;
    background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(30, 107, 255, .25); border-color: var(--blue); }
input:disabled { background: #f1f3f7; color: var(--muted); }
textarea { resize: vertical; min-height: 72px; }
input[type=checkbox] { width: auto; margin: 0; }

.check { display: flex; align-items: center; gap: 8px; padding-top: 22px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font: inherit;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: 7px;
    border: 1px solid #cfd6e4;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: #f3f6fb; text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--red); border-color: #f0c2c4; }
.btn.danger:hover { background: #fdf0f0; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.icon-only { padding: 3px 7px; min-width: 28px; }
.btn.wide { width: 100%; padding: 10px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert.error { background: #fde8e9; color: #8f1a20; }
.alert.ok { background: #e2f6ec; color: #0d5c3b; }
.alert.warn { background: #fff4d1; color: #6e4d00; }
.alert ul { margin: 0; padding-left: 18px; }

.save-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    margin-top: 4px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 -4px 16px rgba(14, 27, 61, .06);
}
.save-bar .spacer { flex: 1; }
.saved { color: var(--green); }

/* Редакторы списков */

.rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .narrow { width: 150px; flex: none; }
.row > .tiny { width: 96px; flex: none; }
.row-actions { display: flex; gap: 4px; flex: none; }
.row .num { width: 22px; flex: none; color: var(--muted); text-align: right; }

.question { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: #fbfcfe; }
.question-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.question-head b { flex: 1; color: var(--navy); }
.sub { font-size: 12px; color: var(--muted); margin: 14px 0 6px; }

.image-picker { display: flex; gap: 10px; align-items: flex-start; }
.image-picker .controls { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.image-picker .line { display: flex; gap: 8px; align-items: center; }
.err { color: var(--red); font-size: 12px; }

.icon { width: 20px; height: 20px; fill: currentColor; display: block; }
.icon-picker { position: relative; flex: none; }
.icon-btn { width: 36px; height: 34px; display: grid; place-items: center; border: 1px solid #cfd6e4; border-radius: 7px; background: #fff; color: var(--blue); cursor: pointer; padding: 0; }
.icon-grid {
    position: absolute;
    z-index: 10;
    top: 38px;
    left: 0;
    width: 236px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    padding: 8px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(14, 27, 61, .16);
}
.icon-grid .icon-btn { border-color: transparent; color: var(--text); width: 100%; }
.icon-grid .icon-btn:hover, .icon-grid .icon-btn.selected { background: #e6efff; color: var(--blue); }

.details { background: #fbfcfe; }
.details td { padding: 14px 18px; }
.answers { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 12px; }
.answers dt { color: var(--muted); }
.answers dd { margin: 0; }

/* Вход */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--navy); }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; padding: 28px; margin: 0; }

/* Служебное */

#blazor-error-ui {
    background: #fff4d1;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
    display: none;
    left: 0;
    padding: 10px 20px;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 12px; top: 8px; }

@media (max-width: 900px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; height: auto; position: static; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; }
    .nav-group { display: none; }
    main { padding: 16px; }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span-3 { grid-column: 1 / -1; }
    .row { flex-wrap: wrap; }
}
