:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0b5cff;
  --primary-hover: #0848c9;
  --danger: #b42318;
  --success: #067647;
  --warning: #b54708;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-nav a {
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 12px;
  transition: 0.2s ease;
}

.side-nav a.active,
.side-nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.side-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
}

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

.header h2 {
  margin: 0;
  font-size: 28px;
}

.header p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 19px;
}

.card h4 {
  margin: 0;
  font-size: 16px;
}

.lead {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(11, 92, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(11, 92, 255, 0.08);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

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

.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 11px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease;
}

.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #eef2ff;
  color: #1e3a8a;
}

.btn-secondary:hover {
  background: #e0e7ff;
}

.btn-light {
  background: #f1f5f9;
  color: #334155;
}

.btn-light:hover {
  background: #e2e8f0;
}

.btn-danger-soft {
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

.btn-danger-soft:hover {
  background: rgba(180, 35, 24, 0.14);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.btn-block {
  width: 100%;
}

.btn-small {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
}

.message {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #f8fafc;
  line-height: 1.55;
}

.message.hidden {
  display: none;
}

.message.success {
  color: var(--success);
  background: rgba(6, 118, 71, 0.07);
  border-color: rgba(6, 118, 71, 0.16);
}

.message.warning {
  color: var(--warning);
  background: rgba(181, 71, 8, 0.07);
  border-color: rgba(181, 71, 8, 0.16);
}

.message.error {
  color: var(--danger);
  background: rgba(180, 35, 24, 0.07);
  border-color: rgba(180, 35, 24, 0.16);
}

.stat {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.stat .k {
  font-size: 12px;
  color: var(--muted);
}

.stat .v {
  margin-top: 8px;
  font-size: 20px;
  font-weight: 700;
  word-break: break-word;
}

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

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.history-empty {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 18px;
  color: var(--muted);
  background: #fff;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  transition: 0.2s ease;
}

.history-item.active {
  border-color: rgba(11, 92, 255, 0.4);
  box-shadow: 0 0 0 4px rgba(11, 92, 255, 0.08);
}

.history-main {
  padding: 16px;
}

.history-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.history-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
}

.history-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.history-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.history-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.history-badge.neutral {
  background: #eef2ff;
  color: #3730a3;
}

.history-badge.success {
  background: rgba(6, 118, 71, 0.1);
  color: var(--success);
}

.history-badge.danger {
  background: rgba(180, 35, 24, 0.1);
  color: var(--danger);
}

.history-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.history-meta-box {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}

.history-meta-k {
  font-size: 12px;
  color: var(--muted);
}

.history-meta-v {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  word-break: break-word;
}

.history-footer {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.suggestion-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.suggestion-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.suggestion-meta {
  margin-top: 6px;
}

.suggestion-desc {
  margin-top: 8px;
  line-height: 1.65;
}

.suggestion-reason {
  margin-top: 8px;
}

.json-box {
  background: #0f172a;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 16px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.draft-preview {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-section {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: #fff;
}

.preview-section h4 {
  margin: 0 0 12px;
  font-size: 16px;
}

.preview-title {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.35;
  margin: 0 0 10px;
  color: var(--text);
}

.preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.preview-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: #1e3a8a;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.preview-chip.critical {
  background: rgba(180, 35, 24, 0.1);
  color: var(--danger);
}

.preview-chip.high {
  background: rgba(181, 71, 8, 0.1);
  color: var(--warning);
}

.preview-chip.medium {
  background: rgba(11, 92, 255, 0.1);
  color: var(--primary);
}

.preview-chip.low {
  background: rgba(6, 118, 71, 0.1);
  color: var(--success);
}

.preview-text {
  color: var(--text);
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-list {
  margin: 0;
  padding-left: 18px;
  line-height: 1.72;
}

.preview-list li + li {
  margin-top: 8px;
}

.preview-sub-block + .preview-sub-block {
  margin-top: 14px;
}

.preview-sub-title {
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 8px;
}

.preview-priority {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #f8fafc;
}

.preview-priority + .preview-priority {
  margin-top: 12px;
}

.preview-priority-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.preview-priority-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.45;
}

.preview-evidence {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.65;
}

.preview-evidence li + li {
  margin-top: 6px;
}

.preview-empty {
  color: var(--muted);
  font-style: italic;
}

.raw-json-wrap {
  margin-top: 14px;
}

.raw-json-wrap summary {
  cursor: pointer;
  font-weight: 700;
  color: #334155;
  user-select: none;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .app {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 18px;
  }

  .grid-2,
  .grid-4,
  .history-meta-grid {
    grid-template-columns: 1fr;
  }

  .preview-priority-top,
  .history-top,
  .history-footer,
  .section-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .row {
    flex-direction: column;
  }

  .row .btn,
  .history-actions .btn {
    width: 100%;
  }

  .history-actions {
    width: 100%;
  }
}