:root {
  --navy: #0a2540;
  --navy-2: #122c52;
  --blue: #1d6cf3;
  --blue-2: #4a8df6;
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #0f1b2d;
  --muted: #5b6a82;
  --line: #e3e8f0;
  --green: #1a9d5c;
  --amber: #c98300;
  --red: #c0392b;
  --shadow: 0 1px 3px rgba(10, 37, 64, 0.06), 0 4px 12px rgba(10, 37, 64, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.topbar {
  background: var(--navy);
  color: #fff;
  padding: 0.75rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-mark {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 1rem;
}

.brand-sub {
  margin-left: 0.75rem;
  color: #b6c4dc;
  font-size: 0.85rem;
}

.badge {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1600px;
  margin: 0 auto;
}

@media (min-width: 1024px) {
  .layout {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.col {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--shadow);
  min-height: 200px;
}

.col h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.5rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.row.right {
  justify-content: flex-end;
}

.row label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--muted);
  flex: 1;
  min-width: 120px;
  gap: 0.25rem;
}

.row label.grow {
  flex: 2;
}
.row label.grow-2 {
  flex: 3;
}

.row label.check {
  flex: 0 0 auto;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  color: var(--text);
  font-size: 0.85rem;
}

input[type="text"],
select,
textarea {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  outline: none;
}

input[type="text"]:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 108, 243, 0.15);
}

textarea {
  width: 100%;
  height: 320px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  resize: vertical;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover {
  background: var(--blue-2);
}
.btn-primary:disabled {
  background: #b9c8e2;
  cursor: not-allowed;
}

.btn-secondary {
  background: #eef2f9;
  color: var(--navy);
}
.btn-secondary:hover {
  background: #e0e8f5;
}

.btn-link {
  background: var(--navy);
  color: #fff;
  align-self: flex-start;
  margin-top: 0.5rem;
}

.steps {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  counter-reset: step;
}
.steps li {
  position: relative;
  padding: 0.5rem 0.5rem 0.5rem 2rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  counter-increment: step;
  background: #fafbfd;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.step-label { flex: 0 0 auto; }
.step-status {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.step-status.info { color: var(--blue); }
.step-status.ok { color: var(--green); }
.step-status.err { color: var(--red); }
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: var(--line);
  color: var(--muted);
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.steps li.active {
  background: rgba(29, 108, 243, 0.06);
  border-color: var(--blue);
  color: var(--text);
}
.steps li.active::before {
  background: var(--blue);
  color: #fff;
}
.steps li.done {
  border-color: var(--green);
  color: var(--text);
}
.steps li.done::before {
  background: var(--green);
  color: #fff;
  content: "✓";
}
.steps li.failed {
  border-color: var(--red);
  color: var(--red);
}

.steps li.active::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 0.5rem;
  border: 2px solid var(--blue);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.status-log {
  background: #0f1b2d;
  color: #cfe1ff;
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  margin: 0.6rem 0 0.75rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.status-log:empty {
  display: none;
}

.status-log .ts {
  color: #7ea0d4;
  margin-right: 0.4rem;
}

.status-log .ok { color: #6fdd9c; }
.status-log .err { color: #ff8a80; }
.status-log .info { color: #cfe1ff; }
.status-log .warn { color: #ffcf7a; }

.meta {
  background: #fafbfd;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.json-block {
  margin-bottom: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  background: #fafbfd;
}
.json-block summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--navy);
}
.json-block pre {
  overflow: auto;
  max-height: 280px;
  background: #0e1726;
  color: #e6edf7;
  padding: 0.6rem;
  border-radius: 4px;
  font-size: 11.5px;
  margin-top: 0.5rem;
}

.score-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  text-align: center;
  background: linear-gradient(180deg, #fff 0%, #f3f7ff 100%);
}
.score-grade {
  font-size: 3rem;
  font-weight: 700;
  color: var(--blue);
  line-height: 1;
}
.score-grade.A {
  color: var(--green);
}
.score-grade.B {
  color: var(--blue);
}
.score-grade.C {
  color: var(--amber);
}
.score-grade.D,
.score-grade.F {
  color: var(--red);
}
.score-num {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
}
.score-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 0.7rem;
}
.score-rationale {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--text);
  text-align: left;
}

.quote-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.quote-card h3 {
  margin-top: 0;
  color: var(--navy);
}
.quote-card .muted {
  color: var(--muted);
  font-size: 0.85rem;
}
.quote-card table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.85rem;
}
.quote-card th,
.quote-card td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
}
.quote-card th {
  background: #fafbfd;
  font-weight: 600;
}
.quote-total {
  font-size: 1.1rem;
  text-align: right;
}
.quote-total strong {
  color: var(--navy);
}

.ghl-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  background: #fafbfd;
  display: flex;
  flex-direction: column;
}

.error {
  border: 1px solid var(--red);
  background: #fdecea;
  color: var(--red);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}


.app-footer {
  margin-top: 2rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #2a3344;
  text-align: center;
  color: #6b7689;
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
}


/* History panel */
.history-panel {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}
.history-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.history-header h3 { margin: 0; font-size: 0.95rem; }
.history-meta {
  color: var(--muted);
  font-size: 0.8rem;
  flex: 1;
}
#history-refresh {
  padding: 0 0.5rem;
  font-size: 1rem;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
}
.history-empty {
  padding: 0.75rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
}
.history-item {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.1s;
}
.history-item:last-child { border-bottom: 0; }
.history-item:hover { background: var(--bg); }
.history-item.selected {
  background: rgba(29, 108, 243, 0.08);
  border-left: 3px solid var(--blue);
  padding-left: calc(0.75rem - 3px);
}
.hi-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.15rem;
}
.hi-grade {
  display: inline-block;
  width: 1.4rem;
  height: 1.4rem;
  line-height: 1.4rem;
  text-align: center;
  font-weight: 700;
  border-radius: 4px;
  background: var(--muted);
  color: white;
  font-size: 0.8rem;
  flex: 0 0 auto;
}
.hi-grade-A { background: var(--green); }
.hi-grade-B { background: var(--blue); }
.hi-grade-C { background: var(--amber); }
.hi-grade-D, .hi-grade-F { background: var(--red); }
.hi-title {
  flex: 1;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.85rem;
}
.hi-score {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}
.hi-bot {
  display: flex;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Mobile: history panel adapts */
@media (max-width: 768px) {
  .history-list { max-height: 200px; }
  .hi-bot { flex-wrap: wrap; gap: 0.5rem; }
}
