/* ============ PhotoBuddy 主题 ============ */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #171a1f;
  --text-2: #3d4450;
  --text-3: #57606c;
  --muted: #8a919c;
  --border: #e7e9ee;
  --hover: #f2f4f7;
  --card: #e8eaef;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #e5484d;
  --toolbar-bg: rgba(245, 246, 248, .85);
  --selectbar-border: #dfe3ff;
  --btn-hover-border: #cfd4dd;
  --btn-primary-hover: #4338ca;
  --btn-danger-hover: #d23b40;
  --btn-ghost-hover: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --radius: 14px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #161a21;
  --text: #e7e9ee;
  --text-2: #c6ccd6;
  --text-3: #9aa1ad;
  --muted: #8a919c;
  --border: #2b3140;
  --hover: #222733;
  --card: #262b36;
  --accent: #8b90ff;
  --accent-soft: #2a2f45;
  --danger: #f06a70;
  --toolbar-bg: rgba(15, 17, 21, .82);
  --selectbar-border: #3c4770;
  --btn-hover-border: #3a4150;
  --btn-primary-hover: #6b71ff;
  --btn-danger-hover: #dc5f66;
  --btn-ghost-hover: #2a2f39;
  --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 12px 30px rgba(0, 0, 0, .55);
  --radius: 14px;
  color-scheme: dark;
}

body, .sidebar, .toolbar, .lb-panel, .modal-card, .settings-card {
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; }
svg { display: block; }
[hidden] { display: none !important; }

.app { display: flex; min-height: 100vh; }

/* ============ 侧栏 ============ */
.sidebar {
  width: 250px; flex: none;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px 14px;
  font-size: 17px; font-weight: 650; letter-spacing: .2px;
}
.brand svg { width: 26px; height: 26px; color: var(--accent); }

.nav { padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 0; background: none; border-radius: 10px;
  color: var(--text-2); text-align: left;
}
.nav-item svg { width: 17px; height: 17px; color: var(--muted); }
.nav-item em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }

.timeline-head {
  display: flex; align-items: center; gap: 8px;
  padding: 18px 20px 8px;
  font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .6px;
}
.timeline-head svg { width: 14px; height: 14px; }
.timeline { flex: 1; overflow: auto; padding: 0 12px 12px; }
.timeline-empty { padding: 8px 12px; color: var(--muted); font-size: 13px; }

.tl-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border: 0; background: none; border-radius: 9px;
  color: var(--text-2); text-align: left;
}
.tl-row:hover { background: var(--hover); }
.tl-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tl-row em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); }
.tl-row.active em { color: var(--accent); opacity: .7; }
.tl-caret { width: 14px; height: 14px; color: var(--muted); transition: transform .15s ease; flex: none; }
.tl-year:not(.open) > .tl-year-btn .tl-caret { transform: rotate(-90deg); }
.tl-months { display: none; padding-left: 14px; }
.tl-year.open .tl-months { display: block; }
.tl-days { display: none; padding-left: 22px; }
.tl-month.open .tl-days { display: block; }
.tl-day {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 10px; border: 0; background: none; border-radius: 8px;
  color: var(--text-3); font-size: 13px; text-align: left;
}
.tl-day:hover { background: var(--hover); }
.tl-day.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tl-day em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); }

.sidebar-foot {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 12px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.foot-status { display: flex; gap: 8px; align-items: center; padding: 0 4px; }
.foot-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.foot-dir {
  color: var(--text-2); font-weight: 500; max-width: 184px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.foot-sub { color: var(--muted); font-size: 11px; }
.sidebar-foot .nav-item { padding: 8px 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 3px; }
.dot.ok { background: #22c55e; }
.dot.busy { background: #f59e0b; animation: pulse 1.2s infinite; }
.dot.warn { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* ============ 主区 ============ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 16px 28px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.toolbar h1 { margin: 0; font-size: 18px; font-weight: 650; }
.toolbar-left { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); }

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 12px; width: 240px;
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 15px; height: 15px; color: var(--muted); flex: none; }
.search input { border: 0; outline: 0; width: 100%; background: none; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font-weight: 500; transition: all .15s ease;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { border-color: var(--btn-hover-border); box-shadow: 0 1px 3px rgba(16, 24, 40, .08); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--btn-primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: var(--btn-danger-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--btn-ghost-hover); color: var(--text); box-shadow: none; }
.icon-btn { padding: 8px 10px; }
.icon-btn svg { width: 17px; height: 17px; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }

.selectbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 28px;
  background: var(--accent-soft); border-bottom: 1px solid var(--selectbar-border);
  color: var(--accent); font-weight: 600;
}

.content { padding: 22px 28px 60px; }

/* ============ 照片网格 ============ */
.day-group { margin-bottom: 30px; }
.day-head { display: flex; align-items: baseline; gap: 10px; margin: 0 2px 12px; }
.day-head h2 { margin: 0; font-size: 15px; font-weight: 650; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 12px;
}
.card {
  position: relative; margin: 0;
  border-radius: 12px; overflow: hidden;
  background: var(--card); aspect-ratio: 1 / 1;
  cursor: zoom-in;
  border: 2px solid transparent;
  transition: transform .18s ease, box-shadow .18s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .3s ease;
}
.card img.loaded { opacity: 1; }
.card figcaption {
  position: absolute; inset: auto 0 0 0; padding: 20px 10px 8px;
  display: flex; flex-direction: column; gap: 1px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .55));
  color: #fff; opacity: 0; transition: opacity .18s ease;
  pointer-events: none;
}
.card:hover figcaption { opacity: 1; }
.card-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-date { font-size: 11px; opacity: .8; }
.card-dur { font-size: 11px; font-weight: 600; opacity: .9; }
.card-note {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px;
  border-radius: 50%; background: rgba(0, 0, 0, .45); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.card-note svg { width: 12px; height: 12px; }
.card-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(0, 0, 0, .4); color: #fff;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.card-play svg { width: 20px; height: 20px; }
.card-check {
  position: absolute; top: 8px; left: 8px; width: 22px; height: 22px;
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, .9);
  background: rgba(0, 0, 0, .25);
  display: none; align-items: center; justify-content: center; color: transparent;
}
.card-check svg { width: 13px; height: 13px; }
body.selecting .card-check { display: flex; }
body.selecting .card { cursor: pointer; }
.card.selected { border-color: var(--accent); }
.card.selected .card-check { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ============ 回收站 ============ */
.trash-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 2px 16px;
}
.trash-bar span { color: var(--muted); font-size: 13px; }
.trash-bar .btn { margin-left: auto; }
.trash-grid .card { cursor: default; }
.trash-caption {
  position: absolute; inset: auto 0 0 0; padding: 14px 8px 40px;
  display: flex; flex-direction: column; gap: 2px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .62));
  color: #fff; pointer-events: none; opacity: 1;
}
.trash-path { font-size: 10px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trash-meta { font-size: 10px; opacity: .8; }
.trash-actions { position: absolute; inset: auto 8px 8px auto; }
.trash-actions .btn { padding: 4px 10px; font-size: 12px; }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ============ 重复媒体 ============ */
.dupes-bar { display: flex; align-items: center; gap: 10px; margin: 0 2px 16px; }
.dupes-bar span { color: var(--muted); font-size: 13px; }
.dupes-group { margin-bottom: 26px; }
.dupes-head { display: flex; align-items: center; gap: 10px; margin: 0 2px 12px; flex-wrap: wrap; }
.dupes-head b { font-size: 14px; }
.dupes-head code { background: var(--hover); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 11px; color: var(--text-3); }
.dupes-head .btn { margin-left: auto; }
.dupes-caption { position: absolute; inset: auto 0 0 0; padding: 8px; background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .62)); color: #fff; pointer-events: none; opacity: 1; }

/* ============ 状态区 ============ */
.state {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 90px 0; color: var(--muted); text-align: center;
}
.state svg { width: 46px; height: 46px; opacity: .5; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 灯箱 ============ */
.lightbox { position: fixed; inset: 0; z-index: 100; display: flex; }
.lb-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 16, .94); }
.lb-stage {
  position: relative; flex: 1; margin: 0;
  display: flex; align-items: center; justify-content: center; min-width: 0;
}
.lb-stage img {
  max-width: calc(100% - 96px); max-height: calc(100vh - 96px);
  width: auto; height: auto; min-width: 0; min-height: 0; object-fit: contain;
  border-radius: 6px; box-shadow: 0 12px 60px rgba(0, 0, 0, .5);
  transition: opacity .2s ease;
}
.lb-stage video {
  max-width: calc(100% - 96px); max-height: calc(100vh - 96px);
  width: auto; height: auto; min-width: 0; min-height: 0; object-fit: contain;
  border-radius: 12px; box-shadow: 0 12px 60px rgba(0, 0, 0, .5);
  background: #000;
}
.lb-spinner {
  position: absolute; width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .2); border-top-color: #fff;
  animation: spin .8s linear infinite; display: none;
}
.lb-spinner.show { display: block; }
.lb-btn {
  position: absolute; z-index: 5; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .08); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lb-btn:hover { background: rgba(255, 255, 255, .18); }
.lb-btn svg { width: 20px; height: 20px; }
.lb-close { top: 18px; left: 18px; }
.lb-prev { left: 18px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 342px; top: 50%; transform: translateY(-50%); }

.lb-panel {
  position: relative; z-index: 4; width: 320px; flex: none;
  background: var(--panel); padding: 26px 22px; overflow: auto;
  display: flex; flex-direction: column; gap: 14px;
}
.lb-panel h2 { margin: 0; font-size: 15px; word-break: break-all; }
.lb-meta { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.lb-meta div { display: flex; justify-content: space-between; gap: 12px; }
.lb-meta dt { color: var(--muted); flex: none; }
.lb-meta dd { margin: 0; text-align: right; word-break: break-all; color: var(--text-2); }
.lb-note-label { font-size: 12px; font-weight: 600; color: var(--muted); }
#lb-note { resize: vertical; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none; }
#lb-note:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.lb-actions { display: flex; flex-wrap: wrap; gap: 8px; }
body.lb-open { overflow: hidden; }

/* ============ 标签 ============ */
.lb-tags { display: flex; flex-direction: column; gap: 8px; }
.lb-tag-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 3px 8px 3px 10px; font-size: 12px; font-weight: 500;
}
.chip-x {
  border: 0; background: none; color: var(--accent); font-size: 14px; line-height: 1;
  padding: 0 2px; cursor: pointer; opacity: .7;
}
.chip-x:hover { opacity: 1; }
#lb-tags-input { border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; outline: none; }
#lb-tags-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; }
.card-tags i {
  font-style: normal; font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: rgba(255,255,255,.25); color: #fff;
}

/* ============ 对话框 ============ */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16, 20, 28, .45); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; width: min(430px, calc(100vw - 40px));
  background: var(--panel); border-radius: 16px; padding: 24px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h2 { margin: 0; font-size: 16px; }
.modal-card p { margin: 0; line-height: 1.6; }
.modal-card input {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; outline: none; width: 100%;
}
.modal-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ============ 设置页 ============ */
.settings { max-width: 720px; display: flex; flex-direction: column; gap: 16px; }
.settings-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.settings-card h2 { margin: 0; font-size: 15px; }
.settings-card p { margin: 0; line-height: 1.7; }
.settings-row { display: flex; gap: 10px; }
.settings-row input {
  flex: 1; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
.settings-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.settings-stats { display: flex; gap: 26px; padding-top: 4px; }
.settings-stats div { display: flex; flex-direction: column; gap: 2px; }
.settings-stats b { font-size: 18px; }
.settings-stats span { color: var(--muted); font-size: 12px; }
.settings-row input[readonly] { opacity: .8; cursor: not-allowed; }
.settings code {
  background: var(--hover); border: 1px solid var(--border); border-radius: 5px;
  padding: 1px 6px; font-size: 12px; color: var(--text-3);
}

/* ============ 相册 ============ */
.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.album-card {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 18px 16px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
  color: inherit;
  text-align: left;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.album-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.album-card svg { width: 34px; height: 34px; color: var(--accent); }
.album-name { font-size: 15px; font-weight: 600; color: var(--text); word-break: break-all; }
.album-count { font-size: 12px; color: var(--muted); }

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none;
  transition: all .25s ease; z-index: 300; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ============ 响应式 ============ */
@media (max-width: 960px) {
  .sidebar { display: none; }
  .toolbar { padding: 14px 16px; flex-wrap: wrap; }
  .toolbar-right { width: 100%; }
  .search { flex: 1; width: auto; }
  .content { padding: 16px 16px 50px; }
  .lb-next { right: 18px; }
  .lb-panel { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
}

/* ============ 登录 ============ */
.login {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px;
}
.login[hidden] { display: none; }
.login-card {
  width: min(360px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-brand svg { width: 28px; height: 28px; color: var(--accent); }
.login-brand h1 { margin: 0; font-size: 20px; }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.login-field input {
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-size: 14px; outline: none;
}
.login-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-err { color: var(--danger); font-size: 12px; min-height: 16px; margin: 0; word-break: break-all; }
