:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-soft: #64748b;
  --muted: #94a3b8;
  --border: #e7edf3;
  --border-strong: #d5dee8;
  --blue: #1e4b7a;
  --blue-hover: #173e66;
  --blue-soft: #e8f1f8;
  --blue-mid: #3d6a94;
  --zebra: #f4f7fb;
  --row-hover: #eef3f8;
  --selected: #dce8f4;
  --selected-hover: #d3e2f1;
  --danger: #8f3030;
  --danger-border: #e7c8c8;
  --danger-soft: #f8eeee;
  --ok: #1d6b3c;
  --ok-soft: #e7f3ec;
  --wait: #8a6414;
  --wait-soft: #f8f3e4;
  --fetch: #1e4b7a;
  --fetch-soft: #e7eef6;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  max-width: 78rem;
  margin: 1.75rem auto 3rem;
  padding: 0 1.25rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--blue);
}

h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text);
}

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

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

nav.nav {
  display: flex;
  gap: 0.15rem;
  padding: 0.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

nav.nav a {
  text-decoration: none;
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
}

nav.nav a:hover {
  color: var(--blue);
}

nav.nav a.active {
  background: var(--blue);
  color: #fff;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0 0 1rem;
}

.ingest {
  padding: 1rem;
  display: grid;
  gap: 0.85rem;
}

textarea[name="url"] {
  width: 100%;
  min-height: 7rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  resize: vertical;
  line-height: 1.45;
}

textarea::placeholder {
  color: var(--muted);
}

.ingest-bar,
.toolbar-main,
.inline-actions,
.filter-fields,
.filters,
.meta,
.mode-actions,
.table-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.75rem;
  align-items: center;
}

.table-head,
.toolbar,
.filters {
  justify-content: space-between;
}

.ingest-bar {
  justify-content: flex-start;
}

.mode-actions button.danger {
  order: -1;
}

.filters {
  padding: 0.9rem 1rem;
  align-items: flex-end;
}

.filter-fields {
  align-items: flex-end;
}

label.field {
  display: grid;
  gap: 0.28rem;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-soft);
}

select,
input[type="date"] {
  min-height: 2.35rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}

.range {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
}

.range-sep {
  color: var(--muted);
  padding-bottom: 0.45rem;
}

button,
.button {
  min-height: 2.35rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.button:hover {
  border-color: var(--blue-mid);
  color: var(--blue);
}

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

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

button.danger {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--surface);
}

button.danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.text-btn {
  min-height: 2.35rem;
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.35rem;
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}

.text-btn:hover {
  color: var(--blue);
}

.file-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 2.35rem;
  max-width: 16rem;
  padding: 0.4rem 0.8rem;
  border: 1px dashed var(--blue-mid);
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.file-picker.has-file {
  border-style: solid;
  max-width: 22rem;
}

.file-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-picker span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea:focus,
select:focus,
input[type="date"]:focus {
  outline: 2px solid rgba(30, 75, 122, 0.22);
  border-color: var(--blue-mid);
}

button:focus-visible,
a:focus-visible,
.file-picker:focus-within {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.error,
.notice {
  background: var(--surface);
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  margin: 0 0 1rem;
}

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

.notice {
  color: var(--wait);
  border-left-color: #c4a15a;
}

.table-panel {
  overflow: hidden;
}

.table-head,
.toolbar,
.table-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.75rem;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
}

.table-head,
.toolbar {
  border-bottom: 1px solid var(--border);
}

.toolbar {
  justify-content: flex-end;
}

.table-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.progress-note {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.2rem 0 0;
  color: var(--text-soft);
  font-size: 0.88rem;
}

.dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 0 rgba(30, 75, 122, 0.4);
  animation: pulse 1.6s ease-out infinite;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 6px rgba(30, 75, 122, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(30, 75, 122, 0);
  }
}

.selection-count {
  color: var(--blue);
  font-size: 0.85rem;
  font-weight: 650;
}

.meta {
  margin-left: auto;
  color: var(--text-soft);
  font-size: 0.88rem;
}

.pager {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.library-table,
.session-table {
  table-layout: auto;
}

th,
td {
  text-align: left;
  vertical-align: middle;
  padding: 0.72rem 0.7rem;
  border-bottom: 1px solid var(--border);
}

th:first-child,
td:first-child {
  padding-left: 1rem;
}

th:last-child,
td:last-child {
  padding-right: 1rem;
}

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

th {
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-soft);
  background: var(--surface);
  white-space: nowrap;
}

th a {
  color: inherit;
  text-decoration: none;
}

th a:hover,
th a.active {
  color: var(--blue);
}

tbody tr:nth-child(even) {
  background: var(--zebra);
}

tbody tr:hover {
  background: var(--row-hover);
}

tbody tr.is-selected,
tbody tr.is-selected:nth-child(even) {
  background: var(--selected);
}

tbody tr.is-selected:hover {
  background: var(--selected-hover);
}

td.date {
  white-space: nowrap;
  color: var(--text);
}

.library-table .check {
  width: 2.75rem;
}

td.title {
  min-width: 10rem;
}

td.date,
td.status-col,
td.row-actions,
th.actions {
  white-space: nowrap;
}

td.url {
  width: 12rem;
  max-width: 12rem;
  white-space: normal;
}

td.url a {
  color: var(--blue);
  text-decoration: none;
  overflow-wrap: break-word;
}

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

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

.empty {
  color: var(--text-soft);
  text-align: center;
  padding: 1.6rem 1rem;
}

input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--blue);
  cursor: pointer;
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1.4;
  background: #f1f5f9;
  color: #475569;
}

.status-saved {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-wait {
  background: var(--wait-soft);
  color: var(--wait);
}

.status-fetch {
  background: var(--fetch-soft);
  color: var(--fetch);
}

.status[data-reason] {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 0.18em;
}

.status-tip {
  position: fixed;
  z-index: 30;
  max-width: 18rem;
  padding: 0.45rem 0.65rem;
  background: #1e3a5f;
  color: #f8fafc;
  font-size: 0.8rem;
  line-height: 1.4;
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18);
  pointer-events: none;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.15rem;
  white-space: nowrap;
}

.inline-form {
  display: inline-flex;
}

.icon-btn {
  width: 2rem;
  height: 2rem;
  min-height: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--blue-mid);
}

.icon-btn:hover {
  background: var(--blue-soft);
  border-color: transparent;
  color: var(--blue);
}

.icon-btn.danger {
  color: #a24a4a;
  border-color: transparent;
  background: transparent;
}

.icon-btn.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

.transcript {
  padding: 0.9rem 1rem 1rem;
}

.transcript-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.icon-btn .icon-check {
  display: none;
}

.icon-btn.is-copied {
  color: var(--ok);
}

.icon-btn.is-copied .icon-copy {
  display: none;
}

.icon-btn.is-copied .icon-check {
  display: block;
}

.format-dialog {
  width: min(22rem, calc(100% - 2rem));
  margin: auto;
  padding: 1.1rem 1.15rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16);
}

.format-dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.format-dialog form {
  display: grid;
  gap: 1rem;
}

.format-choices {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 0.45rem;
}

.format-choices legend {
  margin-bottom: 0.35rem;
  padding: 0;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text);
}

.format-choices label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.35rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.format-choices label:hover {
  border-color: var(--blue-mid);
  color: var(--blue);
}

.format-choices label:has(input:checked) {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  font-size: 0.92rem;
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .dot {
    animation: none;
  }
}

@media (max-width: 760px) {
  body {
    margin-top: 1rem;
    padding: 0 0.75rem 2rem;
  }

  .top,
  .filters,
  .ingest-bar,
  .toolbar,
  .table-head {
    align-items: stretch;
  }

  .filter-fields,
  .ingest-bar,
  .toolbar-main,
  .range {
    flex-direction: column;
    align-items: stretch;
  }

  .range-sep {
    display: none;
  }

  .file-picker,
  .filter-fields select,
  .filter-fields input[type="date"],
  .ingest-bar select,
  .toolbar select,
  .table-head select,
  .ingest-bar button,
  .filters button,
  .toolbar button,
  .table-head button,
  .pager .button {
    width: 100%;
  }

  .mode-actions,
  .toolbar-main,
  .ingest-bar > .inline-actions,
  .filters > .inline-actions {
    width: 100%;
  }

  .meta {
    margin-left: 0;
  }

  nav.nav {
    width: 100%;
  }

  nav.nav a {
    flex: 1;
    text-align: center;
  }
}
