:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --text: #17202a;
  --muted: #657282;
  --line: #d9dee7;
  --line-strong: #c8d0dc;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --sidebar: #111827;
  --sidebar-hover: #1f2937;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
  height: 100vh;
  background: var(--sidebar);
  color: #f9fafb;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 0;
}

.brand {
  display: grid;
  gap: 4px;
  padding-bottom: 14px;
  border-bottom: 1px solid #2b3546;
}

.home-button {
  width: 100%;
  display: block;
  text-align: left;
  color: #f9fafb;
  background: #0f172a;
  border: 1px solid #263244;
  border-radius: 6px;
  padding: 10px 11px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.home-button.active,
.home-button:hover,
.home-button:focus-visible {
  background: var(--sidebar-hover);
  border-color: #3b4658;
  outline: none;
}

.brand strong {
  font-size: 18px;
  font-weight: 700;
}

.brand span {
  color: #b8c0cc;
  font-size: 13px;
}

#groupNav {
  display: grid;
  gap: 14px;
  overflow: auto;
  padding-right: 2px;
}

.nav-section-title {
  margin-top: 6px;
  color: #d9dee7;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.nav-section-title:first-child {
  margin-top: 0;
}

.group {
  display: grid;
  gap: 6px;
}

.group h2 {
  margin: 0;
  color: #aab3c2;
  font-size: 12px;
  font-weight: 700;
}

.group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #f9fafb;
  background: #0f172a;
  border: 1px solid #263244;
  border-radius: 6px;
  padding: 10px 11px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.group-toggle::before {
  content: ">";
  color: #aab3c2;
  font-size: 12px;
  transition: transform 0.16s ease;
}

.group.is-expanded .group-toggle::before {
  transform: rotate(90deg);
}

.group-toggle span {
  flex: 1;
  text-align: left;
}

.group-toggle small {
  color: #aab3c2;
  font-size: 12px;
  font-weight: 700;
}

.group-toggle:hover,
.group-toggle:focus-visible {
  background: var(--sidebar-hover);
  border-color: #3b4658;
  outline: none;
}

.group-tools {
  display: grid;
  gap: 4px;
  padding-left: 10px;
  border-left: 1px solid #263244;
}

.group-tools[hidden] {
  display: none;
}

.tool-button,
.cyberchef-link {
  width: 100%;
  display: block;
  text-align: left;
  color: #f9fafb;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 10px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
}

.tool-button.active,
.tool-button:hover,
.tool-button:focus-visible,
.cyberchef-link:hover,
.cyberchef-link:focus-visible {
  background: var(--sidebar-hover);
  border-color: #374151;
  outline: none;
}

.cyberchef-link {
  margin-top: auto;
}

.tool-search {
  display: grid;
  gap: 7px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
}

.tool-search input {
  border-color: #374151;
  background: #0f172a;
  color: #f9fafb;
}

.tool-search input::placeholder {
  color: #8b95a5;
}

.workspace {
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  padding: 14px 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

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

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

#toolSubtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(420px, 0.68fr) minmax(680px, 1.32fr);
  gap: 14px;
  align-items: stretch;
  min-height: 0;
  height: 100%;
}

.tool-layout.home-layout {
  grid-template-columns: minmax(0, 1fr);
}

.tool-layout.home-layout .side-stack {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 0;
}

#toolForm {
  display: grid;
  gap: 10px;
  align-content: start;
  overflow: auto;
}

.module-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 2px;
}

.module-tab {
  min-height: 34px;
  border-color: var(--line-strong);
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}

.module-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.module-tab.active:hover,
.module-tab.active:focus-visible {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

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

.form-section h3 {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.3;
}

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

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

label.full-span {
  grid-column: 1 / -1;
}

label.is-hidden {
  display: none;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.16);
}

textarea {
  min-height: 96px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

button {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

button.primary {
  justify-self: start;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.form-actions {
  display: flex;
  justify-content: flex-start;
  padding-top: 2px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

button.secondary {
  background: #f8fafc;
  border-color: var(--line-strong);
  color: var(--text);
  font-weight: 600;
}

button.secondary:hover,
button.secondary:focus-visible {
  background: #eef6f5;
  border-color: var(--accent);
}

button.secondary.danger {
  color: var(--danger);
  border-color: #f3b8b2;
}

button.secondary.danger:hover,
button.secondary.danger:focus-visible {
  background: #fff7f6;
  border-color: var(--danger);
}

button.primary:hover,
button.primary:focus-visible {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.home-panel {
  overflow: auto;
  gap: 14px;
  background:
    linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.7fr);
  gap: 14px;
  align-items: stretch;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.home-hero-copy {
  display: grid;
  gap: 10px;
  align-content: center;
}

.home-title-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.home-kicker {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.home-version {
  color: #8a4b05;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
}

.home-hero h2 {
  margin: 0;
  max-width: 760px;
  font-size: 24px;
  line-height: 1.25;
}

.home-hero p {
  margin: 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.5;
}

.home-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.home-status-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.home-stat {
  display: grid;
  gap: 6px;
  min-height: 72px;
  align-content: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.home-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.home-stat strong {
  font-size: 15px;
}

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

.home-cards-featured {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.home-cards-compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.home-section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.home-section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.home-section-title h3 {
  margin: 0;
  font-size: 16px;
}

.home-section-title span {
  color: var(--muted);
  font-size: 13px;
}

.home-card {
  display: grid;
  gap: 7px;
  min-height: 124px;
  text-align: left;
  align-content: start;
  background: #ffffff;
  border-color: var(--line);
  padding: 13px;
}

.home-card:hover,
.home-card:focus-visible {
  background: #eef6f5;
  border-color: var(--accent);
}

.home-card-label {
  justify-self: start;
  color: var(--accent);
  background: #eef6f5;
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 800;
}

.home-card strong {
  font-size: 15px;
  line-height: 1.25;
}

.home-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.home-card .home-card-label {
  color: var(--accent);
  line-height: 1;
}

.home-cards-compact .home-card {
  min-height: 112px;
  padding: 12px;
}

.home-cards-compact .home-card strong {
  font-size: 14px;
}

.home-cards-compact .home-card span:not(.home-card-label) {
  font-size: 12px;
}

.home-footer {
  padding: 2px 4px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.certificate-workspace {
  display: grid;
  gap: 10px;
}

.certificate-workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.certificate-workspace-header h3 {
  margin: 0;
}

.certificate-node-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.certificate-workspace-grid {
  display: grid;
  grid-template-columns: minmax(210px, 0.32fr) minmax(360px, 1fr);
  gap: 12px;
  align-items: stretch;
}

.certificate-tree {
  min-height: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 5px;
}

.cert-node {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  border-color: transparent;
  background: transparent;
  padding: 7px 8px 7px calc(8px + var(--depth, 0) * 18px);
}

.cert-node:hover,
.cert-node:focus-visible {
  background: #eef6f5;
  border-color: #c7dfdc;
}

.cert-node.is-selected {
  background: #e8f4f2;
  border-color: var(--accent);
}

.cert-node-icon {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.cert-node-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.cert-node-state {
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  padding: 2px 7px;
  font-size: 12px;
  white-space: nowrap;
}

.cert-node.is-selected .cert-node-state {
  color: var(--accent-strong);
  border-color: #8cc9c2;
}

.certificate-node-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}

.certificate-node-editor textarea {
  min-height: 150px;
}

.certificate-upload-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.certificate-upload-row input[type="file"] {
  flex: 1 1 260px;
}

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

.result-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.side-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.guide-panel {
  display: grid;
  gap: 10px;
  max-height: 220px;
  overflow: hidden;
}

.usage-guide {
  display: grid;
  gap: 10px;
  overflow: hidden;
}

.guide-section {
  display: grid;
  gap: 8px;
}

.guide-section h3 {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.3;
}

.guide-section ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.guide-section li + li {
  margin-top: 4px;
}

.result-output {
  min-height: 0;
  max-height: none;
  margin: 0;
  overflow: auto;
  word-break: break-word;
}

.result-card {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 0;
}

.error-card {
  border-color: rgba(180, 35, 24, 0.36);
  background: #fff7f6;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.result-row:last-child {
  border-bottom: 0;
}

.result-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.result-value {
  min-width: 0;
  white-space: pre-wrap;
}

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

.result-list {
  margin: 0;
  padding-left: 18px;
}

.result-table-wrap {
  overflow: visible;
  padding: 0 12px 12px;
}

.result-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
}

.result-table th,
.result-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.result-table th {
  color: var(--muted);
  font-weight: 700;
  background: #f3f6f9;
}

.status-ok {
  color: var(--accent-strong);
  font-weight: 700;
}

.status-partial {
  color: #b45309;
  font-weight: 700;
}

.status-warn {
  color: var(--danger);
  font-weight: 700;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  border: 1px solid currentColor;
  padding: 3px 9px;
  background: #fff;
  white-space: nowrap;
}

.certificate-result-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.certificate-result-title h3,
.result-table-wrap h3 {
  margin: 0;
  font-size: 14px;
}

.cert-alert {
  margin: 12px;
  border-radius: 8px;
  padding: 12px;
  font-weight: 700;
}

.cert-alert-ok {
  border: 1px solid #86efac;
  background: #f0fdf4;
  color: #166534;
}

.cert-alert-bad {
  border: 1px solid #fecaca;
  background: #fff7f6;
  color: var(--danger);
}

.certificate-table col:nth-child(1) {
  width: 15%;
}

.certificate-table col:nth-child(2) {
  width: 34%;
}

.certificate-table col:nth-child(3) {
  width: 34%;
}

.certificate-table col:nth-child(4) {
  width: 17%;
}

.result-code,
.raw-json pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.result-code {
  padding: 0;
}

.copy-inline {
  padding: 5px 8px;
  font-size: 12px;
}

.raw-json {
  margin-top: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.raw-json summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.raw-json pre {
  margin-top: 10px;
  overflow: auto;
}

.empty-nav {
  color: #aab3c2;
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 2px;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.error {
  color: var(--danger);
}

@media (max-width: 1080px) {
  body {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .sidebar {
    height: auto;
    position: static;
  }

  #groupNav {
    max-height: 360px;
  }

  .cyberchef-link {
    margin-top: 0;
  }

  .workspace {
    height: auto;
    overflow: visible;
    padding: 18px;
  }

  .topbar,
  .result-header {
    align-items: stretch;
    flex-direction: column;
  }

  .tool-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .certificate-workspace-grid {
    grid-template-columns: 1fr;
  }

  .side-stack,
  .result-panel,
  .guide-panel {
    position: static;
  }

  .side-stack {
    height: auto;
  }

  #toolForm {
    overflow: visible;
  }

  .home-hero {
    grid-template-columns: 1fr;
  }

  .home-cards-featured,
  .home-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .home-cards-compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  h1 {
    font-size: 22px;
  }

  .result-output {
    max-height: none;
  }

  .result-row {
    grid-template-columns: 1fr;
  }

  .copy-inline {
    justify-self: start;
  }
}

@media (max-width: 640px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

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

  .home-hero {
    padding: 14px;
  }

  .home-hero h2 {
    font-size: 20px;
  }

  .home-status-panel,
  .home-cards-featured,
  .home-cards-compact,
  .home-cards {
    grid-template-columns: 1fr;
  }

  .certificate-workspace-header {
    align-items: stretch;
    flex-direction: column;
  }

  .certificate-node-actions {
    justify-content: flex-start;
  }
}
