:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --ink: #2a2a2a;
  --muted: #6b6b6b;
  --line: #e7e3da;
  --primary: #3b6e8f;
  --primary-dark: #2a5570;
  --accent: #c98b56;
  --danger: #b3563f;
  --ok: #4f7a4a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Noto Sans TC', sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 240px;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
}
.brand {
  padding: 8px 20px 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.brand a { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 18px; text-decoration: none; }
.brand-icon { font-size: 22px; }

.sidebar nav { padding: 0 8px; }
.nav-group {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
  padding: 14px 12px 4px;
  text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg); text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item span { width: 20px; display: inline-block; text-align: center; }

.version { padding: 16px 20px; color: var(--muted); font-size: 11px; }

.menu-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 8px;
  width: 40px; height: 40px;
  font-size: 18px; cursor: pointer; z-index: 100;
}

/* ---- Main ---- */
.content {
  margin-left: 240px;
  padding: 24px 32px 80px;
  max-width: 1100px;
}
.content.full { margin-left: 0; max-width: 480px; margin-top: 8vh; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 4px 24px rgba(0,0,0,.15); }
  .menu-toggle { display: block; }
  .content { margin-left: 0; padding: 56px 16px 80px; }
}

/* ---- Flash ---- */
.flashes { margin-bottom: 16px; }
.flash {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 8px;
  background: #fff; border: 1px solid var(--line);
}
.flash.success { border-color: var(--ok); color: var(--ok); }
.flash.error { border-color: var(--danger); color: var(--danger); }

/* ---- Page header ---- */
.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.page-title { margin: 0; font-size: 24px; }
.page-title .icon { margin-right: 6px; }
.page-subtitle { color: var(--muted); margin: 4px 0 0; font-size: 14px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink);
  font-size: 14px; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-link { background: none; border: none; padding: 0; color: var(--primary); cursor: pointer; }

/* ---- Cards / Grid ---- */
.card {
  background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ---- Forms ---- */
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block; margin-bottom: 4px;
  font-size: 13px; color: var(--muted); font-weight: 500;
}
.form-row input[type=text],
.form-row input[type=password],
.form-row input[type=number],
.form-row input[type=date],
.form-row input[type=email],
.form-row input[type=url],
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
.form-row textarea { min-height: 80px; resize: vertical; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }

/* ---- Table ---- */
table.list {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
table.list th, table.list td {
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
table.list th { background: var(--bg); color: var(--muted); font-weight: 500; font-size: 12px; }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: var(--bg); }

/* ---- Stats ---- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; text-decoration: none; color: var(--ink); display: block;
}
.stat:hover { border-color: var(--primary); text-decoration: none; }
.stat-icon { font-size: 22px; }
.stat-name { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-count { font-size: 22px; font-weight: 700; margin-top: 2px; }

/* ---- Profile ---- */
.profile-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; padding: 24px; border-radius: 16px; margin-bottom: 16px;
}
.profile-card h2 { margin: 0; font-size: 22px; }
.profile-card .motto { opacity: .85; margin-top: 6px; font-size: 14px; }

/* ---- Tags ---- */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); margin-right: 4px;
}
.tag.fav { background: #fff7e0; border-color: #f1d27a; color: #8d6a14; }
.tag.archived { background: #ecebe6; }

/* ---- Photo grid ---- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photos .photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; }
.photos .photo img { width: 100%; height: 100%; object-fit: cover; }
.photos .photo button {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer; font-size: 14px;
}

/* ---- Detail ---- */
.detail-row { display: flex; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.detail-row:last-child { border-bottom: none; }
.detail-row .key { color: var(--muted); font-size: 13px; min-width: 110px; }
.detail-row .val { flex: 1; word-break: break-word; }
.detail-row .val pre { white-space: pre-wrap; font: inherit; margin: 0; }

/* ---- Login ---- */
.auth-box {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 32px; box-shadow: 0 8px 24px rgba(0,0,0,.04);
}
.auth-box h1 { margin: 0 0 4px; }
.auth-box .lead { color: var(--muted); margin-bottom: 24px; }

/* utils */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.empty { text-align: center; padding: 40px; color: var(--muted); }
.password-cell { font-family: monospace; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] {
  flex: 1; min-width: 200px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font: inherit;
}
.inline-form { display: inline; }
.hidden { display: none; }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.disabled-input,
input:disabled, select:disabled, textarea:disabled {
  background: var(--bg); color: var(--muted); cursor: not-allowed;
}
