/* ═══════════════════════════════════════════
   Cloudflare KV Manager · 设计系统
═══════════════════════════════════════════ */
:root {
  --bg: #ebedf0;
  --card: #ffffff;
  --line: #e0e2e8;
  --txt: #1a1d23;
  --muted: #6a7180;
  --acc: #3a76f0;
  --acc-soft: rgba(58,118,240,0.08);
  --danger: #d94545;
  --danger-soft: rgba(217,69,69,0.08);
  --ok: #3aa55f;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.08);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
  --transition-smooth: 0.4s cubic-bezier(0.16,1,0.3,1);
}

[data-theme="dark"] {
  --bg: #0a0a0c;
  --card: #161618;
  --line: #2a2a2e;
  --txt: #e4e4e4;
  --muted: #888888;
  --acc: #4d8aff;
  --acc-soft: rgba(77,138,255,0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239,68,68,0.1);
  --ok: #22c55e;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
}

/* ═══════════════════════════════════════════
   基础重置
═══════════════════════════════════════════ */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-sans);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  transition: background var(--transition-smooth), color var(--transition-smooth);
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
  padding-top: env(safe-area-inset-top);
}

/* ═══════════════════════════════════════════
   桌面端居中容器
═══════════════════════════════════════════ */
.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background: var(--bg);
}

@media (min-width: 600px) {
  body { background: var(--bg); }
  .app-shell {
    box-shadow: var(--shadow-lg);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

/* ═══════════════════════════════════════════
   404 伪装层
═══════════════════════════════════════════ */
.notfound {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 18px;
  color: var(--muted);
}
.notfound-inner { text-align: center; }
.notfound h1 {
  margin: 0;
  font-weight: 700;
  font-size: 42px;
  color: var(--muted);
  opacity: 0.4;
}
.notfound p { margin: 8px 0 0; }

/* ═══════════════════════════════════════════
   管理界面
═══════════════════════════════════════════ */
.app { display: none; }
.app.on {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-sm);
}
header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  flex: 1;
}
header .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}
header .dot.err {
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger);
}

main {
  flex: 1;
  padding: 12px 16px 84px;
}

.tab-pane { display: none; }
.tab-pane.on {
  display: block;
  animation: paneIn 0.3s cubic-bezier(0.16,1,0.3,1) both;
}

@keyframes paneIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════
   表单元素
═══════════════════════════════════════════ */
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }

input, textarea, select {
  width: 100%;
  background: var(--card);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: inherit;
  outline: none;
  transition: all var(--transition);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--acc);
  box-shadow: 0 0 0 3px var(--acc-soft);
}
textarea {
  resize: none;
  min-height: 120px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 6px;
}

/* ═══════════════════════════════════════════
   按钮
═══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--acc);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  transition: all var(--transition);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--txt);
}
.btn.ghost:hover { background: var(--acc-soft); border-color: var(--acc); }

.btn.danger { background: var(--danger); }

.btn-sm {
  padding: 6px 12px;
  min-height: 32px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.theme-toggle {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--txt);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--acc);
  color: var(--acc);
  transform: rotate(20deg);
}

/* ═══════════════════════════════════════════
   列表
═══════════════════════════════════════════ */
.list-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
}
.list-item:hover {
  border-color: var(--acc);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.list-item:active { transform: scale(0.99); }
.list-item .k {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--txt);
  word-break: break-all;
}
.list-item .meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* ═══════════════════════════════════════════
   工具栏
═══════════════════════════════════════════ */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.toolbar input { flex: 1; }

/* ═══════════════════════════════════════════
   空状态 / 加载
═══════════════════════════════════════════ */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  font-size: 14px;
}

.kv-val {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 40vh;
  overflow: auto;
}

.spin {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--acc);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════
   Toast
═══════════════════════════════════════════ */
.toast {
  position: fixed;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  background: #2a2e3a;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s, top 0.25s;
  z-index: 1000;
  max-width: 80vw;
  word-break: break-all;
  box-shadow: var(--shadow-lg);
}
.toast.on { opacity: 1; top: 48px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ═══════════════════════════════════════════
   底部 Tab
═══════════════════════════════════════════ */
.tabs {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
@media (min-width: 600px) {
  .tabs {
    max-width: 560px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}
.tab {
  flex: 1;
  padding: 8px 0 6px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}
.tab.on { color: var(--acc); }
.tab .ico {
  display: block;
  font-size: 22px;
  margin-bottom: 2px;
}

/* ═══════════════════════════════════════════
   底部弹层 Modal
═══════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
  display: none;
  align-items: flex-end;
  justify-content: center;
  animation: fadeBg 0.25s ease;
}
@media (min-width: 600px) {
  .modal { align-items: center; }
}
.modal.on { display: flex; }

@keyframes fadeBg {
  from { background: rgba(0,0,0,0); }
  to { background: rgba(0,0,0,0.5); }
}

.modal .sheet {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow: auto;
  animation: sheetUp 0.3s cubic-bezier(0.16,1,0.3,1) both;
}
@media (min-width: 600px) {
  .modal .sheet {
    border-radius: var(--radius-lg);
  }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 700;
}
.modal .actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.modal .actions .btn { flex: 1; }

/* ═══════════════════════════════════════════
   关于页
═══════════════════════════════════════════ */
.about-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}
.about-card .k {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}
.about-card .v {
  font-size: 14px;
  color: var(--txt);
  word-break: break-all;
}
.about-card .v.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ═══════════════════════════════════════════
   滚动条
═══════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}

/* ═══════════════════════════════════════════
   减少动画
═══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
