:root {
  color-scheme: dark;
  --bg: #0d1520;
  --surface: #131f30;
  --surface-muted: #192738;
  --surface-inset: #0a1219;
  --text: #dce8f5;
  --text-muted: #7a94b4;
  --text-subtle: #4a6585;
  --border: #1d3050;
  --border-subtle: #162540;
  --accent: #3d7eff;
  --accent-soft: #152240;
  --accent-dim: #2a56c0;
  --danger: #e05570;
  --success: #27b87a;
  --warning: #e8a030;
  --shadow-xs: 0 1px 4px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --shadow-sm: 0 4px 16px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.35);
  --shadow-md: 0 8px 32px rgba(0,0,0,.5), 0 4px 8px rgba(0,0,0,.4);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100dvh;
  overflow: hidden;
}

body {
  margin: 0;
  font-family:
    "Hiragino Sans",
    "Yu Gothic",
    sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 900px 700px at 0% -10%, rgba(61,126,255,.09) 0%, transparent 60%),
    radial-gradient(ellipse 600px 500px at 105% 110%, rgba(61,126,255,.06) 0%, transparent 55%);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

/* ── Login ── */
.login-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  text-align: center;
  box-shadow: var(--shadow-md);
  max-width: 360px;
  width: 100%;
}

.login-brand {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
  letter-spacing: -0.01em;
}

.login-desc {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 28px;
  line-height: 1.6;
}

/* ── App Layout ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  gap: 16px;
  flex-shrink: 0;
}

.topbar-brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-body {
  display: flex;
  height: calc(100dvh - 52px);
  overflow: hidden;
}

.sidebar {
  width: 180px;
  flex-shrink: 0;
  padding: 16px 10px;
  border-right: 1px solid var(--border-subtle);
  background: var(--surface-inset);
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 52px;
  height: calc(100dvh - 52px);
  overflow-y: auto;
}

.sidebar-item {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: color 0.15s, background 0.15s;
}

.sidebar-item:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.sidebar-item[data-active="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

main {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 24px 28px 72px;
  overflow-y: auto;
}

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.lead {
  margin: 7px 0 0;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.5;
}

/* ── Page Hero ── */
.page-hero {
  padding: 30px 0 0;
  margin-bottom: 0;
  position: relative;
}

.page-hero::before {
  content: '';
  display: block;
  position: absolute;
  top: 0;
  left: -28px;
  right: -28px;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, rgba(61,126,255,.35) 60%, transparent 100%);
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
}

/* ── Buttons ── */
.button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: opacity 0.15s;
}

.button:hover {
  opacity: 0.88;
}

.button.secondary {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.button.secondary:hover {
  color: var(--text);
  border-color: var(--accent-dim);
  opacity: 1;
}

/* ── Grid / Summary Cards ── */
.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 20px 20px 18px;
  box-shadow: var(--shadow-sm);
}

.card h3 {
  margin: 0 0 14px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.card strong {
  font-size: 38px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

/* ── Sections ── */
.section {
  margin-top: 32px;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.panel-body {
  padding: 20px 22px;
}

/* ── Misc ── */
.empty {
  padding: 32px 16px;
  color: var(--text-subtle);
  text-align: center;
  font-size: 14px;
}

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

.mono {
  font-family:
    "SFMono-Regular",
    Consolas,
    monospace;
  font-size: 12px;
}

/* ── Pills ── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--accent-soft);
  color: var(--accent);
}

.pill[data-tone="danger"] {
  background: rgba(224, 85, 112, 0.15);
  color: var(--danger);
}

.pill[data-tone="success"] {
  background: rgba(39, 184, 122, 0.15);
  color: var(--success);
}

.pill[data-tone="warning"] {
  background: rgba(232, 160, 48, 0.15);
  color: var(--warning);
}

/* ── Request List ── */
.requests-pane {
  display: grid;
  grid-template-columns: 300px 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-height: 500px;
}

.req-list-pane {
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.req-detail-pane {
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Requests page: flex-fill layout ── */
main[data-page="requests"] {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 24px;
}

main[data-page="requests"] #pageError {
  flex-shrink: 0;
}

main[data-page="requests"] #pageBody {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

main[data-page="requests"] .section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 0;
}

main[data-page="requests"] .section-header {
  flex-shrink: 0;
}

main[data-page="requests"] .requests-pane {
  flex: 1;
  min-height: 0;
}

main[data-page="requests"] .req-list-pane,
main[data-page="requests"] .req-detail-pane {
  height: 100%;
}

.req-list-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.1s;
  border-left: 3px solid transparent;
}

.req-list-item:last-child {
  border-bottom: none;
}

.req-list-item:hover {
  background: var(--surface-muted);
}

.req-list-item--active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.req-list-item--active:hover {
  background: var(--accent-soft);
}

.req-list-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.req-issue-key {
  font-size: 11px;
  font-weight: 700;
  font-family:
    "SFMono-Regular",
    Consolas,
    monospace;
  color: var(--text-subtle);
  letter-spacing: 0.04em;
}

.req-list-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  margin-bottom: 4px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.req-list-meta {
  font-size: 11.5px;
  color: var(--text-subtle);
  line-height: 1.3;
}

.req-detail-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.req-detail-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}

.req-block {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.req-block-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
}

.req-kv-grid {
  display: grid;
  gap: 8px 24px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.req-divider {
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: 4px 0;
}

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

.kv-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── List Card / Field Card / Details Card ── */
.list-card {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  min-width: 0;
}

.stack {
  display: grid;
  gap: 12px;
}

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

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.chip[data-active="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

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

.select,
.input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 8px 12px;
  transition: border-color 0.15s;
}

.select:focus,
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input {
  min-width: 180px;
}

/* ── Tab Panels ── */
.tab-panels {
  display: grid;
  gap: 16px;
}

.tab-panel[hidden] {
  display: none;
}

.field-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.field-card {
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
}

.field-card strong {
  display: block;
  margin-top: 6px;
  font-size: 15px;
  font-weight: 700;
}

.details-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 0;
  overflow: hidden;
  min-width: 0;
  box-shadow: var(--shadow-xs);
}

.details-card summary {
  cursor: pointer;
  list-style: none;
  padding: 13px 16px;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text-muted);
  transition: color 0.15s;
}

.details-card summary::-webkit-details-marker {
  display: none;
}

.details-card[open] summary {
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text);
  background: var(--surface-muted);
}

.details-card .details-body {
  padding: 14px 16px;
}

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

.compact-list > li {
  margin-left: 18px;
}

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

.text-block {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
  font-size: 14px;
}

.summary-preview {
  color: var(--text-subtle);
  font-size: 13px;
  font-weight: 400;
  margin-top: 4px;
  line-height: 1.4;
}

/* ── Log / JSON Output (dark terminal) ── */
.log-output,
.json-output {
  min-height: 240px;
  max-height: 700px;
  overflow: auto;
  margin: 0;
  padding: 18px 20px;
  background: #060d18;
  color: #a8cae8;
  border-radius: var(--radius-lg);
  border: 1px solid #0d2240;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.04),
    inset 0 -1px 0 rgba(0,0,0,.3),
    0 8px 32px rgba(0,0,0,.5);
  font-family:
    "SFMono-Regular",
    Consolas,
    monospace;
  font-size: 12.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: #1a3a5e #060d18;
}

.log-output::-webkit-scrollbar,
.json-output::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.log-output::-webkit-scrollbar-track,
.json-output::-webkit-scrollbar-track {
  background: transparent;
}

.log-output::-webkit-scrollbar-thumb,
.json-output::-webkit-scrollbar-thumb {
  background: #1a3a5e;
  border-radius: 3px;
}

.json-output {
  background: #050c15;
  color: #8ab8d8;
}

/* ── Table ── */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13.5px;
}

th {
  color: var(--text-subtle);
  background: var(--surface-muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

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

/* ── Error ── */
.error {
  margin-top: 16px;
  color: var(--danger);
  font-size: 14px;
  padding: 12px 16px;
  background: rgba(224, 85, 112, 0.1);
  border: 1px solid rgba(224, 85, 112, 0.3);
  border-radius: var(--radius-md);
}

/* ── Request Key Facts ── */
.req-key-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 10px 14px;
  background: var(--surface-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

/* ── Summary Meta Line ── */
.summary-meta {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-top: 5px;
  line-height: 1.4;
}

/* ── Details card chevron ── */
.details-card summary::before {
  content: '▸ ';
  font-size: 11px;
  color: var(--text-subtle);
}

.details-card[open] summary::before {
  content: '▾ ';
  color: var(--accent);
}

/* ── Section-contained Grid (e.g. memory summary cards) ── */
.section > .grid {
  margin-top: 0;
}

/* ── Responsive ── */
@media (max-width: 720px) {
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    padding: 8px 10px;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .app-body {
    flex-direction: column;
  }

  main {
    padding-inline: 16px;
  }

  h1 {
    font-size: 22px;
  }

  .page-hero::before {
    left: -16px;
    right: -16px;
  }

  .page-header {
    flex-direction: column;
    gap: 12px;
  }

  .req-kv-grid {
    grid-template-columns: 1fr;
  }

  .requests-pane {
    grid-template-columns: 1fr;
  }

  .req-list-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  .req-detail-pane {
    max-height: none;
  }

  .card strong {
    font-size: 30px;
  }
}

@media (max-width: 480px) {
  main {
    padding-inline: 12px;
  }

  .page-hero::before {
    left: -12px;
    right: -12px;
  }

  .topbar-meta {
    gap: 10px;
  }
}
