:root {
  --bg: #f3f2ef;
  --ink: #252525;
  --muted: #737373;
  --wine: #3a000e;
  --wine-soft: #5a1824;
  --danger: #8d2a2a;
  --line: rgba(37, 37, 37, 0.12);
  --line-strong: rgba(37, 37, 37, 0.18);
  --white: #fff;
  --side: 220px;
  --radius: 2px;
  --shadow: 0 1px 2px rgba(37, 37, 37, 0.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
.app {
  display: flex;
  min-height: 100vh;
}
.sidenav {
  position: sticky;
  top: 0;
  width: var(--side);
  height: 100vh;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--wine);
  color: #fff;
  padding: 28px 0 20px;
}
.logo {
  margin: 0 24px 28px;
  color: #fff;
  text-decoration: none;
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 28px;
  letter-spacing: 0.22em;
}
.sidenav nav { display: flex; flex-direction: column; }
.sidenav nav a, .side-logout {
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  padding: 12px 24px;
  font-size: 15px;
  transition: background 0.15s, color 0.15s;
}
.sidenav nav a.on, .sidenav nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.side-logout { margin-top: auto; font-size: 13px; }
.side-logout:hover { color: #fff; }
.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 28px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 18px; font-weight: 500; }
.back {
  color: var(--wine);
  text-decoration: none;
  font-size: 14px;
}
.back:hover { opacity: 0.75; }
.side { text-align: right; display: flex; justify-content: flex-end; align-items: center; }
.main { padding: 24px 28px 48px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.btn:hover { opacity: 0.92; }
.btn-primary {
  background: var(--wine);
  border-color: var(--wine);
  color: #fff;
}
.btn-primary:hover { background: var(--wine-soft); border-color: var(--wine-soft); opacity: 1; }
.btn-sm { height: 32px; padding: 0 14px; font-size: 13px; }
.btn-block { width: 100%; height: 44px; margin-top: 18px; font-size: 15px; }
.btn-ghost {
  height: 100%;
  min-width: 72px;
  padding: 0 14px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.btn-ghost:hover {
  background: #faf5f5;
  color: var(--danger);
  opacity: 1;
}
.btn-danger {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--danger);
}
.btn-danger:hover {
  background: #faf5f5;
  border-color: var(--danger);
  opacity: 1;
}
.text-btn {
  color: var(--wine);
  text-decoration: none;
  font-size: 14px;
}

.flash {
  margin: 16px 28px 0;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--wine);
}
.flash.err { border-left-color: var(--danger); }
.flash.ok { border-left-color: #2f5d3a; }
.hello { margin: 0 0 16px; color: var(--muted); }
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.stat {
  display: block;
  padding: 20px 18px;
  background: var(--white);
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.stat:hover { border-color: var(--wine); }
.stat b { display: block; font-size: 32px; font-weight: 500; }
.stat span { color: var(--muted); font-size: 13px; }
.group { margin-top: 28px; }
.group h2, .group h3 { margin: 0 0 12px; font-size: 14px; font-weight: 500; letter-spacing: 0.08em; }
.group h2 { color: var(--wine); }
.group h3 { color: var(--muted); margin-top: 18px; }
.links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.links a {
  display: block;
  padding: 16px;
  background: var(--white);
  color: inherit;
  text-decoration: none;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.links a:hover { border-color: rgba(58, 0, 14, 0.35); }
.links strong { display: block; font-weight: 500; }
.links em { display: block; margin-top: 6px; color: var(--muted); font-style: normal; font-size: 12px; }

/* Search */
.search {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  max-width: 520px;
  border: 1px solid var(--line);
  background: var(--white);
  box-shadow: var(--shadow);
}
.search:focus-within { border-color: rgba(58, 0, 14, 0.4); }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 10px 14px;
  outline: none;
}
.search .btn {
  height: 40px;
  border-radius: 0;
  border: 0;
  border-left: 1px solid var(--line);
  padding: 0 20px;
}

.form { max-width: 720px; }
.field { margin-top: 16px; }
.field-label,
.form label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.field > input,
.field > textarea,
.field > select,
.form label > input,
.form label > textarea,
.form label > select {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}
.field > textarea,
.form label > textarea { resize: vertical; min-height: 120px; }
.field > input:focus,
.field > textarea:focus,
.field > select:focus,
.form label > input:focus,
.form label > textarea:focus,
.form label > select:focus {
  border-color: rgba(58, 0, 14, 0.45);
}
.form-actions { margin-top: 24px; }
.form-actions .btn { min-width: 120px; height: 40px; padding: 0 28px; }
.inline-delete { margin-top: 12px; max-width: 720px; }
.inline-delete .btn { height: 36px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.chips a {
  padding: 5px 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  background: var(--white);
  transition: color 0.15s, border-color 0.15s;
}
.chips a:hover { color: var(--ink); border-color: var(--line-strong); }
.chips a.on { color: var(--wine); border-color: var(--wine); }

.cards { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex;
  align-items: stretch;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.card:hover { border-color: rgba(58, 0, 14, 0.28); }
.card-main {
  flex: 1;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.card-main img {
  width: 56px;
  height: 72px;
  object-fit: cover;
  background: var(--bg);
  flex: none;
}
.card-main strong, .card-main em { display: block; }
.card-main strong { font-weight: 500; }
.card-main em { margin-top: 4px; color: var(--muted); font-style: normal; font-size: 12px; }
.card-action { display: flex; margin: 0; }

/* Upload dropzone */
.upload { margin-top: 8px; }
.upload-path {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: var(--radius);
  outline: none;
}
.upload-path:focus { border-color: rgba(58, 0, 14, 0.45); }
.upload-drop {
  display: block;
  position: relative;
  cursor: pointer;
  border: 1px dashed rgba(58, 0, 14, 0.28);
  background: linear-gradient(180deg, #faf9f7 0%, #f5f3ef 100%);
  min-height: 148px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.upload-drop:hover,
.upload.is-drag .upload-drop {
  border-color: var(--wine);
  border-style: solid;
  background: #f8f3f4;
  box-shadow: inset 0 0 0 1px rgba(58, 0, 14, 0.06);
}
.upload.is-drag .upload-drop { background: #f3e9eb; }
.upload-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}
.upload-body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 148px;
  padding: 20px 16px;
  pointer-events: none;
  text-align: center;
}
.upload-hint strong {
  display: block;
  font-weight: 500;
  color: var(--ink);
  font-size: 14px;
}
.upload-hint span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}
.upload-preview {
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-thumb {
  width: 88px;
  height: 112px;
  object-fit: cover;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.upload-file-name {
  max-width: 280px;
  padding: 8px 12px;
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  word-break: break-all;
}
.upload.is-filled .upload-hint strong { font-size: 13px; }
.upload.is-filled .upload-body {
  flex-direction: row;
  justify-content: flex-start;
  text-align: left;
  gap: 18px;
  padding: 16px 20px;
  min-height: 0;
}
.upload.is-filled .upload-drop { min-height: 0; }

.empty, .hint, .logout { color: var(--muted); font-size: 13px; }
.logout { margin-top: 24px; }
.logout a { color: var(--wine); text-decoration: none; }
.pager { display: flex; gap: 16px; align-items: center; margin-top: 20px; font-size: 13px; }
.pager a { color: var(--wine); text-decoration: none; }
.pager a:hover { text-decoration: underline; }
.pager span { color: #b0aea8; }
.pager b { font-weight: 500; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(58, 0, 14, 0.06), transparent 50%),
    #e7e4df;
}
.login-card {
  width: min(420px, calc(100% - 32px));
  background: var(--white);
  padding: 48px 36px 36px;
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(37, 37, 37, 0.06);
}
.brand { text-align: center; margin-bottom: 28px; }
.brand-mark {
  margin: 0;
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 40px;
  letter-spacing: 0.28em;
  color: var(--wine);
}
.brand-sub { margin: 8px 0 0; letter-spacing: 0.32em; font-size: 12px; color: var(--muted); }
.login-card .flash { margin: 0 0 12px; }
.login-card .form label { margin-top: 14px; }
.login-card .form input { margin-top: 6px; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidenav {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 0 8px;
    z-index: 6;
  }
  .logo { margin: 0 12px 0 8px; font-size: 20px; }
  .sidenav nav { flex-direction: row; flex: 1; overflow-x: auto; }
  .sidenav nav a, .side-logout { padding: 14px 12px; white-space: nowrap; }
  .side-logout { margin-top: 0; }
  .stats { grid-template-columns: 1fr 1fr; }
  .main, .top { padding-left: 16px; padding-right: 16px; }
  .flash { margin-left: 16px; margin-right: 16px; }
  .search { max-width: none; }
  .upload.is-filled .upload-body {
    flex-direction: column;
    text-align: center;
  }
}
