/* ==========================================================================
   Action Potential PF — оформление платформы практикума
   ========================================================================== */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --border: #dde3ec;
  --text: #1d2433;
  --text-muted: #6b7686;
  --accent: #2f6fed;
  --accent-dark: #1f56c4;
  --accent-soft: #e8f0ff;
  --ok: #17915c;
  --ok-soft: #e4f6ed;
  --warn: #b46a05;
  --warn-soft: #fdf1dd;
  --fail: #c4352c;
  --fail-soft: #fdeceb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --mono: "JetBrains Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 12px; line-height: 1.25; font-weight: 650; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }

/* --------------------------------------------------------------- макет */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: #101728;
  color: #cbd5e5;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; color: #fff; margin-bottom: 22px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; background: var(--accent);
  display: grid; place-items: center; font-weight: 700; letter-spacing: .5px;
}
.brand-text { font-weight: 650; font-size: 15px; line-height: 1.2; }
.brand-text small { display: block; font-weight: 400; font-size: 11px; color: #8a97ad; margin-top: 3px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  color: #c2cde0; padding: 9px 11px; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 9px; font-size: 14px;
}
.nav-item:hover { background: #1a2338; color: #fff; text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { width: 18px; display: inline-block; opacity: .85; text-align: center; font-size: 13px; }
.nav-icon::before { content: "•"; }
.icon-book::before { content: "▤"; }
.icon-check::before { content: "✓"; }
.icon-chat::before { content: "✉"; }
.icon-gauge::before { content: "◍"; }
.icon-users::before { content: "●"; }
.icon-list::before { content: "≡"; }
.icon-database::before { content: "▣"; }
.icon-bell::before { content: "✉"; font-size: 16px; }
.sidebar-footer { border-top: 1px solid #24304a; padding-top: 12px; display: grid; gap: 6px; }
.role-chip {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  padding: 3px 8px; border-radius: 20px; display: inline-block; width: fit-content;
  background: #24304a; color: #9fb3d6;
}
.role-chip.role-engineer { background: #1d3b2a; color: #74d3a0; }
.role-chip.role-admin { background: #3b2130; color: #e79ab5; }
.link-button {
  background: none; border: none; color: #8a97ad; cursor: pointer; padding: 4px 11px;
  font-size: 13px; text-align: left;
}
.link-button:hover { color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 650; font-size: 16px; }
.bell { position: relative; color: var(--text-muted); font-size: 18px; }
.badge {
  background: var(--fail); color: #fff; border-radius: 10px; font-size: 11px;
  padding: 1px 6px; margin-left: 6px; font-weight: 600;
}
.content { padding: 24px; max-width: 1400px; width: 100%; }

/* --------------------------------------------------------------- карточки */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.metric .value { font-size: 26px; font-weight: 680; letter-spacing: -.5px; }
.metric .label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* --------------------------------------------------------------- таблицы */
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-weight: 600; color: var(--text-muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--mono); font-size: 13px; }

/* --------------------------------------------------------------- статусы */
.status {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted); white-space: nowrap;
}
.status.ok, .status-passed { background: var(--ok-soft); color: var(--ok); }
.status.fail, .status-failed { background: var(--fail-soft); color: var(--fail); }
.status.error { background: var(--fail-soft); color: var(--fail); }
.status.pending, .status-assigned { background: var(--accent-soft); color: var(--accent-dark); }
.status.warn, .status-submitted { background: var(--warn-soft); color: var(--warn); }

/* --------------------------------------------------------------- формы */
label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=datetime-local], input[type=file], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form-row { margin-bottom: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.help { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.errorlist { color: var(--fail); font-size: 13px; list-style: none; padding: 0; margin: 4px 0; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger { background: var(--fail); border-color: var(--fail); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* --------------------------------------------------------------- флеш */
.flash-stack { position: fixed; top: 14px; right: 18px; z-index: 100; display: grid; gap: 8px; max-width: 460px; }
.flash {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: 11px 14px; box-shadow: var(--shadow);
  display: flex; gap: 10px; align-items: flex-start; font-size: 14px;
}
.flash-success { border-left-color: var(--ok); }
.flash-warning { border-left-color: var(--warn); }
.flash-error { border-left-color: var(--fail); }
.flash-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* --------------------------------------------------------------- вход */
.login-page { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(1200px 600px at 20% -10%, #21365f 0%, #101728 55%, #0b111f 100%); }
.login-card { width: 380px; background: var(--surface); border-radius: 14px; padding: 30px; box-shadow: 0 20px 50px rgba(6, 12, 28, .4); }
.login-card h1 { font-size: 21px; margin-bottom: 4px; }
.login-card .sub { color: var(--text-muted); font-size: 13.5px; margin-bottom: 20px; }

/* --------------------------------------------------------------- конструктор */
.constructor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.notebook { display: grid; gap: 12px; }
.cell {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.cell.disabled { opacity: .6; }
.cell.running { border-color: var(--accent); }
.cell-head {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.cell-kind {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 8px; border-radius: 20px; background: var(--accent-soft); color: var(--accent-dark);
}
.cell-kind[data-kind="output"] { background: var(--ok-soft); color: var(--ok); }
.cell-kind[data-kind="markdown"] { background: #eee9fb; color: #6b45c9; }
.cell-kind[data-kind="dataset"] { background: #e3f3fb; color: #17708f; }
.cell-kind[data-kind="stat"] { background: var(--warn-soft); color: var(--warn); }
.cell-title { border: none; background: transparent; font-weight: 600; font-size: 14px; flex: 1; padding: 3px 4px; }
.cell-title:focus { outline: 1px solid var(--border); border-radius: 4px; }
.cell-actions { display: flex; gap: 4px; }
.icon-btn {
  border: 1px solid transparent; background: transparent; cursor: pointer; border-radius: 5px;
  width: 27px; height: 27px; display: grid; place-items: center; color: var(--text-muted); font-size: 14px;
}
.icon-btn:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.cell-body .CodeMirror { height: auto; font-family: var(--mono); font-size: 13px; line-height: 1.5; }
.cell-body .CodeMirror-scroll { min-height: 40px; }
.cell-output { border-top: 1px dashed var(--border); padding: 10px 12px; background: #fbfcfe; }
.cell-output pre {
  margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 12.5px;
  font-family: var(--mono); color: #33405a; max-height: 260px; overflow: auto;
}
.cell-output.error { background: var(--fail-soft); }
.cell-output.error pre { color: var(--fail); }
.cell-status { font-size: 12px; color: var(--text-muted); }

.palette { position: sticky; top: 74px; display: grid; gap: 12px; }
.palette .card { margin-bottom: 0; overflow-wrap: anywhere; word-break: break-word; }
.palette .card code { word-break: break-all; }
#answer-keys > div, #reference-report > div { padding: 2px 0; border-bottom: 1px solid var(--surface-2); }
.palette-group { margin-bottom: 10px; }
.palette-group > summary { cursor: pointer; font-weight: 600; font-size: 13.5px; padding: 5px 0; }
.palette-item {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px;
  margin: 6px 0; cursor: pointer; background: var(--surface);
}
.palette-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.palette-item .t { font-weight: 600; font-size: 13.5px; }
.palette-item .d { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 14px; position: sticky; top: 58px; z-index: 15; box-shadow: var(--shadow);
}

.preview-chart { width: 100%; height: 190px; display: block; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-family: var(--mono); }
.mini-table th, .mini-table td { border: 1px solid var(--border); padding: 3px 6px; text-align: right; }
.mini-table th { background: var(--surface-2); text-align: center; }

/* --------------------------------------------------------------- чат */
.chat-wrap { display: grid; grid-template-rows: 1fr auto; height: calc(100vh - 190px); min-height: 380px; }
.chat-messages { overflow-y: auto; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.msg { max-width: 72%; margin-bottom: 12px; }
.msg .bubble { padding: 9px 12px; border-radius: 12px; background: var(--surface-2); display: inline-block; }
.msg .meta { font-size: 11.5px; color: var(--text-muted); margin-bottom: 3px; }
.msg.own { margin-left: auto; text-align: right; }
.msg.own .bubble { background: var(--accent); color: #fff; }
.msg.system { max-width: 100%; text-align: center; }
.msg.system .bubble { background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.chat-form textarea { flex: 1; min-height: 46px; }

/* --------------------------------------------------------------- прочее */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 14px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; color: var(--text-muted); font-size: 14px; }
.tab.active { background: var(--surface); border: 1px solid var(--border); border-bottom-color: var(--surface); color: var(--text); font-weight: 600; margin-bottom: -1px; }
.logbox {
  background: #0f1626; color: #cbd5e5; border-radius: var(--radius); padding: 14px;
  font-family: var(--mono); font-size: 12.5px; max-height: 560px; overflow: auto; white-space: pre-wrap;
}
.progress { height: 7px; background: var(--surface-2); border-radius: 20px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); }
.tag { display: inline-block; font-size: 12px; background: var(--surface-2); border-radius: 5px; padding: 1px 7px; color: var(--text-muted); }
.empty { text-align: center; padding: 36px; color: var(--text-muted); }
details.spoiler > summary { cursor: pointer; color: var(--accent); font-size: 13.5px; }
.kbd { font-family: var(--mono); font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; }

@media (max-width: 1100px) {
  .constructor { grid-template-columns: 1fr; }
  .palette { position: static; }
}
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 14px; }
}
