:root {
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-subtle: #f8fafc;
  --text: #17202a;
  --muted: #667085;
  --border: #d8dee4;
  --track: #e6ebef;
  --input: #ffffff;
  --button-subtle: #ffffff;
  --button-subtle-hover: #f8fafc;
  --disabled-bg: #e6ebef;
  --disabled-text: #98a2b3;
  --green: #1f7a5b;
  --blue: #275d9f;
  --red: #a33a3a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101418;
    --panel: #171d23;
    --panel-subtle: #202832;
    --text: #edf2f7;
    --muted: #a8b3bf;
    --border: #303a45;
    --track: #27313b;
    --input: #121820;
    --button-subtle: #171d23;
    --button-subtle-hover: #202832;
    --disabled-bg: #232c35;
    --disabled-text: #778391;
    --green: #35a373;
    --blue: #6aa7ff;
    --red: #f07178;
  }
}

:root[data-theme="dark"] {
  --bg: #101418;
  --panel: #171d23;
  --panel-subtle: #202832;
  --text: #edf2f7;
  --muted: #a8b3bf;
  --border: #303a45;
  --track: #27313b;
  --input: #121820;
  --button-subtle: #171d23;
  --button-subtle-hover: #202832;
  --disabled-bg: #232c35;
  --disabled-text: #778391;
  --green: #35a373;
  --blue: #6aa7ff;
  --red: #f07178;
}

:root[data-theme="light"] {
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-subtle: #f8fafc;
  --text: #17202a;
  --muted: #667085;
  --border: #d8dee4;
  --track: #e6ebef;
  --input: #ffffff;
  --button-subtle: #ffffff;
  --button-subtle-hover: #f8fafc;
  --disabled-bg: #e6ebef;
  --disabled-text: #98a2b3;
  --green: #1f7a5b;
  --blue: #275d9f;
  --red: #a33a3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.shell {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0;
}

header {
  margin-bottom: 18px;
}

.page-header,
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.back-button,
.detail-back-button {
  flex: 0 0 auto;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--text);
}

h1 {
  font-size: 32px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
}

.status-panel,
.meta-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.status-line span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.status-line strong {
  font-size: 13px;
}

.progress-track {
  overflow: hidden;
  height: 9px;
  margin-top: 12px;
  border-radius: 999px;
  background: var(--track);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
  transition: width 220ms ease;
}

.message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.message.error {
  color: var(--red);
}

.message.success {
  color: var(--green);
}

.meta-panel {
  margin-top: 14px;
}

dl {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 1px;
  overflow: hidden;
  margin: 14px 0 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--border);
}

dt,
dd {
  min-height: 38px;
  margin: 0;
  padding: 10px 12px;
  background: var(--panel);
  font-size: 13px;
  line-height: 1.35;
}

.public-timeline {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding-left: 22px;
}

.public-timeline li {
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

dt {
  color: var(--muted);
  font-weight: 800;
}

dd {
  overflow-wrap: anywhere;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
  border: 1px solid var(--blue);
  border-radius: 7px;
  background: var(--blue);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
}

button.secondary-button {
  width: auto;
  min-height: 36px;
  margin-top: 0;
  border-color: var(--border);
  background: var(--button-subtle);
  color: var(--text);
  padding: 0 12px;
}

button.secondary-button:hover:not(:disabled) {
  border-color: #aab4c0;
  background: var(--button-subtle-hover);
}

button:hover:not(:disabled) {
  background: #1f4d86;
}

button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

button:disabled {
  border-color: var(--border);
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}

.theme-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  width: auto;
  min-height: 34px;
  margin: 0;
  border-color: var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
  box-shadow: 0 10px 28px rgba(16, 20, 24, 0.14);
  font-size: 12px;
}

.theme-toggle:hover:not(:disabled) {
  background: var(--button-subtle-hover);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 380px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  background: var(--panel);
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.login-form label {
  display: grid;
  gap: 8px;
}

.login-form span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0 12px;
  background: var(--input);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.panel-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

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

.panel-header form {
  margin: 0;
}

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

.panel-stats div,
.table-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.panel-stats div {
  padding: 13px;
}

.panel-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.panel-stats strong {
  display: block;
  margin-top: 9px;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-panel {
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.open-link-form,
.xml-upload-form {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.open-link-form label,
.xml-upload-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.open-link-form div,
.xml-upload-form div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.open-link-form button {
  min-height: 42px;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--panel-subtle);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tbody tr:hover td {
  background: var(--panel-subtle);
}

tbody tr.expandable-row {
  cursor: pointer;
}

tbody tr.expandable-row:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

tbody tr.expandable-row.is-expanded td {
  background: var(--panel-subtle);
}

tbody tr.is-target-row td {
  background: color-mix(in srgb, var(--blue) 14%, var(--panel));
}

td a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

td a:hover {
  text-decoration: underline;
}

.muted-cell-text {
  color: var(--muted);
  font-size: 13px;
}

.inline-button {
  width: auto;
  min-height: 30px;
  margin: 0;
  border-color: var(--border);
  background: var(--button-subtle);
  color: var(--blue);
  padding: 0 9px;
  font-size: 12px;
}

.inline-button:hover:not(:disabled) {
  border-color: #aab4c0;
  background: var(--button-subtle-hover);
}

.inline-button:disabled {
  color: var(--disabled-text);
}

.timeline-detail-row[hidden] {
  display: none;
}

.timeline-detail-cell {
  padding: 0;
  background: var(--panel-subtle);
}

.timeline-detail {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--border);
}

.timeline-detail strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
}

.timeline-detail .detail-header {
  align-items: center;
}

.timeline-detail .detail-back-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.timeline-detail .detail-grid {
  grid-template-columns: 160px minmax(0, 1fr);
  margin: 0;
  border-radius: 7px;
}

.timeline-detail .detail-grid dt,
.timeline-detail .detail-grid dd {
  min-height: 34px;
  padding: 8px 10px;
  white-space: normal;
}

.timeline-detail .detail-grid a {
  overflow-wrap: anywhere;
}

.timeline-detail ol {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 22px;
}

.timeline-detail ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 22px;
}

.extraction-summary {
  display: grid;
  gap: 10px;
  padding-top: 2px;
}

.extraction-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.extraction-switch {
  display: inline-grid;
  grid-auto-flow: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--button-subtle);
}

.extraction-switch button {
  width: auto;
  min-width: 64px;
  min-height: 30px;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
}

.extraction-switch button:hover:not(:disabled) {
  background: var(--button-subtle-hover);
}

.extraction-switch button.is-active {
  background: var(--blue);
  color: #ffffff;
}

.extraction-loading {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

.extraction-note {
  margin: 0;
  color: var(--muted);
}

.timeline-detail li,
.timeline-detail p {
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  white-space: normal;
}

.timeline-detail .summary-label {
  color: var(--text);
  font-weight: 400;
}

.timeline-detail .summary-value {
  color: var(--text);
  font-size: inherit;
  font-weight: 800;
  line-height: inherit;
}

.timeline-detail p {
  margin: 0;
  color: var(--muted);
}

.number-cell {
  text-align: right;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.table-panel .message {
  margin: 0;
  padding: 12px;
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 24px, 720px);
    padding-top: 24px;
  }

  h1 {
    font-size: 26px;
  }

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

  .page-header .back-button {
    width: 100%;
  }

  dl {
    grid-template-columns: 1fr;
  }

  .panel-shell {
    width: min(100% - 24px, 1180px);
    padding-top: 20px;
  }

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

  .panel-header .secondary-button {
    width: 100%;
  }

  .panel-stats {
    grid-template-columns: 1fr 1fr;
  }

  .open-link-form div,
  .xml-upload-form div {
    grid-template-columns: 1fr;
  }

  .open-link-form .secondary-button,
  .xml-upload-form .secondary-button {
    width: 100%;
  }

  .timeline-detail .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar {
    transition: none;
  }

  .loading-spinner {
    animation: none;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
