:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border: #e5e7eb;
  --danger: #dc2626;
  --ok: #059669;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #eef2ff 0%, var(--bg) 40%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.page {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: calc(32px + var(--safe-top)) calc(16px + var(--safe-right))
    calc(48px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.header h1 {
  margin: 0;
  font-size: clamp(22px, 5vw, 28px);
  line-height: 1.25;
  word-break: break-word;
}

.nav-link {
  flex-shrink: 0;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: clamp(16px, 3vw, 24px);
  box-shadow: var(--shadow);
}

.section-title {
  margin: 0 0 16px;
  font-size: 18px;
}

.guest-box {
  margin-bottom: 16px;
}

.guest-box label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

input[type="password"],
input[type="text"] {
  width: 100%;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.dropzone {
  border: 2px dashed #c7d2fe;
  border-radius: 14px;
  background: #f8fafc;
  padding: clamp(28px, 6vw, 40px) 16px;
  text-align: center;
  cursor: pointer;
  transition: 0.2s ease;
  touch-action: manipulation;
  user-select: none;
}

.dropzone.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}

.drop-title {
  margin: 0 0 8px;
  font-size: clamp(16px, 4vw, 18px);
  font-weight: 600;
}

.drop-title .mobile-only {
  display: none;
}

.drop-title .desktop-only {
  display: inline;
}

.drop-sub,
.drop-tip,
.empty-tip {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.drop-tip {
  margin-top: 8px;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 42px;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.danger {
  color: var(--danger);
  border-color: #fecaca;
}

.btn.btn-sm {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.file-list {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
}

.file-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.file-item:last-child {
  border-bottom: none;
}

.file-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.file-main {
  flex: 1;
  min-width: 0;
}

.file-name {
  word-break: break-all;
  font-size: 14px;
  font-weight: 600;
}

.file-status {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.file-status.is-error {
  color: var(--danger);
}

.file-item.status-done .file-status {
  color: var(--ok);
}

.file-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.file-progress {
  margin-top: 10px;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #60a5fa, #2563eb);
  transition: width 0.15s ease;
}

.file-item.status-done .progress-bar {
  background: linear-gradient(90deg, #34d399, #059669);
}

.result-box {
  margin-top: 20px;
  padding: 16px;
  border-radius: 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.result-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #bbf7d0;
}

.result-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.result-info {
  flex: 1;
  min-width: 0;
}

.result-info a {
  color: var(--ok);
  word-break: break-all;
}

.result-actions {
  flex-shrink: 0;
}

body.modal-open {
  overflow: hidden;
}

.modal-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px calc(16px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: #fff;
}

.preview-url-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.preview-url-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.preview-url-row input,
.modal-footer input {
  flex: 1;
  min-width: 0;
  max-width: none;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  background: #f8fafc;
  color: var(--text);
}

.preview-url-row .btn,
.modal-footer .btn {
  flex-shrink: 0;
  width: auto;
}

.error-box {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  word-break: break-word;
}

.login-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.error-text {
  color: var(--danger);
  min-height: 20px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar .section-title {
  margin: 0;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 14px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.filter-field input[type='date'] {
  min-width: 160px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.page-info {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.pagination .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.ops {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(12px + var(--safe-top)) calc(12px + var(--safe-right))
    calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal-content {
  position: relative;
  width: min(900px, 100%);
  max-height: calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom));
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-header .btn {
  flex-shrink: 0;
  width: auto;
}

.modal-body {
  padding: 16px;
  overflow: auto;
  text-align: center;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.modal-body img,
.modal-body video {
  max-width: 100%;
  max-height: min(70vh, calc(100dvh - 220px));
  width: auto;
  height: auto;
  border-radius: 8px;
  background: #000;
}

@media (max-width: 768px) {
  .page {
    padding: calc(20px + var(--safe-top)) calc(12px + var(--safe-right))
      calc(28px + var(--safe-bottom)) calc(12px + var(--safe-left));
  }

  .card {
    border-radius: 14px;
  }

  .drop-title .mobile-only {
    display: inline;
  }

  .drop-title .desktop-only {
    display: none;
  }

  .actions {
    flex-direction: column;
  }

  .actions .btn,
  .login-row .btn,
  .login-row input,
  .guest-box input {
    width: 100%;
    max-width: none;
  }

  .login-row {
    flex-direction: column;
    align-items: stretch;
  }

  .file-list li,
  .file-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .file-meta {
    justify-content: flex-end;
    white-space: normal;
  }

  .file-meta .btn {
    width: auto;
    min-width: 72px;
  }

  .result-item {
    flex-direction: column;
    align-items: stretch;
  }

  .result-actions .btn {
    width: 100%;
  }

  .preview-url-row {
    flex-direction: column;
    align-items: stretch;
  }

  .preview-url-row .btn,
  .modal-footer .btn {
    width: 100%;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .toolbar .btn {
    width: auto;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-field input[type='date'] {
    width: 100%;
    min-width: 0;
  }

  .filter-actions .btn {
    flex: 1;
  }

  .pagination {
    gap: 8px;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tbody tr {
    margin-bottom: 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafafa;
  }

  tbody tr:last-child {
    margin-bottom: 0;
  }

  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    text-align: right;
    word-break: break-word;
  }

  tbody td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  tbody td:first-child {
    padding-top: 0;
    font-weight: 600;
  }

  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
    max-width: 40%;
  }

  tbody td.ops-cell {
    display: block;
  }

  tbody td.ops-cell::before {
    display: block;
    margin-bottom: 8px;
    max-width: none;
  }

  .ops {
    width: 100%;
  }

  .ops .btn {
    flex: 1 1 calc(33.33% - 8px);
    min-width: 72px;
  }

  .modal-content {
    border-radius: 12px;
  }

  .modal-header .btn {
    width: auto;
    min-width: 64px;
  }
}

@media (max-width: 480px) {
  .header {
    align-items: flex-start;
  }

  .nav-link {
    font-size: 14px;
  }

  .ops {
    flex-direction: column;
  }

  .ops .btn {
    width: 100%;
    flex: none;
  }

  .modal {
    padding: 0;
    align-items: stretch;
  }

  .modal-content,
  .modal-content.preview-modal {
    width: 100%;
    max-height: none;
    height: 100dvh;
    height: 100%;
    border-radius: 0;
  }

  .modal-header {
    padding-top: calc(12px + var(--safe-top));
  }

  .modal-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
  }

  .modal-body img,
  .modal-body video {
    max-height: none;
    max-width: 100%;
    width: 100%;
    height: auto;
    object-fit: contain;
  }

  .modal-body video {
    max-height: calc(100dvh - 220px - var(--safe-top) - var(--safe-bottom));
  }

  .modal-footer {
    padding-bottom: calc(16px + var(--safe-bottom));
  }
}
