:root {
  --bg: #f4f5f7;
  --white: #fff;
  --muted-bg: #fafbfc;
  --line: #e4e7ec;
  --line-dark: #d0d5dd;
  --ink: #101828;
  --ink-2: #667085;
  --ink-3: #98a2b3;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-light: #eff4ff;
  --green: #12b76a;
  --amber: #f79009;
  --red: #f04438;
  --r: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden { display: none !important; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.header-brand { display: flex; align-items: center; gap: 14px; }

.logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  display: grid;
  place-items: center;
}

.header h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header p {
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 1px;
}

.btn-run {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--blue);
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-run:hover { background: var(--blue-dark); }
.btn-run:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Layout ── */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 0;
}

.main {
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

/* ── Cards ── */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.card-top h2 {
  font-size: 14px;
  font-weight: 600;
}

.badge {
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.btn-outline {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--white);
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-outline:hover { border-color: var(--blue); color: var(--blue); }

/* ── Input box (textarea + actions inside) ── */
.input-box {
  margin: 0;
  border-bottom: 1px solid var(--line);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-box.drag-over {
  box-shadow: inset 0 0 0 2px var(--blue);
}

.input-box textarea {
  display: block;
  width: 100%;
  min-height: 240px;
  padding: 16px 18px 8px;
  border: none;
  resize: vertical;
  font: inherit;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
  background: transparent;
}

.input-box textarea:focus { outline: none; }
.input-box textarea::placeholder { color: var(--ink-3); }

.input-box-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 12px;
  background: var(--muted-bg);
  border-top: 1px solid var(--line);
}

.btn-text {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--blue);
  background: none;
  border: none;
  padding: 4px 6px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.12s;
}

.btn-text:hover { background: var(--blue-light); }
.btn-text:disabled { opacity: 0.5; cursor: not-allowed; }

.bar-sep { color: var(--ink-3); font-size: 13px; }
.bar-hint { margin-left: auto; font-size: 12px; color: var(--ink-3); }

/* ── Options row ── */
.options {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 16px;
  padding: 14px 18px;
}

.opt {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 130px;
}

.opt-wide { flex: 1; min-width: 200px; }

.opt span {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.opt select,
.opt input {
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  background: var(--white);
  color: var(--ink);
}

.opt select:focus,
.opt input[type="text"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-light);
}

.opt-check {
  flex: 1 1 100%;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  min-width: 100%;
  padding: 10px 12px;
  margin-top: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--muted-bg);
  cursor: pointer;
}

.opt-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--blue);
  cursor: pointer;
  flex-shrink: 0;
}

.check-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-transform: none;
  letter-spacing: normal;
}

.check-text strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.check-text small {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-2);
  line-height: 1.4;
}

/* ── Output ── */
.output {
  padding: 16px 18px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  max-height: 460px;
  overflow-y: auto;
}

.notice {
  margin: 14px 18px 0;
  padding: 10px 14px;
  background: #fffaeb;
  border: 1px solid #fec84b;
  border-radius: 6px;
  font-size: 13px;
  color: #b54708;
}

.notice div + div { margin-top: 4px; }

/* ── Sidebar ── */
.aside {
  background: var(--white);
  border-left: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.kpi {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--muted-bg);
}

.kpi-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-val {
  display: block;
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-top: 2px;
}

.kpi-val.excellent, .kpi-val.good { color: var(--green); }
.kpi-val.fair { color: var(--amber); }
.kpi-val.poor { color: var(--red); }
.kpi-val.kpi-blue { color: var(--blue); }

.kpi-sub {
  display: block;
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 2px;
}

.aside-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.aside-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

.pct { font-size: 12px; color: var(--blue); font-variant-numeric: tabular-nums; }

.bar-track {
  height: 4px;
  background: var(--line);
  margin: 6px 12px 12px;
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.aside-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px 4px;
}

#metricsGrid { padding: 2px 12px 12px; }

.m-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}

.m-row:last-child { border-bottom: none; }
.m-row .lbl { color: var(--ink-2); }
.m-row .vals { font-variant-numeric: tabular-nums; }
.m-row .old { color: var(--ink-3); font-size: 12px; }
.m-row .new { font-weight: 600; }
.m-row .arr { color: var(--ink-3); margin: 0 4px; font-size: 11px; }
.m-row.up .new { color: var(--green); }
.m-row.down .new { color: var(--red); }

.aside-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  background: none;
  border: none;
  cursor: pointer;
}

.aside-toggle:hover { background: var(--muted-bg); color: var(--ink); }
.aside-toggle[aria-expanded="true"] .arr { transform: rotate(90deg); display: inline-block; }

.aside-body {
  padding: 0 12px 12px;
  border-top: 1px solid var(--line);
}

.aside-note {
  font-size: 12px;
  color: var(--ink-2);
  padding: 10px 0;
  line-height: 1.5;
}

.d-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 4px 0;
  color: var(--ink-2);
}

.d-row span:last-child { font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(16, 24, 40, 0.12);
  z-index: 100;
  max-width: 90vw;
}

.toast.ok { background: var(--ink); color: #fff; }
.toast.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .aside { border-left: none; border-top: 1px solid var(--line); }
}

@media (max-width: 560px) {
  .header, .main { padding-left: 16px; padding-right: 16px; }
  .bar-hint { display: none; }
  .opt { min-width: calc(50% - 10px); }
  .opt-wide { min-width: 100%; }
}
