:root {
  --bg: #071018;
  --bg-soft: #0b1520;
  --panel: #101b27;
  --panel-strong: #152332;
  --panel-soft: #0d1823;
  --border: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.36);
  --text: #e8eef7;
  --muted: #91a4ba;
  --muted-2: #64758a;
  --blue: #58a6ff;
  --cyan: #4fd1c5;
  --green: #45d483;
  --yellow: #f2bd5a;
  --red: #ff6464;
  --violet: #a78bfa;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  --font: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(17, 29, 42, 0.92), var(--bg) 310px),
    var(--bg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

a { color: inherit; text-decoration: none; }

button, input, select, textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 24px;
  background: rgba(7, 16, 24, 0.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(88, 166, 255, 0.54);
  border-radius: 8px;
  background: linear-gradient(135deg, #1e3a5f, #152332 58%, #143a35);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.brand-title {
  margin: 0;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0;
}

.brand-subtitle {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 7px;
}

.nav a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.nav a.active {
  color: #f8fbff;
  background: rgba(88, 166, 255, 0.14);
  border-color: rgba(88, 166, 255, 0.36);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 220px;
}

.page {
  width: min(1540px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.page-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-title h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 780;
  letter-spacing: 0;
}

.page-title p {
  max-width: 760px;
  margin: 5px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.layout-main { grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.85fr); align-items: start; }
.layout-side { grid-template-columns: minmax(340px, 0.75fr) minmax(0, 1.25fr); align-items: start; }

.panel {
  background: linear-gradient(180deg, rgba(21, 35, 50, 0.96), rgba(13, 24, 35, 0.96));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel.pad { padding: 16px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 760;
  letter-spacing: 0;
}

.panel-header .hint {
  color: var(--muted);
  font-size: 12px;
}

.section {
  padding: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.transition-status-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.metric {
  min-height: 92px;
  padding: 13px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.metric.compact {
  min-height: 72px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 8px;
  font-size: 26px;
  font-weight: 780;
  line-height: 1;
}

.metric-value.small {
  font-size: 18px;
  line-height: 1.2;
}

.metric-note {
  margin-top: 7px;
  color: var(--muted-2);
  font-size: 12px;
}

.btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}

.btn:hover { border-color: var(--border-strong); background: rgba(255, 255, 255, 0.08); }
.btn.primary { background: linear-gradient(180deg, #2879d8, #1f62b7); border-color: rgba(111, 180, 255, 0.62); color: white; }
.btn.success { background: linear-gradient(180deg, #23985d, #167246); border-color: rgba(69, 212, 131, 0.54); color: white; }
.btn.warning { background: rgba(242, 189, 90, 0.14); border-color: rgba(242, 189, 90, 0.42); color: #ffe2a3; }
.btn.danger { background: rgba(255, 100, 100, 0.15); border-color: rgba(255, 100, 100, 0.46); color: #ffd0d0; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.48; cursor: not-allowed; }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 5px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted-2);
  box-shadow: 0 0 0 3px rgba(100, 117, 138, 0.16);
}

.status-dot.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(69, 212, 131, 0.16); }
.status-dot.warn { background: var(--yellow); box-shadow: 0 0 0 3px rgba(242, 189, 90, 0.16); }
.status-dot.bad { background: var(--red); box-shadow: 0 0 0 3px rgba(255, 100, 100, 0.16); }
.status-dot.blue { background: var(--blue); box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.16); }

.timeline {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}

.phase-step {
  min-height: 58px;
  padding: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
}

.phase-step.active {
  color: #f8fbff;
  background: rgba(88, 166, 255, 0.15);
  border-color: rgba(88, 166, 255, 0.46);
}

.phase-step.done {
  color: #d6ffe8;
  border-color: rgba(69, 212, 131, 0.36);
}

.chart-box {
  height: 330px;
  position: relative;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

input, select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: rgba(7, 16, 24, 0.72);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(88, 166, 255, 0.64);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.14);
}

input[type="range"] {
  padding: 0;
  min-height: 28px;
  accent-color: var(--blue);
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--blue);
}

.table-wrap { overflow: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.log-box {
  min-height: 360px;
  max-height: 540px;
  overflow: auto;
  padding: 14px;
  color: #d6e2f0;
  background: #061018;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.alert-list {
  display: grid;
  gap: 8px;
}

.alert-item {
  padding: 10px;
  color: #ffe2a3;
  background: rgba(242, 189, 90, 0.12);
  border: 1px solid rgba(242, 189, 90, 0.28);
  border-radius: 7px;
}

.muted { color: var(--muted); }
.ok { color: var(--green); }
.warn { color: var(--yellow); }
.bad { color: var(--red); }
.blue { color: var(--blue); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
}

.modal-backdrop.show { display: flex; }

.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 70;
  display: none;
  max-width: 420px;
  padding: 11px 14px;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toast.show { display: block; }

@media (max-width: 1120px) {
  .layout-main, .layout-side, .grid.cols-2, .grid.cols-3, .grid.cols-4 {
    grid-template-columns: 1fr;
  }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .transition-status-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .timeline { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions, .brand { min-width: 0; }
}

@media (max-width: 620px) {
  .page { width: min(100vw - 20px, 1540px); padding-top: 14px; }
  .topbar { padding: 12px; }
  .metric-grid, .form-grid { grid-template-columns: 1fr; }
  .transition-status-grid { grid-template-columns: 1fr; }
  .timeline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-title { align-items: flex-start; flex-direction: column; }
  .page-title h1 { font-size: 24px; }
  .chart-box { height: 260px; }
}
