:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #16191d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --brand: #1f6feb;
  --brand-dark: #1a5cc4;
  --ok-bg: #e7f6ec;
  --ok-ink: #1b6b3a;
  --err-bg: #fdecec;
  --err-ink: #a32020;
  --warn-bg: #fff6e5;
  --warn-ink: #8a5a00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

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

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

/* ---------------------------------------------------------------- шапка */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 28px; height: 60px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .5px;
}
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.nav a.active { background: #eaf1fe; color: var(--brand); }
.user-box { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 550; }

/* ------------------------------------------------------------- страница */
.page { max-width: 1180px; margin: 0 auto; padding: 26px 28px 60px; }
.head-row { display: flex; align-items: flex-start; gap: 24px; margin-bottom: 20px; }
.head-row > div:first-child { flex: 1; }
.head-actions { display: flex; gap: 10px; align-items: center; }
h1 { font-size: 25px; margin: 0 0 4px; letter-spacing: -.2px; }
h2 { font-size: 17px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 20px 0 10px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.crumbs { color: var(--muted); font-size: 13px; margin: 0 0 6px; }
.nowrap { white-space: nowrap; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; }
.empty {
  padding: 28px; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}

/* ------------------------------------------------------------- сообщения */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; }
.alert-ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert-err { background: var(--err-bg); color: var(--err-ink); }
.alert-warn { background: var(--warn-bg); color: var(--warn-ink); }
.alert ul { margin: 8px 0 0; padding-left: 20px; }
.token { display: block; margin-top: 8px; padding: 10px; background: #fff; border-radius: 8px; word-break: break-all; }

/* -------------------------------------------------------------- элементы */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 550;
  cursor: pointer; transition: background .12s, border-color .12s;
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 7px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.danger { color: #b02a2a; }
.link { font-weight: 550; }

label { display: block; font-size: 13px; color: var(--muted); font-weight: 550; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
  font: inherit; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 111, 235, .12);
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; resize: vertical; }
input[type=file] { padding: 6px; background: var(--bg); }
input[type=checkbox] { display: inline-block; width: auto; margin: 0 8px 0 0; }
.check { display: flex; align-items: center; color: var(--ink); font-weight: 500; align-self: end; padding-bottom: 9px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack > button { align-self: flex-start; }
.row-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row-form .grow { flex: 1; min-width: 180px; }
.upload-form { display: flex; gap: 8px; align-items: center; }
.upload-form input[type=file] { width: 220px; margin: 0; }

fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px 18px; margin: 0; }
legend { padding: 0 8px; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.fields.wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); margin-top: 14px; }
details { margin-top: 14px; }
summary { cursor: pointer; color: var(--brand); font-size: 13px; font-weight: 550; }

/* --------------------------------------------------------------- таблицы */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.row-bad td { background: var(--err-bg); }

/* ---------------------------------------------------------------- бейджи */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted);
}
.badge-success, .badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-failed, .badge-cancelled { background: var(--err-bg); color: var(--err-ink); }
.badge-running { background: #e6f0ff; color: var(--brand); }
.badge-queued { background: var(--warn-bg); color: var(--warn-ink); }
.badge-role { background: #eef0f3; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip { padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 550; }
.chip-ok { background: var(--ok-bg); color: var(--ok-ink); }
.chip-off { background: var(--bg); color: #9aa1ab; }

/* -------------------------------------------------------------- проекты */
.project-card { display: flex; flex-direction: column; gap: 4px; }
.project-card h3 { margin: 0; font-size: 16px; }
.project-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: auto; padding-top: 10px; }
.project-card form { margin-top: 10px; }

/* --------------------------------------------------------------- расчёт */
.status-line { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.progress { height: 8px; background: var(--bg); border-radius: 20px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--brand); border-radius: 20px; transition: width .4s ease; }
.log {
  margin: 14px 0 0; padding: 14px; max-height: 280px; overflow: auto;
  background: #12161c; color: #cfd6e0; border-radius: 10px;
  font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap;
}
.log:empty { display: none; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.metric {
  display: flex; flex-direction: column; gap: 2px; padding: 14px;
  background: var(--bg); border-radius: 10px;
}
.metric-value { font-size: 21px; font-weight: 650; letter-spacing: -.3px; }
.metric-label { font-size: 12px; color: var(--muted); }
.issues { margin: 0; padding-left: 20px; color: var(--err-ink); font-size: 14px; }
.issues li { margin-bottom: 4px; }

/* ------------------------------------------------------------------ вход */
.auth-wrap {
  display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 40px;
  align-items: start; margin-top: 40px;
}
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 30px; box-shadow: var(--shadow); }
.auth-card h1 { margin-bottom: 8px; }
.auth-card .stack { margin-top: 22px; }
.auth-card .btn { width: 100%; }
.auth-side { padding-top: 20px; }
.auth-side h2 { font-size: 19px; }
.ticks { list-style: none; padding: 0; margin: 0; }
.ticks li { position: relative; padding-left: 26px; margin-bottom: 12px; color: var(--muted); }
.ticks li::before {
  content: "✓"; position: absolute; left: 0; top: 0;
  color: var(--ok-ink); font-weight: 700;
}

/* -------------------------------------------------------------- шахматка */
.chess td, .chess th { padding: 4px 6px; vertical-align: top; }
.chess-cell { min-width: 178px; }
.hidden-form { display: none; }
.lesson {
  position: relative; padding: 7px 26px 7px 9px; border-radius: 9px;
  background: var(--bg); border: 1px solid var(--line); cursor: pointer;
  display: flex; flex-direction: column; gap: 1px; transition: box-shadow .12s, border-color .12s;
}
.lesson:hover { border-color: var(--brand); }
.lesson.is-selected { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,111,235,.18); }
.lesson.is-potok { background: #fff3d6; }
.lesson.is-remote { background: var(--ok-bg); }
.lesson.is-pinned { border-style: dashed; cursor: default; }
.lesson-subj { font-size: 12.5px; font-weight: 550; line-height: 1.3; }
.lesson-meta { font-size: 11.5px; color: var(--muted); }
.lesson-tag {
  font-size: 10.5px; color: var(--muted); background: #fff;
  border-radius: 5px; padding: 1px 5px; align-self: flex-start;
}
.pin {
  position: absolute; top: 4px; right: 4px; border: none; background: transparent;
  cursor: pointer; font-size: 13px; line-height: 1; padding: 2px; border-radius: 5px;
}
.pin:hover { background: #fff; }

.foot { padding: 22px 28px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; gap: 12px; }
  .brand-text { display: none; }
  .page { padding: 18px 16px 40px; }
  .head-row { flex-direction: column; }
}
