/* ==========================================================================
   Humming 云盘 —— 全局样式
   移动优先：基础样式面向小屏，@media (min-width: 640px) 起逐步放大
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --bg-soft: #eef0f4;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #14181f;
  --text-soft: #5b6472;
  --text-faint: #8a93a1;
  --accent: #2f6df6;
  --accent-hover: #1f57d0;
  --accent-soft: rgba(47, 109, 246, 0.1);
  --danger: #d13c3c;
  --danger-soft: rgba(209, 60, 60, 0.1);
  --ok: #1f9d55;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --bg-elevated: #141c2b;
    --bg-soft: #1b2434;
    --border: #26303f;
    --border-strong: #38455a;
    --text: #e7ecf3;
    --text-soft: #a3adbd;
    --text-faint: #7b8697;
    --accent: #5b8dff;
    --accent-hover: #7aa2ff;
    --accent-soft: rgba(91, 141, 255, 0.14);
    --danger: #ef6a6a;
    --danger-soft: rgba(239, 106, 106, 0.14);
    --ok: #4ac585;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── 顶栏 ────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 10px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
  letter-spacing: 0.01em;
  min-width: 0;
}

.brand-mark {
  font-size: 20px;
  line-height: 1;
}

.brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-user {
  font-size: 13px;
  color: var(--text-soft);
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 4px 11px;
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

/* ── 布局 ────────────────────────────────────────────────────────────── */

.container {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 16px 40px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}

.footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

/* ── 卡片 / 面板 ─────────────────────────────────────────────────────── */

.card,
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
  margin-bottom: 16px;
}

.upload-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.panel-title {
  font-size: 16px;
  font-weight: 650;
  margin: 0;
}

.hint {
  font-size: 12.5px;
  color: var(--text-faint);
}

/* ── 按钮 ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--bg-soft);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

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

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-soft);
}

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

.btn-danger-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--danger);
}

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

.btn-sm {
  min-height: 34px;
  padding: 0 11px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

/* ── 表单 ────────────────────────────────────────────────────────────── */

.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 6px;
  font-weight: 550;
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 防止 iOS 聚焦时自动放大 */
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ── 登录页 ──────────────────────────────────────────────────────────── */

.login-wrap,
.error-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 0;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 22px;
}

.login-head {
  text-align: center;
  margin-bottom: 22px;
}

.login-logo {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 8px;
}

.login-title {
  font-size: 20px;
  margin: 0 0 4px;
  font-weight: 680;
}

.login-sub {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-faint);
}

/* ── 错误页 ──────────────────────────────────────────────────────────── */

.error-card {
  width: 100%;
  max-width: 420px;
  padding: 32px 24px;
  text-align: center;
}

.error-code {
  font-size: 46px;
  font-weight: 750;
  color: var(--accent);
  line-height: 1;
}

.error-title {
  font-size: 18px;
  margin: 10px 0 6px;
}

.error-message {
  color: var(--text-soft);
  margin: 0 0 20px;
  overflow-wrap: anywhere;
}

.error-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── 提示条 ──────────────────────────────────────────────────────────── */

.alert {
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 13.5px;
  margin-bottom: 16px;
  overflow-wrap: anywhere;
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid transparent;
}

/* ── 上传区 ──────────────────────────────────────────────────────────── */

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-direction: column;
  text-align: center;
  min-height: 132px;
  padding: 20px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-icon {
  font-size: 26px;
  line-height: 1;
}

.dropzone-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14.5px;
}

.dropzone-sub {
  font-size: 12.5px;
  color: var(--text-faint);
}

/* ── 上传进度 ────────────────────────────────────────────────────────── */

.progress {
  margin-top: 14px;
}

.progress-track {
  height: 7px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.2s ease;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
  color: var(--text-soft);
  margin-top: 7px;
}

.progress-info span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 文件列表 ────────────────────────────────────────────────────────── */

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.file-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-areas:
    'icon main'
    'actions actions';
  gap: 4px 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  transition: border-color 0.15s ease, opacity 0.15s ease;
}

.file-row.is-removing {
  opacity: 0.4;
}

.file-icon {
  grid-area: icon;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  line-height: 1;
}

.file-main {
  grid-area: main;
  min-width: 0;
}

.file-name {
  display: block;
  color: var(--text);
  font-weight: 550;
  font-size: 14.5px;
  text-decoration: none;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.file-name:hover {
  color: var(--accent);
  text-decoration: underline;
}

.file-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 2px;
}

.dot {
  opacity: 0.5;
}

.file-actions {
  grid-area: actions;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 1px solid var(--border);
}

.file-actions .btn {
  flex: 1 1 auto;
  min-width: 84px;
}

/* ── 空状态 ──────────────────────────────────────────────────────────── */

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-faint);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.empty-text {
  margin: 0;
  font-size: 14px;
}

/* ── 查看页 ──────────────────────────────────────────────────────────── */

.viewer-bar {
  margin-bottom: 14px;
}

.viewer-panel {
  padding: 14px;
}

.viewer-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.viewer-title-wrap {
  min-width: 0;
}

.viewer-title {
  font-size: 17px;
  font-weight: 650;
  margin: 0 0 4px;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.viewer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.viewer-actions .btn {
  flex: 1 1 auto;
}

.preview {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}

.preview-image img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 74vh;
  object-fit: contain;
  margin: 0 auto;
  background: var(--bg-soft);
}

.preview-image.is-broken {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-soft);
  font-size: 14px;
}

.preview-media {
  padding: 12px;
}

.preview-media video {
  display: block;
  width: 100%;
  max-height: 74vh;
  border-radius: var(--radius-sm);
  background: #000;
}

.preview-media audio {
  display: block;
  width: 100%;
}

.preview-frame iframe {
  display: block;
  width: 100%;
  height: 74vh;
  min-height: 420px;
  border: 0;
  background: var(--bg-elevated);
}

.preview-text {
  max-height: 74vh;
  overflow: auto;
}

.preview-text pre {
  margin: 0;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}

.preview-empty {
  text-align: center;
  padding: 48px 18px;
  color: var(--text-soft);
}

.preview-empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.preview-empty p {
  margin: 0 0 16px;
}

/* ── Toast ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg-elevated);
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.is-error {
  background: var(--danger);
  color: #fff;
}

/* ── 宽屏增强 ────────────────────────────────────────────────────────── */

@media (min-width: 640px) {
  body {
    font-size: 15px;
  }

  .container {
    padding-top: 26px;
  }

  .panel {
    padding: 20px;
  }

  .dropzone {
    flex-direction: row;
    justify-content: flex-start;
    min-height: 108px;
    text-align: left;
  }

  .file-row {
    grid-template-columns: 44px 1fr auto;
    grid-template-areas: 'icon main actions';
    gap: 14px;
    padding: 12px 14px;
  }

  .file-actions {
    padding-top: 0;
    margin-top: 0;
    border-top: 0;
    justify-content: flex-end;
  }

  .file-actions .btn {
    flex: 0 0 auto;
    min-width: 0;
  }

  .viewer-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .viewer-actions .btn {
    flex: 0 0 auto;
  }
}

/* 超宽屏限制正文宽度，避免行太长 */
@media (min-width: 1200px) {
  .container,
  .topbar-inner {
    max-width: 1040px;
  }
}

/* 尊重系统的"减少动效"设置 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
