/* 主题色只挂在 html[data-theme]，勿用 :root：:root 即 html，会与浅色规则层叠错乱 */
html {
  --radius: 12px;
  --radius-sm: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-gradient-mid: #1a2332;
  --surface: #151b24;
  --border: #263041;
  --text: #e6edf3;
  --muted: #8b9cb3;
  --input-bg: #0c1016;
  --code-bg: rgba(255, 255, 255, 0.06);
  --topbar-bg: rgba(15, 20, 25, 0.85);
  --card-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --btn-secondary-bg: #1a2230;
  --btn-default-bg: #1e2633;
  --btn-default-hover: #252f3f;
  --flash-success-text: #bbf7d0;
  --flash-danger-text: #fecaca;
  --focus-ring: rgba(59, 130, 246, 0.18);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f6;
  --bg-gradient-mid: #e2e8f0;
  --surface: #ffffff;
  --border: #d1dae6;
  --text: #0f172a;
  --muted: #64748b;
  --input-bg: #f8fafc;
  --code-bg: rgba(15, 23, 42, 0.06);
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --card-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.1);
  --success: #16a34a;
  --success-bg: rgba(22, 163, 74, 0.1);
  --btn-secondary-bg: #f1f5f9;
  --btn-default-bg: #f1f5f9;
  --btn-default-hover: #e2e8f0;
  --flash-success-text: #166534;
  --flash-danger-text: #991b1b;
  --focus-ring: rgba(37, 99, 235, 0.2);
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  background-color: var(--bg);
  background-image: radial-gradient(
      900px 480px at 12% -8%,
      var(--bg-gradient-mid) 0%,
      transparent 55%
    ),
    radial-gradient(600px 400px at 92% 8%, rgba(59, 130, 246, 0.06) 0%, transparent 45%);
  color: var(--text);
  line-height: 1.55;
  letter-spacing: 0.01em;
  -webkit-text-size-adjust: 100%;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

::selection {
  background: rgba(59, 130, 246, 0.28);
  color: inherit;
}

html[data-theme="light"] ::selection {
  background: rgba(37, 99, 235, 0.2);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code {
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: env(safe-area-inset-top, 0);
}

html[data-theme="light"] .topbar {
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.85rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.brand-block {
  min-width: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  flex-shrink: 0;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1;
  letter-spacing: 0;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.38);
  user-select: none;
}

html[data-theme="light"] .brand-logo {
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.28);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

@media (min-width: 480px) {
  .brand-text {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.45rem 0.65rem;
  }
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.9;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem 1.35rem;
  flex-wrap: wrap;
}

/* 主题与退出之间加大间距，减少误触 */
.topbar-actions .logout {
  margin-left: 0.35rem;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-size: 1.08rem;
  line-height: 1.2;
}

.brand-link:hover .brand {
  color: var(--accent);
}

.brand-link:hover .brand-logo {
  filter: brightness(1.07);
  box-shadow: 0 3px 14px rgba(59, 130, 246, 0.5);
}

html[data-theme="light"] .brand-link:hover .brand-logo {
  box-shadow: 0 3px 14px rgba(37, 99, 235, 0.35);
}

.theme-toggle,
.btn-toolbar {
  min-height: 44px;
  min-width: 44px;
  padding: 0.45rem 0.85rem;
  touch-action: manipulation;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-refresh-icon {
  display: inline-block;
  font-size: 1.05rem;
  line-height: 1;
  margin-right: 0.2rem;
  opacity: 0.85;
  transition: transform 0.35s ease;
}

#force-refresh-btn:active .btn-refresh-icon {
  transform: rotate(-200deg);
}

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

.btn-ghost:focus-visible {
  outline-color: var(--accent);
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
  padding-bottom: calc(2.5rem + env(safe-area-inset-bottom, 0));
}

/* 视口居中提示，不占主内容流 */
.toast-container {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: max(1rem, env(safe-area-inset-top, 0)) max(1rem, env(safe-area-inset-right, 0))
    max(1rem, env(safe-area-inset-bottom, 0)) max(1rem, env(safe-area-inset-left, 0));
  pointer-events: none;
  box-sizing: border-box;
}

.toast {
  pointer-events: auto;
  width: min(22rem, calc(100vw - 2rem));
  padding: 0.75rem 1rem;
  padding-left: 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left-width: 3px;
  font-size: 0.92rem;
  line-height: 1.45;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(0.5rem) scale(0.98);
  animation: toast-in 0.35s ease forwards;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

@keyframes toast-in {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.toast-out {
  opacity: 0;
  transform: translateY(-0.35rem) scale(0.98);
  animation: none;
}

.toast-success {
  border-color: rgba(34, 197, 94, 0.35);
  border-left-color: var(--success);
  background: var(--success-bg);
  color: var(--flash-success-text);
}

.toast-danger {
  border-color: rgba(239, 68, 68, 0.35);
  border-left-color: var(--danger);
  background: var(--danger-bg);
  color: var(--flash-danger-text);
}

.toast-info {
  border-left-color: var(--muted);
  color: var(--text);
  background: var(--surface);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.15rem;
  box-shadow: var(--card-shadow);
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.card:hover {
  border-color: rgba(59, 130, 246, 0.22);
}

html[data-theme="light"] .card:hover {
  border-color: rgba(37, 99, 235, 0.2);
}

.login-card {
  max-width: 420px;
  margin: 2rem auto;
  padding: 1.5rem 1.5rem;
}

.h1 {
  font-size: 1.5rem;
  margin: 0 0 0.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.h2 {
  font-size: 1.15rem;
  margin: 0 0 0.65rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.h2::before {
  content: "";
  width: 3px;
  height: 1em;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), #6366f1);
  flex-shrink: 0;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
  line-height: 1.55;
}

th .small-hint {
  display: inline;
  margin: 0;
  font-size: 0.72rem;
  font-weight: 400;
}

.time-cell {
  white-space: normal;
  max-width: 18rem;
  vertical-align: top;
}

.time-stack {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  line-height: 1.45;
  font-size: 0.88rem;
}

.time-utc,
.time-cn {
  margin: 0;
}

.time-label {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-right: 0.35rem;
  vertical-align: middle;
}

.time-cn .time-label {
  color: var(--accent);
}

.time-zone-hint {
  font-size: 0.78em;
  color: var(--muted);
  font-weight: 400;
  margin-left: 0.2rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.stack.tight {
  gap: 0.45rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.label {
  font-size: 0.85rem;
  color: var(--muted);
}

.input,
.textarea {
  width: 100%;
  max-width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: rgba(59, 130, 246, 0.55);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.input:focus-visible,
.textarea:focus-visible {
  outline: none;
}

.input-sm {
  padding: 0.45rem 0.55rem;
  font-size: 16px;
}

.textarea-sm {
  min-height: 3rem;
  resize: vertical;
  font-size: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.9rem;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  background: var(--btn-default-bg);
  border-color: var(--border);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease;
}

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

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  border-color: rgba(59, 130, 246, 0.4);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

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

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

.btn-sm {
  min-height: 40px;
  padding: 0.4rem 0.65rem;
  font-size: 0.88rem;
}

.btn-danger {
  background: var(--danger-bg);
  border-color: rgba(239, 68, 68, 0.35);
  color: var(--danger);
}
html[data-theme="light"] .btn-danger {
  color: #b91c1c;
}
.btn-danger:hover {
  filter: brightness(1.05);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.section-head .h2 {
  flex: 1 1 auto;
  min-width: min(100%, 12rem);
}

.section-head .muted {
  flex: 1 1 100%;
  margin-bottom: 0;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.15rem;
  scrollbar-width: thin;
}

.table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.table th,
.table td {
  padding: 0.65rem 0.45rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.nowrap {
  white-space: nowrap;
}

.col-actions {
  width: 1%;
  min-width: 130px;
}

.rename-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: stretch;
}

.rename-row .input {
  min-width: 0;
  flex: 1 1 140px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.inline-form {
  margin: 0;
}

.inline {
  display: inline;
}

.upload-form {
  max-width: 520px;
}

/* 移动端：表格改为卡片块 */
@media (max-width: 768px) {
  .table-wrap {
    overflow-x: visible;
    margin: 0;
  }

  .table {
    min-width: 0;
    display: block;
  }

  .table thead {
    display: none;
  }

  .table tbody {
    display: block;
  }

  .table tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 0.9rem;
    margin-bottom: 0.85rem;
    background: var(--input-bg);
  }

  html[data-theme="light"] .table tr {
    background: #f8fafc;
  }

  .table td {
    display: block;
    border: none;
    padding: 0.55rem 0;
    width: 100%;
  }

  .table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.35rem;
  }

  .table td:last-child {
    padding-bottom: 0;
  }

  .col-actions {
    min-width: 0;
  }

  .action-row {
    flex-direction: row;
    justify-content: flex-start;
  }

  .rename-row {
    flex-direction: column;
  }

  .rename-row .btn {
    width: 100%;
  }

  .table td[data-label="大小"] {
    display: none;
  }
}
