*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #5c6570;
  --border: #dde2e8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #0f766e;
  --warn-bg: #fff7ed;
  --warn-border: #fdba74;
  --info-bg: #eff6ff;
  --info-border: #93c5fd;
  --accent-bg: #ecfdf5;
  --accent-border: #6ee7b7;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
}

.logo {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  font-size: 1.05rem;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

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

.nav-user {
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-form {
  display: inline;
  margin: 0;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.main {
  flex: 1;
  padding: 1.5rem 1rem 2.5rem;
}

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1.25rem 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.site-footer p {
  margin: 0.25rem 0;
}

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

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.lead {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 1.05rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.card-narrow {
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.card h1,
.card h2 {
  margin-top: 0;
}

.placeholder {
  padding: 1.5rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
  background: var(--bg);
}

.notices {
  display: grid;
  gap: 0.75rem;
}

.notice {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

.notice-info {
  background: var(--info-bg);
  border-color: var(--info-border);
}

.notice-accent {
  background: var(--accent-bg);
  border-color: var(--accent-border);
}

.notice-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.flash-list {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.flash-info {
  background: var(--info-bg);
  border: 1px solid var(--info-border);
}

.flash-success {
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
}

.flash-error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
}

.form {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.form label {
  font-weight: 600;
  font-size: 0.9rem;
}

.form input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.form input:disabled {
  background: var(--bg);
  color: var(--muted);
}

.form-footer {
  margin-top: 1rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: center;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-outline {
  border-color: var(--border);
  color: var(--text);
  background: var(--surface);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

@media (max-width: 480px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.75rem 0;
  }

  .nav {
    width: 100%;
    justify-content: flex-start;
  }
}

.convert-form {
  margin-top: 0.5rem;
}

.format-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0;
}

.format-fieldset legend {
  font-weight: 600;
  padding: 0 0.25rem;
}

.format-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.format-option {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--bg);
}

.format-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--info-bg);
}

.hidden {
  display: none !important;
}

.convert-status {
  margin-top: 1rem;
}

.status-processing {
  text-align: center;
  padding: 1.5rem 0;
}

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0 auto 1rem;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

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

.status-error {
  color: #b91c1c;
  font-weight: 600;
}

.status-completed .btn {
  margin: 0.75rem 0;
}

.table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
}

.library-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.library-table th,
.library-table td {
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.library-table th {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.filename-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

.actions-cell {
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-queued,
.badge-processing,
.badge-active {
  background: var(--info-bg);
  color: #1e40af;
}

.badge-completed {
  background: var(--accent-bg);
  color: #065f46;
}

.badge-failed {
  background: #fef2f2;
  color: #b91c1c;
}

.active-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.active-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.active-list li:last-child {
  border-bottom: none;
}

.active-name {
  font-weight: 600;
  flex: 1 1 140px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.active-route {
  color: var(--muted);
  font-size: 0.9rem;
}

.archive-banner {
  margin-bottom: 1rem;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.95rem;
}

.pagination a {
  color: var(--primary);
  text-decoration: none;
}

.pagination a:hover {
  text-decoration: underline;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  background: var(--bg);
  margin-bottom: 1rem;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--info-bg);
}

.upload-zone-title {
  margin: 0 0 0.35rem;
  font-weight: 600;
}

.upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

#upload-zone {
  position: relative;
}
