/* GD64 — calm theme. Dark by default, follows the system light setting. */
:root {
  --bg: #15171c;
  --surface: #1c1f26;
  --surface-2: #20242c;
  --inset: #181a20;
  --line: #2a2e37;
  --line-soft: #242830;
  --text: #e4e6eb;
  --muted: #9aa0ab;
  --dim: #6b717c;
  --accent: #7c9cd6;
  --accent-soft: rgba(124, 156, 214, 0.14);
  --accent-text: #a9c0ea;
  --ok: #8fc7a3;
  --warn: #d9b577;
  --bad: #e09a9a;
  --violet: #b8a3dd;
  --teal: #86c2c4;
  --code-key: #9dbbe6;
  --code-str: #a8d1b3;
  --code-num: #e2b392;
  --code-bool: #d9c07f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 6px 20px -8px rgba(0, 0, 0, 0.35);
  --radius: 10px;
  --radius-sm: 6px;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --window-height: 540px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f8f9fa;
    --inset: #fbfbfc;
    --line: #e1e4e8;
    --line-soft: #eceef1;
    --text: #25282e;
    --muted: #5e6470;
    --dim: #8b919b;
    --accent: #4f73b8;
    --accent-soft: rgba(79, 115, 184, 0.1);
    --accent-text: #3c5f9e;
    --ok: #3d8a5c;
    --warn: #9a7327;
    --bad: #b85353;
    --violet: #7657b0;
    --teal: #2f7d80;
    --code-key: #3c5f9e;
    --code-str: #3d7a4f;
    --code-num: #a55a2a;
    --code-bool: #8a6a12;
    --shadow: 0 1px 2px rgba(20, 30, 50, 0.05), 0 6px 18px -10px rgba(20, 30, 50, 0.15);
  }
}

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

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-soft); }

.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 16px 22px;
  gap: 16px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px 20px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 11px; margin-right: auto; }

.logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-text);
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px;
  letter-spacing: -0.3px;
}

.brand h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.2px; line-height: 1.2; }
.ver { font-size: 11px; font-weight: 500; color: var(--dim); margin-left: 4px; }
.brand-desc { font-size: 12px; color: var(--dim); }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.header-actions { display: flex; align-items: center; gap: 6px; }

/* ---------- Segmented controls ---------- */
.seg-group {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  gap: 1px;
}

.seg-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  min-height: 26px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  transition: background 0.15s, color 0.15s;
}
.seg-btn:hover:not(.active) { color: var(--text); }
.seg-btn.active { background: var(--accent-soft); color: var(--accent-text); }

.seg-sm { padding: 1px; }
.seg-sm .seg-btn { font-size: 11px; padding: 2px 7px; min-height: 22px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  padding: 5px 12px;
  min-height: 30px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--dim); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface); border-color: var(--line); color: var(--text); }

.btn-primary { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }

.btn-sm { padding: 2px 9px; min-height: 24px; font-size: 11.5px; border-radius: 6px; }

label.btn-file { position: relative; overflow: hidden; }
label.btn-file input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.icon-btn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 6px;
  color: var(--dim); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-close:hover:not(:disabled) { color: var(--bad); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }

.btn:focus-visible, .seg-btn:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------- Window layouts ---------- */
.windows-container { display: flex; gap: 16px; flex: 1; min-height: 0; }

.windows-container.layout-horizontal { flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
.windows-container.layout-horizontal .window-card { flex: 1 1 540px; min-width: 440px; max-width: 820px; }

.windows-container.layout-vertical { flex-direction: column; }
.windows-container.layout-vertical .window-card { width: 100%; }

.windows-container.layout-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(480px, 1fr)); }

/* ---------- Window card ---------- */
.window-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  min-width: 360px;
  height: var(--window-height);
  resize: both;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.window-card.focused { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

.window-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 7px 8px 7px 12px;
  border-bottom: 1px solid var(--line-soft);
  user-select: none;
}

.window-title-group { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }

.window-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px; font-weight: 600;
  padding: 2px 6px;
  border-radius: 5px;
  min-width: 80px; max-width: 260px;
  field-sizing: content;
  text-overflow: ellipsis;
}
.window-title-input:hover { background: var(--surface-2); }
.window-title-input:focus { outline: none; border-color: var(--line); background: var(--inset); }

.window-format-badge {
  font-size: 11px; font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--dim);
  background: var(--surface-2);
  white-space: nowrap;
}
.window-format-badge.kind-jwt   { color: var(--violet); background: color-mix(in srgb, var(--violet) 13%, transparent); }
.window-format-badge.kind-json  { color: var(--teal);   background: color-mix(in srgb, var(--teal) 13%, transparent); }
.window-format-badge.kind-text  { color: var(--accent-text); background: var(--accent-soft); }
.window-format-badge.kind-image { color: var(--ok);     background: color-mix(in srgb, var(--ok) 13%, transparent); }
.window-format-badge.kind-error { color: var(--bad);    background: color-mix(in srgb, var(--bad) 13%, transparent); }

.window-actions { display: flex; align-items: center; gap: 2px; }

/* ---------- Window body + splitter ---------- */
.window-body {
  display: grid;
  grid-template-columns: 1fr 9px 1fr;
  flex: 1; min-height: 0;
  overflow: hidden;
}
.window-card.internal-stacked .window-body { grid-template-columns: 1fr; grid-template-rows: 1fr 9px 1fr; }

.split-divider {
  display: grid; place-items: center;
  cursor: col-resize;
  background: var(--surface);
  border-left: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
}
.window-card.internal-stacked .split-divider {
  cursor: row-resize;
  border: 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}
.split-handle-icon { width: 3px; height: 22px; border-radius: 2px; background: var(--line); transition: background 0.15s; }
.window-card.internal-stacked .split-handle-icon { width: 22px; height: 3px; }
.split-divider:hover .split-handle-icon, .split-divider:active .split-handle-icon { background: var(--accent); }

/* ---------- Panes ---------- */
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; overflow: hidden; }

.pane-sub-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 6px 8px;
  min-height: 38px;
  padding: 5px 10px 5px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 11.5px;
}
.pane-title-row { display: flex; align-items: center; gap: 8px; }
.pane-sub-title { font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.pane-tools { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.pane-stat { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; margin-right: 2px; }

.editor-area-wrap { position: relative; flex: 1; display: flex; min-height: 0; }

textarea.encoded-textarea {
  flex: 1; width: 100%;
  background: var(--inset);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px; line-height: 1.6;
  padding: 12px 14px;
  border: 0; outline: none; resize: none;
  word-break: break-all; white-space: pre-wrap;
}
textarea.encoded-textarea::placeholder { color: var(--dim); }

.drag-overlay {
  position: absolute; inset: 8px;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1.5px dashed var(--accent);
  border-radius: 8px;
  color: var(--accent-text);
  z-index: 40; pointer-events: none;
}
.drag-overlay svg { stroke: currentColor; }
.pane-input.dragover .drag-overlay { display: flex; }
.drag-overlay p { font-size: 13px; font-weight: 600; margin-top: 8px; }

/* ---------- Output ---------- */
.output-area-wrap {
  flex: 1; min-height: 0;
  overflow-y: auto;
  background: var(--inset);
  padding: 14px;
}

pre.raw-display-view, .code-view {
  margin: 0;
  white-space: pre-wrap; word-break: break-all;
  font-family: var(--mono);
  font-size: 12.5px; line-height: 1.6;
  color: var(--text);
}
.code-view { padding: 10px 12px; font-size: 12px; }

.state-empty {
  height: 100%; min-height: 150px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--dim);
  user-select: none;
}
.state-empty svg { width: 30px; height: 30px; margin-bottom: 10px; opacity: 0.55; }
.state-empty h4 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.state-empty p { font-size: 12px; max-width: 250px; }

.state-error {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bad) 9%, transparent);
  color: var(--bad);
}
.state-error svg { flex-shrink: 0; margin-top: 1px; }
.state-error h5 { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.state-error p { font-size: 12px; color: var(--muted); }

/* JWT */
.jwt-layout { display: flex; flex-direction: column; gap: 12px; }

.jwt-meta-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 2px; font-size: 12px; }
.jwt-title { font-weight: 600; font-size: 12.5px; }
.jwt-alg { color: var(--dim); margin-left: 6px; font-size: 11.5px; }

.token-pill { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; }
.token-pill.active  { color: var(--ok);  background: color-mix(in srgb, var(--ok) 14%, transparent); }
.token-pill.expired { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.token-pill.neutral { color: var(--muted); background: var(--surface-2); }

.card-block {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  overflow: hidden;
}
.card-block-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 8px 5px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.card-block-title { font-size: 11.5px; font-weight: 600; }
.card-block-title.claims-color  { color: var(--accent-text); }
.card-block-title.header-color  { color: var(--code-num); }
.card-block-title.payload-color { color: var(--violet); }
.card-block-title.sig-color     { color: var(--teal); }

.claims-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.claims-table th, .claims-table td { padding: 7px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
.claims-table th { font-size: 11px; font-weight: 600; color: var(--dim); }
.claims-table tr:last-child td { border-bottom: 0; }
.claims-key-col { width: 28%; }
.claims-key { font-family: var(--mono); font-weight: 600; color: var(--code-key); white-space: nowrap; }
.claims-label { display: block; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-weight: 400; font-size: 11px; color: var(--dim); }
.claims-value { font-family: var(--mono); color: var(--text); }
.claims-value, .claims-value span, .claims-hint { word-break: normal; overflow-wrap: anywhere; }
.claims-hint { display: block; margin-top: 1px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 11px; color: var(--muted); }
.claims-empty { color: var(--dim); text-align: center; }

.sig-value { padding: 9px 12px; font-family: var(--mono); font-size: 11.5px; color: var(--teal); word-break: break-all; }

.hl-key  { color: var(--code-key); }
.hl-str  { color: var(--code-str); }
.hl-num  { color: var(--code-num); }
.hl-bool { color: var(--code-bool); }
.hl-null { color: var(--dim); font-style: italic; }

/* Image */
.image-preview-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px; }
.image-preview-wrap img {
  max-width: 100%; max-height: 300px;
  border-radius: 6px; border: 1px solid var(--line);
  background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--inset) 0% 50%) 50% / 14px 14px;
}
.image-meta { font-size: 11.5px; color: var(--dim); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* ---------- Footer ---------- */
.app-footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 16px;
  font-size: 11.5px; color: var(--dim);
}

/* ---------- Small screens ---------- */
@media (max-width: 800px) {
  .app-wrapper { padding: 12px; gap: 12px; }
  .brand-desc { display: none; }
  .toolbar { order: 3; width: 100%; }
  .windows-container.layout-horizontal { flex-direction: column; }
  .windows-container.layout-grid { grid-template-columns: 1fr; }
  .windows-container .window-card { min-width: 0 !important; width: 100%; flex: none; }
  .window-body { grid-template-columns: 1fr; grid-template-rows: 1fr 9px 1fr; }
  .split-divider { cursor: row-resize; border: 0; border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
  .split-handle-icon { width: 22px; height: 3px; }
  .window-title-input { max-width: 170px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
