:root {
  color-scheme: dark;
  --bg: #101114;
  --surface: #17191d;
  --surface-2: #1f2228;
  --surface-3: #272b33;
  --border: #313640;
  --border-light: #414855;
  --ink: #f3f4f6;
  --ink-2: #c8ced8;
  --muted: #8b93a1;
  --accent: #5aa7a0;
  --accent-strong: #438b85;
  --accent-soft: rgba(90, 167, 160, 0.13);
  --accent-glow: rgba(90, 167, 160, 0.18);
  --success: #6fcf97;
  --success-soft: rgba(111, 207, 151, 0.1);
  --warn: #e2b15f;
  --warn-soft: rgba(226, 177, 95, 0.1);
  --danger: #e07171;
  --danger-soft: rgba(224, 113, 113, 0.11);
  --r-2xl: 12px;
  --r-xl: 10px;
  --r-lg: 8px;
  --r-md: 7px;
  --r-sm: 6px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
  --shadow-sm: 0 10px 26px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
}

body::before {
  content: none;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1220px, calc(100% - 40px));
  height: 100vh;
  margin: 0 auto;
  padding: 20px 0;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  height: 100%;
  min-height: 0;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  min-height: 0;
}

/* ─── HEADINGS ─── */

h2 {
  margin: 0;
  line-height: 1.1;
}

h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
}

/* ─── UPLOAD HEADER ─── */

.upload-header {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 520px);
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-sm);
}

/* ─── DROPZONE ─── */

.dropzone {
  display: grid;
  min-height: 120px;
  align-content: center;
  gap: 10px;
  padding: 22px 24px;
  border: 2px dashed var(--border-light);
  border-radius: var(--r-xl);
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.dropzone-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

.dropzone-name {
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.file-meta {
  color: var(--muted);
  font-size: 13px;
}

/* ─── CONTROLS ─── */

.controls {
  display: grid;
  gap: 10px;
  align-content: start;
}

.search-field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ─── PROGRESS ─── */

.percent-progress {
  position: relative;
  min-height: 38px;
  overflow: hidden;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.percent-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  border-radius: var(--r-lg);
  transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.percent-progress span {
  position: relative;
  display: grid;
  min-height: 38px;
  place-items: center;
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
}

.progress {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.progress li {
  position: relative;
  min-height: 36px;
  padding: 9px 10px 9px 30px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  transition: background 200ms ease, border-color 200ms ease, color 200ms ease;
}

.progress li::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 10px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--border-light);
  border-radius: 50%;
  transform: translateY(-50%);
  transition: all 200ms ease;
}

.progress li.active {
  border-color: rgba(226, 177, 95, 0.38);
  background: var(--warn-soft);
  color: var(--ink);
  font-weight: 550;
}

.progress li.active::before {
  border-color: var(--warn);
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(226, 177, 95, 0.12);
}

.progress li.complete {
  border-color: rgba(52, 211, 153, 0.25);
  background: var(--success-soft);
  color: var(--success);
}

.progress li.complete::before {
  border-color: var(--success);
  background: var(--success);
}

/* ─── INPUTS & BUTTONS ─── */

select,
button,
textarea,
input {
  width: 100%;
  font: inherit;
}

select,
button,
input {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--ink);
}

select:focus,
button:focus,
textarea:focus,
input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.action-row,
.download-actions,
.history-tools {
  display: flex;
  gap: 8px;
}

.action-row button {
  flex: 1;
}

button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  cursor: pointer;
  transition: background 140ms ease, box-shadow 140ms ease, transform 80ms ease;
}

button:hover {
  background: var(--accent-strong);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  border-color: var(--border-light);
  background: var(--surface-3);
  color: var(--muted);
  cursor: wait;
  box-shadow: none;
  transform: none;
}

.secondary-button,
.danger-button {
  width: auto;
  min-height: 38px;
}

.secondary-button {
  border-color: var(--border-light);
  background: var(--surface-2);
  color: var(--ink-2);
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: none;
}

.danger-button {
  border-color: rgba(248, 113, 113, 0.25);
  background: var(--surface-2);
  color: var(--danger);
}

.danger-button:hover {
  background: var(--danger-soft);
  box-shadow: none;
}

.danger-button:disabled {
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: default;
  box-shadow: none;
  transform: none;
}

.job-meta,
.save-status {
  color: var(--muted);
  font-size: 13px;
}

/* ─── RESULT ─── */

.result {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
}

.result-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.mode-switch {
  display: flex;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 3px;
}

.mode-switch button {
  width: auto;
  min-height: 32px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 0 14px;
  box-shadow: none;
}

.mode-switch button:hover {
  color: var(--ink);
  background: var(--surface-3);
  box-shadow: none;
}

.mode-switch button.active {
  background: var(--accent);
  color: #fff;
  box-shadow: none;
}

.download-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.download-actions a {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 8px 16px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all 140ms ease;
}

.download-actions a:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.result-bar a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

textarea {
  min-height: 0;
  height: 100%;
  resize: vertical;
  border: 0;
  border-radius: 0;
  padding: 22px 26px;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.75;
  font-size: 14px;
}

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

.result-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--border);
  padding: 12px 24px;
}

.save-status {
  min-width: 0;
}

.copy-button {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* ─── HISTORY ─── */

.history {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.history-bar {
  display: grid;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 18px;
}

.history-heading {
  display: grid;
  gap: 12px;
}

.history-tools {
  display: grid;
  align-items: stretch;
}

.search-field {
  display: grid;
  min-width: 0;
}

.search-field span {
  margin-bottom: 6px;
}

.history-tools input {
  min-width: 0;
}

.compact-switch {
  width: 100%;
}

.compact-switch button {
  flex: 1;
  min-height: 38px;
}

.history-tools .danger-button {
  width: 100%;
}

.history-list {
  display: grid;
  align-content: start;
  min-height: 0;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  transition: background 140ms ease;
}

.history-item:last-child {
  border-bottom: 0;
}

.history-item:hover {
  background: var(--surface-2);
}

.history-item.selected {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding-left: 21px;
}

.history-item strong,
.history-item span {
  display: block;
}

.history-item strong {
  overflow-wrap: anywhere;
  font-size: 14px;
  color: var(--ink);
}

.history-info {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.title-editor {
  position: relative;
  display: grid;
}

.history-title {
  min-height: 36px;
  border-color: var(--border);
  padding: 0 46px 0 12px;
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
}

.history-title[readonly] {
  border-color: transparent;
  background: transparent;
  padding-left: 0;
  cursor: text;
}

.history-title:focus {
  border-color: var(--accent);
}

.icon-save,
.title-saved {
  position: absolute;
  top: 50%;
  right: 5px;
  width: 30px;
  min-height: 28px;
  transform: translateY(-50%);
}

.icon-save {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-sm);
  padding: 0;
  min-height: 26px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
}

.icon-save:hover {
  background: var(--accent-strong);
}

.title-saved {
  display: grid;
  place-items: center;
  color: var(--success);
  font-weight: 700;
  font-size: 16px;
}

.history-item span {
  color: var(--muted);
  font-size: 13px;
}

.history-actions {
  display: grid;
  gap: 8px;
}

.history-primary-actions,
.history-secondary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.history-secondary-actions.no-srt {
  grid-template-columns: 1fr;
}

.history-actions button,
.history-actions a,
.history-primary-actions button,
.history-primary-actions a,
.history-secondary-actions button,
.history-secondary-actions a {
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 12px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: all 140ms ease;
}

.history-actions button:hover,
.history-actions a:hover,
.history-primary-actions button:hover,
.history-primary-actions a:hover,
.history-secondary-actions button:hover,
.history-secondary-actions a:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: none;
}

.history-open {
  border-color: rgba(90, 167, 160, 0.34);
  color: var(--accent);
}

.empty {
  margin: 0;
  padding: 40px 24px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  line-height: 1.7;
}

/* ─── AUTH ─── */

.auth-page {
  overflow: auto;
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: 100%;
  max-width: 400px;
}

.auth-card {
  padding: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow);
}

.auth-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
}

.auth-subtitle {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 14px;
}

.auth-error {
  margin-bottom: 18px;
  padding: 12px 16px;
  background: var(--danger-soft);
  border: 1px solid rgba(224, 113, 113, 0.3);
  border-radius: var(--r-lg);
  color: var(--danger);
  font-size: 14px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-field {
  display: grid;
  gap: 6px;
}

.auth-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ─── ADMIN ─── */

.admin-shell {
  width: min(900px, calc(100% - 40px));
  margin: 0 auto;
  padding: 32px 0 60px;
  display: grid;
  gap: 24px;
}

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

.admin-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
}

.admin-nav {
  display: flex;
  gap: 8px;
}

.admin-nav-link {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  min-height: 38px;
  border-radius: var(--r-lg);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.admin-message {
  padding: 12px 16px;
  border-radius: var(--r-lg);
  font-size: 14px;
  background: var(--success-soft);
  border: 1px solid rgba(111, 207, 151, 0.3);
  color: var(--success);
}

.admin-message.error {
  background: var(--danger-soft);
  border-color: rgba(224, 113, 113, 0.3);
  color: var(--danger);
}

.admin-card {
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-sm);
}

.admin-card h2 {
  margin: 0 0 20px;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-end: end;
  margin-bottom: 14px;
}

.admin-checkbox-field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding-top: 22px;
}

.admin-checkbox {
  width: auto;
  min-height: auto;
  border: none;
}

.admin-create-btn {
  width: auto;
  min-height: 44px;
  padding: 0 24px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.admin-table th {
  text-align: left;
  padding: 0 12px 12px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 12px 12px 12px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

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

.admin-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.admin-badge-admin {
  background: var(--accent-soft);
  border-color: rgba(90, 167, 160, 0.3);
  color: var(--accent);
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.admin-inline-form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.admin-pw-input {
  width: 160px;
  min-height: 34px;
  font-size: 13px;
  padding: 0 10px;
}

.admin-sm-btn {
  width: auto;
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

/* ─── MOBILE ─── */

@media (max-width: 780px) {
  .shell {
    width: calc(100% - 24px);
    height: auto;
    min-height: 100vh;
    padding: 14px 0 40px;
  }

  body {
    overflow: auto;
  }

  .workspace,
  .work-grid {
    height: auto;
  }

  .work-grid,
  .upload-header {
    grid-template-columns: 1fr;
  }

  .upload-header {
    padding: 16px;
  }

  .progress {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .action-row,
  .history-bar,
  .history-heading,
  .history-tools,
  .result-bar,
  .result-tools,
  .result-footer {
    display: grid;
    grid-template-columns: 1fr;
  }

  .download-actions {
    display: flex;
    justify-content: stretch;
  }

  .download-actions a {
    flex: 1;
    justify-content: center;
  }

  .mode-switch {
    overflow-x: auto;
  }

  .mode-switch button {
    flex: 1 0 auto;
  }

  .search-field {
    min-width: 0;
  }

  .history-actions {
    display: grid;
    width: 100%;
  }

  .history-actions button,
  .history-actions a {
    flex: 1;
  }
}
