:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-soft: #f0f3f5;
  --line: #d8dee4;
  --line-strong: #b8c1ca;
  --text: #1c232b;
  --muted: #66717d;
  --blue: #275d89;
  --blue-dark: #1d4b72;
  --green: #20735a;
  --amber: #9b6a15;
  --red: #a83a32;
  --shadow: 0 10px 30px rgba(22, 33, 44, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

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

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #222a33;
  color: #eef2f5;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #2f3a45;
  border-radius: 8px;
  font-weight: 700;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
}

.brand-subtitle {
  margin-top: 2px;
  color: #aeb8c2;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  width: 100%;
  height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #cbd3da;
  text-align: left;
  padding: 0 12px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.is-active {
  background: #303b46;
  color: #ffffff;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 15px;
}

.muted {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.view {
  display: none;
  min-width: 0;
}

.view.is-active {
  display: grid;
  gap: 16px;
}

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

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.metric {
  min-height: 86px;
  padding: 16px;
  display: grid;
  align-content: center;
  gap: 6px;
}

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

.metric strong {
  font-size: 23px;
  line-height: 1.1;
}

.panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.split {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.template-upload-panel {
  display: grid;
  gap: 12px;
}

.template-upload-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(160px, 0.8fr) minmax(110px, 0.45fr) minmax(220px, 1.2fr);
  gap: 12px;
  align-items: end;
}

.template-upload-action {
  display: flex;
  grid-column: 1 / -1;
  align-items: end;
  justify-content: flex-end;
}

.template-workbench {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.template-library {
  display: grid;
  gap: 12px;
  align-content: start;
}

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

.template-list {
  display: grid;
  gap: 8px;
  max-height: 680px;
  overflow: auto;
  padding-right: 2px;
}

.template-card {
  width: 100%;
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 11px;
  text-align: left;
  cursor: pointer;
}

.template-card:hover,
.template-card.is-active {
  border-color: var(--blue);
  background: #f7fafc;
}

.template-card-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.template-card-top strong {
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.template-card-meta,
.template-card-date,
.template-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.template-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
}

.template-editor {
  display: grid;
  gap: 12px;
}

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

.template-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-width: 0;
}

.template-summary dt {
  color: var(--muted);
  font-size: 12px;
}

.template-summary dd {
  margin: 4px 0 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.template-meta-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.55fr);
  gap: 12px;
}

.template-editor textarea[name="content_json"] {
  min-height: 420px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}

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

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

.json-status.ok {
  color: var(--green);
}

.json-status.bad {
  color: var(--red);
}

.form-grid {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

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

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.checkbox input {
  width: 16px;
  height: 16px;
  padding: 0;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(39, 93, 137, 0.16);
}

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

.button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 0 13px;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  background: var(--surface-soft);
}

.button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.button:disabled:hover {
  background: #ffffff;
}

.button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--blue-dark);
}

.button.primary:disabled,
.button.primary:disabled:hover {
  background: var(--blue);
}

.button.ghost {
  background: transparent;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

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

th {
  background: #f3f5f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

td {
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

#findings-table td:nth-child(1) {
  min-width: 120px;
  width: 11%;
}

#findings-table td:nth-child(2) {
  min-width: 130px;
  width: 10%;
}

#findings-table td:nth-child(3),
#findings-table td:nth-child(4),
#findings-table td:nth-child(5),
#findings-table td:nth-child(6) {
  min-width: 220px;
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}

.status.ok {
  border-color: rgba(32, 115, 90, 0.28);
  background: rgba(32, 115, 90, 0.1);
  color: var(--green);
}

.status.warn {
  border-color: rgba(155, 106, 21, 0.28);
  background: rgba(155, 106, 21, 0.1);
  color: var(--amber);
}

.status.bad {
  border-color: rgba(168, 58, 50, 0.28);
  background: rgba(168, 58, 50, 0.1);
  color: var(--red);
}

.details {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px 12px;
  margin: 0;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 7px;
}

.list-title {
  font-weight: 700;
}

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

.list-content {
  color: #34404b;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  min-height: 42px;
  display: none;
  align-items: center;
  border-radius: 8px;
  background: #202830;
  color: #ffffff;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.toast.is-visible {
  display: flex;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 14px;
    gap: 12px;
  }

  .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
    padding: 0 6px;
  }

  .workspace {
    padding: 16px;
  }

  .metric-grid,
  .split,
  .template-upload-grid,
  .template-workbench,
  .template-meta-grid {
    grid-template-columns: 1fr;
  }

  .template-list {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    display: grid;
  }

  .metric-grid {
    gap: 8px;
  }

  .details {
    grid-template-columns: 1fr;
  }

  .template-summary {
    grid-template-columns: 1fr;
  }

  .nav {
    overflow-x: auto;
    grid-template-columns: repeat(5, max-content);
  }

  table {
    min-width: 0;
  }

  th,
  td {
    padding: 9px 8px;
    overflow-wrap: anywhere;
  }
}
