:root {
  color-scheme: light;
  --background: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #eef1f4;
  --border: #d8dde3;
  --text: #20242a;
  --muted: #5c6672;
  --primary: #176b4d;
  --primary-hover: #10563d;
  --secondary: #2f5d8a;
  --danger: #b42318;
  --focus: #d97706;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  line-height: 1.5;
}

button, input, summary { font: inherit; }

button, .button, summary { cursor: pointer; }

button:disabled { cursor: wait; opacity: 0.65; }

a { color: inherit; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
  outline-offset: 2px;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner,
.page-shell {
  width: min(1280px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row h1 { margin: 0; font-size: 20px; letter-spacing: 0; }
.brand-row p { margin: 1px 0 0; color: var(--muted); font-size: 13px; }

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  font-weight: 750;
  letter-spacing: 0;
}

.brand-mark-small { width: 38px; height: 38px; font-size: 14px; }

.page-shell { padding: 28px 0 56px; }

.upload-section,
.library-section {
  background: transparent;
}

.upload-section { padding-bottom: 28px; border-bottom: 1px solid var(--border); }
.library-section { margin-top: 28px; }

.section-heading {
  min-height: 56px;
  padding: 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.section-heading h2 { margin: 0; font-size: 17px; letter-spacing: 0; }
.section-heading span { color: var(--muted); font-size: 13px; }

.upload-grid {
  padding: 18px 0 0;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.4fr) minmax(220px, 1.2fr) auto;
  align-items: end;
  gap: 14px;
}

.field { min-width: 0; }

label {
  display: block;
  margin-bottom: 6px;
  color: #39414a;
  font-size: 13px;
  font-weight: 650;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid #aeb7c1;
  border-radius: 5px;
  background: #fff;
  color: var(--text);
}

input[type="file"] { padding: 7px; }

.button {
  min-height: 42px;
  padding: 9px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 5px;
  text-decoration: none;
  font-weight: 650;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}

.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { background: #edf4fa; border-color: #aec6dc; color: #1e4e78; }
.button-secondary:hover { background: #dfeef8; }
.button-quiet { background: #fff; border-color: #b9c1ca; color: #343b44; }
.button-quiet:hover { background: var(--surface-muted); }
.button-danger { background: #fff; border-color: #e5aaa5; color: var(--danger); }
.button-danger:hover { background: #fff0ef; }

.table-wrap { width: 100%; border: 1px solid var(--border); border-radius: 6px; overflow: visible; }

table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 14px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid #e5e8ec; }
th { background: #f7f8fa; color: #4c5661; font-size: 12px; text-transform: uppercase; }
th:nth-child(1) { width: 22%; }
th:nth-child(2) { width: 8%; }
th:nth-child(3) { width: 9%; }
th:nth-child(4) { width: 12%; }
th:nth-child(5) { width: 12%; }
th:nth-child(6) { width: 37%; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
td { font-size: 14px; overflow-wrap: anywhere; }
.cell-content { min-width: 0; }

audio { width: min(230px, 100%); height: 34px; display: block; margin-top: 8px; }
code { font-size: 12px; color: #5b3c10; }
.muted { color: var(--muted); font-size: 12px; }
.version-badge { display: inline-block; padding: 2px 7px; border-radius: 4px; background: #e7f3ed; color: #10563d; font-weight: 700; }

.actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 7px; }
.actions form { margin: 0; }
.replace-control { position: relative; }
.replace-control summary { list-style: none; }
.replace-control summary::-webkit-details-marker { display: none; }

.replace-form {
  position: absolute;
  z-index: 20;
  right: 0;
  top: calc(100% + 7px);
  width: min(320px, calc(100vw - 40px));
  padding: 14px;
  background: #fff;
  border: 1px solid #aeb7c1;
  border-radius: 6px;
  box-shadow: 0 12px 28px rgba(24, 31, 39, 0.18);
}
.replace-form label + label { margin-top: 10px; }
.replace-form .button { width: 100%; margin-top: 12px; }

.alert {
  margin-bottom: 16px;
  padding: 11px 14px;
  border: 1px solid;
  border-radius: 5px;
  font-size: 14px;
}
.alert-success { background: #edf8f2; border-color: #9ac9af; color: #14583e; }
.alert-error { background: #fff1f0; border-color: #e8aaa4; color: #8f1d15; }

.empty-state { min-height: 180px; display: grid; place-items: center; color: var(--muted); }

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

.login-panel {
  width: min(380px, 100%);
  padding: 30px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(24, 31, 39, 0.1);
}
.login-panel .brand-mark { margin-bottom: 18px; }
.login-panel h1 { margin: 0 0 24px; font-size: 24px; letter-spacing: 0; }
.form-stack { display: grid; gap: 8px; }
.form-stack input { margin-bottom: 8px; }
.form-stack .button { margin-top: 8px; }

@media (max-width: 940px) {
  .upload-grid { grid-template-columns: 1fr 1fr; }
  .upload-button { width: 100%; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody { padding: 8px 14px 14px; }
  tbody tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  tbody tr:last-child { border-bottom: 0; }
  td { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; padding: 8px 2px; border: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 650; }
  .actions { min-width: 0; }
  .replace-form { left: 0; right: auto; }
}

@media (max-width: 620px) {
  .topbar-inner, .page-shell { width: min(100% - 24px, 1280px); }
  .page-shell { padding-top: 16px; }
  .upload-grid { grid-template-columns: 1fr; padding: 14px; }
  .section-heading { padding: 13px 0; }
  td { grid-template-columns: 82px minmax(0, 1fr); }
  .login-panel { padding: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
