:root {
  --bg: #f4f0e8;
  --card: #fffcf7;
  --ink: #2a241c;
  --muted: #7a7166;
  --line: #e6dfd2;
  --accent: #c9842a;
  --accent-soft: #fff4e0;
  --accent-ink: #fffdf8;
  --ok: #2f7a52;
  --warn: #b06d14;
  --err: #b42318;
  --info: #3d6a88;
  --shadow: 0 10px 28px rgba(80, 56, 20, .07);
  --radius: 16px;
  --tap: 44px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", sans-serif;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(88px + var(--safe-b)) calc(16px + var(--safe-l));
  max-width: 1180px;
  margin: 0 auto;
}
body.noscroll { overflow: hidden; }
.login-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
}
.login-card, .sheet {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.sheet { display: flex; flex-direction: column; }
.sheet:not(.slim) { max-height: min(92dvh, 860px); overflow: hidden; }
.sheet > header, .sheet > .tabs { flex-shrink: 0; }
.login-card { width: min(400px, 100%); }
.login-card .login-submit { margin-top: 22px; width: 100%; }
.eyebrow {
  display: inline-block;
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 0;
  border-radius: 999px;
  padding: 4px 10px;
}
h1 { font-size: 26px; margin: 12px 0 8px; letter-spacing: -.03em; }
h2 { margin: 0; font-size: 18px; }
p, .hint { color: var(--muted); }
.login-card p { margin: 0 0 22px; }
label { display: block; font-size: 13px; font-weight: 650; margin: 14px 0 8px; }
.login-card label { margin-top: 4px; }
.login-card label + input { margin-bottom: 4px; }
.login-card input[type="password"] { margin-bottom: 0; }
input, select, textarea {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: var(--tap);
  padding: 0 12px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #e8c48a;
  outline-offset: 1px;
  border-color: #e0c089;
}
select[multiple] { min-height: 88px; padding: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: var(--tap);
  min-height: var(--tap);
  min-width: 72px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn-ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}
.btn-danger {
  background: #fde8e6;
  color: var(--err);
  border-color: #f4c7c2;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
button.icon {
  height: 40px;
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: #f4f0e8;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}
.banner.err {
  background: #fde8e6;
  color: var(--err);
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 16px;
}
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.top-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.top-actions .btn { min-width: 72px; }
.who { color: var(--muted); font-size: 13px; }
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(88px, 1fr));
  gap: 10px;
  margin: 18px 0 14px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1 1 180px; min-width: 0; }
.toolbar select { width: auto; min-width: 120px; flex: 0 0 auto; }
.toolbar-acts { display: flex; gap: 8px; flex: 1 1 100%; }
.toolbar-acts .btn { flex: 1; }
.batch-bar {
  position: sticky;
  top: var(--safe-t);
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border: 1px solid #edd7a8;
  border-radius: 14px;
}
.batch-bar .btn { flex: 1; min-width: 110px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; align-items: stretch; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  min-height: 100%;
}
.card.sel { outline: 2px solid var(--accent); }
.card-top { display: grid; grid-template-columns: 72px 1fr; gap: 12px; flex: 1; }
.card-info { display: flex; flex-direction: column; min-width: 0; }
.card-meta {
  display: flex; align-items: center; gap: 6px; flex-wrap: nowrap;
  min-height: 24px; max-height: 24px; overflow: hidden;
}
.card-meta .id { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.cover-wrap { position: relative; display: block; width: 72px; height: 100px; }
.cover-wrap input {
  position: absolute; left: 6px; top: 6px; width: 18px; min-height: 18px;
  margin: 0; z-index: 1; accent-color: var(--accent);
}
.cover {
  width: 72px; height: 100px; object-fit: cover; border-radius: 10px; background: #eee8dc;
}
.cover.ph {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--muted);
}
.name {
  font-weight: 700; cursor: pointer;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  line-clamp: 2; overflow: hidden;
  line-height: 1.4; height: 2.8em; margin: 4px 0 2px;
}
.sub {
  color: var(--muted); font-size: 13px; margin-top: 2px; line-height: 1.4;
  height: 1.4em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tag {
  font-size: 11px; border-radius: 999px; padding: 3px 8px;
  background: #f4f0e8; color: var(--muted);
}
.tag.ACTIVE { background: #e5f5ec; color: var(--ok); }
.tag.ENDED { background: #e8f1f7; color: var(--info); }
.tag.PAUSED { background: var(--accent-soft); color: var(--warn); }
.tag.ERROR { background: #fde8e6; color: var(--err); }
.ops { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: auto; }
.ops .btn { width: 100%; }
.ops .btn.span { grid-column: 1 / -1; }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }
.fab {
  position: fixed;
  right: calc(16px + var(--safe-r));
  bottom: calc(16px + var(--safe-b));
  width: 56px; height: 56px; min-width: 56px; min-height: 56px;
  padding: 0;
  border-radius: 50%;
  font-size: 28px; font-weight: 500;
  box-shadow: 0 10px 24px rgba(201, 132, 42, .35);
  z-index: 15;
  display: none;
}
.modal, .drawer {
  position: fixed; inset: 0; background: rgba(42, 36, 28, .35);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 12px; overflow: auto; z-index: 20;
}
.drawer { justify-content: flex-end; padding: 0; }
.sheet { width: min(640px, 100%); }
.sheet.slim { width: min(420px, 100%); }
.pane {
  width: min(560px, 100%);
  height: 100%;
  background: var(--card);
  border-left: 1px solid var(--line);
  padding: 18px;
  overflow: auto;
}
.sheet header, .pane header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.sheet header h2, .pane header h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button {
  flex: 1;
  height: var(--tap);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.row select { width: 110px; flex: 0 0 auto; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.grow { grid-column: span 2; }
#paneMeta { flex: 1; min-height: 0; overflow: auto; }
.form { display: flex; flex-direction: column; min-height: 0; }
.sheet:not(.slim) .form { flex: 1; }
.form-body {
  flex: 1;
  overflow: auto;
  min-height: 0;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.form label { margin-top: 0; }
.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  margin: 0 -24px;
  padding: 12px 24px 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: none;
}
.actions .btn { flex: 1; }
.meta-list { display: grid; gap: 8px; margin-top: 12px; max-height: min(50dvh, 420px); overflow: auto; }
.meta {
  display: grid; grid-template-columns: 48px 1fr; gap: 10px;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
  min-height: 72px; background: #fff;
}
.meta:hover, .meta.on { border-color: #e0c089; background: var(--accent-soft); }
.meta img, .meta .ph { width: 48px; height: 68px; border-radius: 8px; object-fit: cover; background: #eee8dc; }
.preview { margin-top: 12px; font-size: 14px; }
.preview div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.stack { display: grid; gap: 8px; }
.stack-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.stack-item b { display: block; margin-bottom: 4px; }
.stack-item .row-ops { display: flex; gap: 8px; margin-top: 10px; }
.stack-item .row-ops .btn { flex: 1; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-b));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: #fffdf8;
  border: 0;
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 30;
  text-align: center;
}
[hidden] { display: none !important; }

@media (max-width: 720px) {
  h1 { font-size: 22px; margin: 6px 0 0; }
  .top { flex-direction: column; align-items: stretch; gap: 10px; }
  .top-right { justify-content: flex-end; }
  .top-right .who { margin-right: auto; }
  .top-actions { flex: 0 0 auto; }
  .stats {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding-bottom: 4px;
    grid-template-columns: none;
  }
  .stat { min-width: 92px; flex: 0 0 auto; scroll-snap-align: start; }
  .toolbar-acts { display: none; }
  .fab { display: inline-flex; }
  .grid { grid-template-columns: 1fr; }
  .modal {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }
  .sheet, .sheet.slim {
    width: 100%;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    padding: calc(12px + var(--safe-t)) 16px 0;
  }
  .drawer { justify-content: stretch; }
  .pane {
    width: 100%;
    border: 0;
    padding: calc(12px + var(--safe-t)) 16px calc(20px + var(--safe-b));
  }
  .row { flex-wrap: wrap; }
  .row select { width: 100%; }
  .row .btn, .row button { width: 100%; }
  .grow { grid-column: auto; }
  .form { flex: 1; }
  .form .actions {
    position: static;
    margin: 0 -16px;
    padding: 12px 16px calc(12px + var(--safe-b));
    background: var(--card);
    border-top: 1px solid var(--line);
    box-shadow: none;
  }
  .meta-list { max-height: none; }
}

@media (min-width: 721px) {
  .ops { display: grid; }
  .toolbar-acts { flex: 0 0 auto; }
  .toolbar-acts .btn { flex: 0 0 auto; }
}
