:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.12);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --danger: #ff3b30;
  --ok: #34c759;
  --warn: #ff9f0a;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", "Noto Sans SC", sans-serif;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-lift: 0 8px 28px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

.bg-mesh { display: none; }

.page {
  width: min(920px, calc(100% - 2.5rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}
.page--wide { width: min(1080px, calc(100% - 2.5rem)); }

.header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding: 1.35rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.header-main {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.site-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: contain;
  background: #fff;
  flex-shrink: 0;
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: contain;
  margin: 0 auto 0.85rem;
  display: block;
}

.brand {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.brand-sub {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 980px;
  background: #f5f5f7;
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 500;
}

.panel {
  margin-bottom: 1rem;
  padding: 1.5rem 1.55rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 0.4rem;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head h2 { margin: 0; }

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
  letter-spacing: 0;
}
.muted code {
  font-size: 0.85em;
  padding: 0.12em 0.4em;
  border-radius: 6px;
  background: #f5f5f7;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.kv {
  display: grid;
  gap: 0;
  margin: 1rem 0 0;
}
.kv > div {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.5rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}
.kv > div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); font-size: 0.8125rem; }
.kv dd { margin: 0; font-weight: 500; }

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 980px;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.4rem;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.98); }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}
.btn--ghost:hover { background: rgba(0, 113, 227, 0.06); }
.btn--danger {
  color: var(--danger);
  border-color: rgba(255, 59, 48, 0.25);
  background: #fff;
}
.btn--danger:hover { background: rgba(255, 59, 48, 0.06); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.login-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
  background: var(--bg);
}
.login-card {
  width: min(400px, 100%);
  padding: 2.5rem 2rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lift);
}
.login-brand {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.035em;
}
.login-sub {
  margin: 0.6rem 0 1.75rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}
.login-cta {
  width: 100%;
  min-height: 2.75rem;
  font-size: 1rem;
}
.login-hint {
  margin: 1.15rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}
.login-error {
  margin: 0.85rem 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 160px;
}
.field.grow { flex: 1; }
.field span {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: none;
}
.field input,
.field select {
  min-height: 2.5rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  font: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}
.form-msg {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
}
.form-msg.is-error { color: var(--danger); }
.form-msg.is-ok { color: var(--ok); }

.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th, .table td {
  text-align: left;
  padding: 0.85rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
}
.table tr:last-child td { border-bottom: 0; }

[hidden] { display: none !important; }

.upload-form { display: flex; flex-direction: column; gap: 0.9rem; }
.file-drop {
  display: grid;
  place-items: center;
  min-height: 8rem;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fafafa;
  cursor: pointer;
  padding: 1.25rem;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.file-drop input { display: none; }
.file-drop:hover,
.file-drop.is-drag {
  border-color: var(--accent);
  background: rgba(0, 113, 227, 0.04);
  color: var(--accent);
}
.progress {
  height: 0.35rem;
  border-radius: 980px;
  background: #ebebed;
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.15s ease;
}

.error-list {
  display: grid;
  gap: 0.85rem;
}
.error-card {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  transition: box-shadow 0.15s ease;
}
.error-card:hover { box-shadow: var(--shadow); }
.error-card__img {
  display: block;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #f5f5f7;
  aspect-ratio: 1;
}
.error-card__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.error-card__meta {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.ocr-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.55;
  max-height: 10rem;
  overflow: auto;
  background: #f5f5f7;
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  color: var(--ink);
}
.error-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}
.badge {
  display: inline-flex;
  padding: 0.2rem 0.55rem;
  border-radius: 980px;
  font-size: 0.72rem;
  font-weight: 500;
  background: #f5f5f7;
  color: var(--muted);
}
.badge--ok { background: rgba(52, 199, 89, 0.12); color: #248a3d; }
.badge--warn { background: rgba(255, 159, 10, 0.14); color: #9a6700; }
.badge--err { background: rgba(255, 59, 48, 0.12); color: var(--danger); }

.classify-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: flex-end;
  margin-top: 0.75rem;
}
.field.inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  margin: 0 0 1rem;
  padding: 0.25rem;
  background: #ebebed;
  border-radius: 980px;
  width: fit-content;
  max-width: 100%;
}
.tabs__btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.45rem 1rem;
  border-radius: 980px;
  cursor: pointer;
}
.tabs__btn.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.notebook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.notebook-card {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
  font: inherit;
  color: inherit;
}
.notebook-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--line-strong);
}
.notebook-card__badge {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent);
}
.notebook-card__title {
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.notebook-card__count {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .page, .page--wide { width: calc(100% - 1.5rem); padding-top: 1.25rem; }
  .header { padding: 1.1rem 1.15rem; }
  .brand { font-size: 1.3rem; }
  .panel { padding: 1.2rem; }
  .kv > div { grid-template-columns: 1fr; gap: 0.15rem; }
  .error-card { grid-template-columns: 1fr; }
  .tabs { width: 100%; }
  .tabs__btn { flex: 1; }
}
