:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #18202a;
  --muted: #66717e;
  --accent: #215fa6;
  --accent-dark: #1a4d88;
  --ok: #1f7a4d;
  --warn: #9a6200;
  --err: #a32020;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

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

h1 { font-size: 1.5rem; margin: 0 0 .4rem; }
h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
h4 { font-size: .95rem; margin: .2rem 0 .3rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; margin: .3rem 0; }
.req { color: var(--err); }
.right { text-align: right; }
code {
  background: #eef1f4;
  padding: .1rem .3rem;
  border-radius: 3px;
  font-size: .9em;
}

/* ---------- Шапка ---------- */
.topbar {
  background: var(--accent-dark);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem; height: 2rem;
  background: #fff; color: var(--accent-dark);
  border-radius: var(--radius);
  font-weight: 700; font-size: .85rem;
}
.brand-text { font-weight: 600; }
.topnav { display: flex; gap: 1rem; flex-wrap: wrap; }
.topnav a { color: #e8f0f6; text-decoration: none; }
.topnav a:hover { color: #fff; text-decoration: underline; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.user-role { font-size: .8rem; background: rgba(255,255,255,.15); padding: .15rem .5rem; border-radius: 999px; }
.user-name { font-size: .9rem; }

/* ---------- Страница ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.footer {
  max-width: 1100px; margin: 0 auto; padding: 0 1rem 2rem;
  color: var(--muted); font-size: .85rem;
}

/* ---------- Панели и карточки ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 1rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.panel-internal { border-left: 3px solid var(--warn); }
.error-panel { text-align: center; }

.cards { display: flex; flex-wrap: wrap; gap: .7rem; margin: 1rem 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  min-width: 8.5rem;
}
.card-stat { display: flex; flex-direction: column; }
.stat-value { font-size: 1.5rem; font-weight: 600; }
.stat-label { color: var(--muted); font-size: .85rem; }

.hero { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }
.hero p { max-width: 60ch; color: var(--muted); }

/* ---------- Таблицы ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { background: #eef1f4; font-size: .85rem; font-weight: 600; }
.table tr:last-child td { border-bottom: none; }

/* ---------- Списки ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: .8rem;
  align-items: baseline;
  flex-wrap: wrap;
}
.list-item:last-child { border-bottom: none; }

.empty {
  color: var(--muted);
  background: #f0f3f6;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin: .4rem 0;
}

/* ---------- Формы ---------- */
.form { display: block; }
.stack { display: flex; flex-direction: column; gap: .35rem; }
.inline-form-block { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: .8rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin-top: .6rem; }
input[type="text"], input[type="password"], input[type="file"], textarea, select {
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem 1rem;
  margin: 0 0 1rem;
}
legend { font-size: .9rem; font-weight: 600; padding: 0 .4rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-actions { display: flex; align-items: center; gap: .8rem; margin-top: .8rem; }
.actions { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.assign-form { display: flex; align-items: flex-end; gap: .5rem; }
.assign-form label { margin-top: 0; }
.assign-form select { width: auto; min-width: 12rem; }
.inline-form { display: inline-flex; align-items: center; gap: .4rem; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-block;
  padding: .45rem .9rem;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-small { padding: .25rem .6rem; font-size: .85rem; }
.btn-ghost { background: transparent; color: #e8f0f6; border-color: rgba(255,255,255,.4); }
.btn-ghost:hover { color: #fff; border-color: #fff; }

/* ---------- Сообщения ---------- */
.flashes { list-style: none; margin: 0 0 1rem; padding: 0; }
.flash {
  padding: .6rem .9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  margin-bottom: .5rem;
}
.flash-error { border-color: #e0b4b4; background: #fdf2f2; color: var(--err); }
.flash-success { border-color: #b6d8c4; background: #f1f9f4; color: var(--ok); }

/* ---------- Значки ---------- */
.badge {
  display: inline-block;
  padding: .1rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  background: #e7ebef;
  color: var(--muted);
  white-space: nowrap;
}
.badge-draft { background: #eceff2; color: #4c5866; }
.badge-submitted { background: #e3eefb; color: #1f5f8b; }
.badge-initial_review { background: #fdf0dc; color: #8a5b00; }
.badge-assigned { background: #e9e4fb; color: #4b3b91; }
.badge-in_progress { background: #dff1f6; color: #14606f; }
.badge-result_available { background: #e2f4e8; color: var(--ok); }
.badge-closed { background: #e8eaec; color: #6b7683; }
.badge-question-open { background: #fdeaea; color: var(--err); }
.badge-question-answered { background: #fdf3e0; color: var(--warn); }
.badge-question-resolved { background: #e2f4e8; color: var(--ok); }

/* ---------- Карточка заявки ---------- */
.request-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.next-action {
  background: #eaf2f8;
  border: 1px solid #cfe0ec;
  border-radius: var(--radius);
  padding: .7rem 1rem;
  margin: .5rem 0 1rem;
}
.result-block { border-left: 3px solid var(--ok); padding-left: .8rem; margin-bottom: 1rem; }
.result-draft { border-left-color: var(--warn); }
.questions { list-style: none; margin: 0; padding: 0; }
.question {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: .7rem .9rem;
  margin-bottom: .7rem;
  background: #fff;
}
.question-open { border-left-color: var(--err); }
.question-answered { border-left-color: var(--warn); }
.question-resolved { border-left-color: var(--ok); }
.question-head { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; margin-bottom: .3rem; }
.answer { background: #f5f8fa; border-radius: var(--radius); padding: .4rem .7rem; margin: .5rem 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  padding: .4rem 0 .4rem .9rem;
  border-left: 2px solid var(--border);
  display: flex;
  gap: .7rem;
  flex-wrap: wrap;
  align-items: baseline;
}
.timeline-when { min-width: 9rem; }
.timeline-action { font-weight: 600; }
.timeline-actor { font-style: italic; }

/* ---------- Страница входа ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  width: 100%;
  max-width: 24rem;
}
.login-card .btn { margin-top: 1rem; }

/* ---------- Адаптивность ---------- */
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar-user { margin-left: 0; width: 100%; }
  .timeline-when { min-width: 0; }
  .table { display: block; overflow-x: auto; }
}

/* ---------- Оболочка кабинета (по макету) ---------- */
.akp-topbar {
  display: flex; align-items: center; gap: 1rem; min-height: 64px; padding: 0 1.2rem;
  background: #fff; border-bottom: 1px solid var(--border);
}
.akp-topbar .brand { color: var(--text); }
.akp-topbar .brand-mark { background: var(--accent); color: #fff; border-radius: 10px; }
.akp-topbar .topbar-user { margin-left: auto; }
.akp-topbar .user-role { background: #eaf2fb; color: var(--accent); }
.akp-topbar .user-name { color: var(--text); font-weight: 600; }
.akp-topbar .btn-ghost { color: var(--text); border-color: var(--border); }
.akp-topbar .btn-ghost:hover { color: var(--accent); border-color: var(--accent); }
.akp-frame { display: flex; min-height: calc(100vh - 64px); }
.akp-sidebar {
  width: 188px; flex: none; padding: 1rem .7rem; background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: .8rem; justify-content: space-between;
}
.akp-side-nav { display: flex; flex-direction: column; gap: 2px; }
.akp-side-nav a { display: block; padding: .55rem .8rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.akp-side-nav a:hover { background: #f3f5f7; color: var(--text); }
.akp-side-nav a[aria-current="page"] { background: #eaf2fb; color: var(--accent); }
.akp-help { font-size: .78rem; color: var(--muted); line-height: 1.4; }
.akp-main { flex: 1; min-width: 0; }
.page { margin: 0; max-width: 1100px; }
.panel, .card, .hero, .table, .question { box-shadow: 0 1px 2px rgba(26,37,49,.04); }
.table th { background: #f7f8fa; }
@media (max-width: 720px) {
  .akp-frame { flex-direction: column; }
  .akp-sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .akp-side-nav { flex-direction: row; flex-wrap: wrap; }
  .akp-help { display: none; }
}

/* ---------- Карточка заявки (по макету) ---------- */
.akp-breadcrumb { font-size: .8rem; color: var(--muted); margin-bottom: .5rem; }
.akp-breadcrumb a { color: var(--muted); }
.request-head h1 { font-size: 1.7rem; letter-spacing: -.01em; }
.status-focus {
  display: flex; align-items: center; gap: .9rem; padding: .9rem 1.1rem; margin: .8rem 0 1.2rem;
  background: #fff5e6; border: 1px solid #f1dcb8; border-radius: 12px;
}
.status-focus-icon {
  flex: none; width: 2.2rem; height: 2.2rem; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: #fbe6c3; color: #9a5a00; font-weight: 700;
}
.status-focus-title { font-weight: 600; }
.status-focus-text { color: var(--muted); font-size: .92rem; }
.next-action { display: none; }
.steps { list-style: none; display: flex; margin: 0 0 1.4rem; padding: 0; }
.step { flex: 1; position: relative; text-align: left; padding-top: 1.5rem; font-size: .8rem; color: var(--muted); }
.step::before { content: ""; position: absolute; top: .45rem; left: 1.1rem; right: -.2rem; height: 2px; background: var(--border); }
.step:last-child::before { display: none; }
.step-dot { position: absolute; top: 0; left: 0; width: 1rem; height: 1rem; border-radius: 50%; background: #fff; border: 2px solid var(--border); }
.step.is-done .step-dot { background: #28744a; border-color: #28744a; }
.step.is-done::before { background: #28744a; }
.step.is-current .step-dot { background: #9a5a00; border-color: #9a5a00; }
.step.is-current { color: var(--text); font-weight: 600; }
.panel h2 { font-size: 1.05rem; }
.request .panel { border-radius: 12px; }
@media (max-width: 720px) { .step-label { display: none; } .step { padding-top: 1.2rem; } }
.step { padding-right: .6rem; }

/* ---------- Позиции и вопросы (по макету) ---------- */
.pos-list { list-style: none; margin: 0; padding: 0; }
.pos-row { display: flex; align-items: center; gap: .9rem; padding: .8rem 0; border-bottom: 1px solid var(--border); }
.pos-row:last-child { border-bottom: 0; }
.pos-tag {
  flex: none; min-width: 2.4rem; text-align: center; padding: .25rem .4rem; border-radius: 8px;
  background: #f3f5f7; border: 1px solid var(--border); font-weight: 700; font-size: .85rem;
}
.pos-main { flex: 1; min-width: 0; }
.pos-title { font-weight: 600; }
.pos-meta { color: var(--muted); font-size: .82rem; }
.pos-state { flex: none; font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; }
.pos-state::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--border); }
.pos-state.is-warn { color: #9a5a00; } .pos-state.is-warn::before { background: #9a5a00; }
.pos-state.is-ok { color: #28744a; } .pos-state.is-ok::before { background: #28744a; }
.pos-state.is-info { color: var(--accent); } .pos-state.is-info::before { background: var(--accent); }
.count-pill { flex: none; min-width: 1.8rem; text-align: center; padding: .15rem .5rem; border-radius: 999px; background: #fdeaea; color: #a83d3d; font-weight: 600; font-size: .85rem; }
.panel-questions.has-open { border-color: #f1dcb8; }
.panel-questions .questions { margin-top: .8rem; }
.question { border-left-width: 1px; border-radius: 10px; box-shadow: none; }
.question-open { background: #fffaf0; border-color: #f1dcb8; }
.question-answered { background: #fff; }
.question-resolved { background: #fafbfc; }
.question-head .muted:first-of-type { font-weight: 600; }

/* ---------- Главная и списки (по макету) ---------- */
.req-list { list-style: none; margin: 0; padding: 0; }
.req-row { display: flex; align-items: center; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--border); }
.req-row:last-child { border-bottom: 0; }
.req-num {
  flex: none; padding: .25rem .6rem; border-radius: 8px; background: #f3f5f7; border: 1px solid var(--border);
  font-weight: 700; font-size: .82rem; color: var(--text); text-decoration: none; white-space: nowrap;
}
.req-num:hover { border-color: var(--accent); color: var(--accent); }
.cards { gap: .8rem; }
.card-stat { min-width: 9rem; flex: 1 1 9rem; max-width: 12rem; }
.card-stat .stat-value { color: var(--muted); }
.card-stat.has-value { border-color: #cfe0f3; background: #f6faff; }
.card-stat.has-value .stat-value { color: var(--accent); }
.panel-head h2 { margin: 0; }
.panel-head { margin-bottom: .6rem; }
.request-head h1, .page > h1 { letter-spacing: -.01em; }
.page > h1 { font-size: 1.7rem; }
@media (max-width: 720px) { .req-row { flex-wrap: wrap; } }

/* ---------- Вкладки, возврат, фильтры ---------- */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin: 0 0 1.2rem; overflow-x: auto; }
.tab { padding: .6rem .9rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; border-radius: 999px; background: #eef1f4; color: var(--muted); font-size: .75rem; text-align: center; }
.tab.is-active .tab-count { background: #eaf2fb; color: var(--accent); }
.status-focus.is-return { background: #fff0f0; border-color: #efcaca; }
.status-focus.is-return .status-focus-icon { background: #f6d4d4; color: #a83d3d; }
.return-form { flex-basis: 100%; border-top: 1px solid var(--border); padding-top: .8rem; }
.return-form textarea { margin: .3rem 0 .5rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: 0 0 1rem; }
.filters input[type="search"] { flex: 1 1 14rem; width: auto; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; background: #fff; }
.filters select { width: auto; min-width: 11rem; }
.filters .check { display: inline-flex; align-items: center; gap: .4rem; margin: 0; font-size: .88rem; }
.count-pill-soft { background: #eef1f4; color: var(--muted); }

.topbar-user a.user-name { color: var(--text); text-decoration: none; }
.topbar-user a.user-name:hover { color: var(--accent); }

/* ---------- AI-разбор ---------- */
.ai-badge { flex: none; font-size: .78rem; padding: .15rem .6rem; border-radius: 999px; background: #eaf2fb; color: var(--accent); white-space: nowrap; }
.ai-badge.is-cloud { background: #fff5e6; color: #9a5a00; }
.ai-suggestion { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .6rem; }
.ai-pos-label { display: flex; gap: .8rem; align-items: center; margin: 0; flex: 1; font-size: inherit; color: inherit; cursor: pointer; }
.ai-missing { margin: .2rem 0 .6rem 1.1rem; padding: 0; color: #9a5a00; }
.ai-engine { border: 0; padding: 0; margin: 0 0 .6rem; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.ai-engine .check { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }

/* ---------- Состав установки ---------- */
.components { list-style: none; margin: .4rem 0 0; padding: 0; display: grid; gap: .25rem; }
.component { display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; font-size: .85rem; padding: .2rem .5rem; background: #f7f8fa; border-radius: 8px; }
.component-kind { font-weight: 600; color: var(--accent); }
.component-params { color: var(--muted); }

/* ---------- Привязка к серии ---------- */
.catalog-box { display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; margin-top: .3rem; padding: .25rem .6rem; background: #eaf2fb; border-radius: 8px; }
.catalog-series { font-weight: 600; color: var(--accent); }
.catalog-link { color: var(--accent); font-weight: 600; }

/* ---------- Результативность инженеров ---------- */
.level-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.level-name { font-weight: 700; font-size: 1.1rem; }
.level-bar { height: .6rem; background: #eef1f4; border-radius: 999px; overflow: hidden; margin-top: .6rem; }
.level-bar span { display: block; height: 100%; background: linear-gradient(90deg, #215fa6, #3b8bd9); border-radius: 999px; }
.badges { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .6rem; }
.badge-card { display: flex; flex-direction: column; gap: .15rem; padding: .6rem .8rem; border: 1px dashed var(--border); border-radius: 10px; opacity: .55; }
.badge-card.is-earned { opacity: 1; border-style: solid; background: #f6faff; border-color: #cfe0f3; }
.badge-title { font-weight: 600; }
.stars { color: #d9902b; letter-spacing: .1em; white-space: nowrap; }
.rating-comment { font-size: .85rem; color: var(--muted); font-style: italic; }
.rules { margin: .2rem 0 0 1.1rem; padding: 0; font-size: .9rem; }
.rating-stars { border: 0; padding: 0; margin: 0 0 .4rem; display: inline-flex; flex-direction: row-reverse; justify-content: flex-end; }
.rating-stars input { position: absolute; opacity: 0; }
.rating-stars label { font-size: 1.8rem; color: #cfd5dc; cursor: pointer; margin: 0; padding: 0 .1rem; }
.rating-stars input:checked ~ label, .rating-stars label:hover, .rating-stars label:hover ~ label { color: #d9902b; }
.rating-stars input:focus-visible + label { outline: 2px solid var(--accent); }
.count-pill-xp { background: #eaf2fb; color: var(--accent); }

/* ---------- Диспетчерская ---------- */
.complexity { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; white-space: nowrap; background: #eef1f4; color: var(--muted); }
.complexity.c2 { background: #eaf2fb; color: #215fa6; }
.complexity.c3 { background: #fff5e6; color: #9a5a00; }
.complexity.c4 { background: #ffe9d6; color: #b3500a; }
.complexity.c5 { background: #fdeaea; color: #a83d3d; font-weight: 600; }
.load-bar { flex: none; width: 8rem; height: .5rem; background: #eef1f4; border-radius: 999px; overflow: hidden; }
.load-bar span { display: block; height: 100%; background: linear-gradient(90deg, #3b8bd9, #d9902b); }
