:root {
  --bg: #f4f7f9;
  --panel: #ffffff;
  --text: #1b252d;
  --muted: #65727e;
  --line: #d9e1e7;
  --accent: #247a6b;
  --accent-dark: #185f54;
  --warn: #a86612;
  --bad: #b8392d;
  --good: #247a48;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
.button,
input,
textarea,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar h1,
.panel h2,
.login-panel h1 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 22px;
}

.topbar p,
.login-panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

.topbar form {
  display: flex;
  align-items: center;
  gap: 12px;
}

.layout {
  min-width: 0;
  padding: 24px;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 82px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}

.sidebar nav {
  position: sticky;
  top: 0;
  display: grid;
  gap: 4px;
  padding: 18px 12px;
}

.sidebar a {
  display: flex;
  min-height: 40px;
  align-items: center;
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  text-decoration: none;
}

.sidebar a:hover {
  background: #eaf0f2;
}

.sidebar a.active {
  color: white;
  background: var(--accent);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.metrics.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metrics article,
.panel,
.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metrics article {
  padding: 16px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr 64px;
  align-items: center;
  gap: 14px;
  margin: 18px 0;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #d8e5e2;
}

.progress-track div {
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.system-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.resource-body {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.resource-body strong {
  font-size: 24px;
}

.resource-body span {
  color: var(--muted);
  font-size: 13px;
}

.resource-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce8e5;
}

.resource-track div {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.process-list {
  display: grid;
  gap: 6px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.process-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line-soft);
  padding-top: 6px;
  font-size: 13px;
  font-weight: 650;
}

.process-list span {
  white-space: nowrap;
}

.log-panel {
  margin-bottom: 18px;
}

.log-stream {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding: 12px 16px;
  color: #d6e7e4;
  background: #10201d;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.log-stream div {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.log-stream .raw-log-line {
  display: block;
  white-space: pre-wrap;
}

.log-stream span {
  color: #8ad5c8;
  font-weight: 800;
  text-transform: uppercase;
}

.log-stream .muted {
  color: #96a6a3;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.page-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(260px, 560px);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.page-head h2 {
  margin: 0;
  font-size: 24px;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
  word-break: break-word;
}

.page-head code {
  display: block;
  overflow: auto;
  border-radius: 6px;
  padding: 10px;
  color: #24323b;
  background: #edf3f5;
  font-size: 12px;
}

.bot-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.bot-controls form {
  display: inline-flex;
}

.bot-start-form {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.bot-start-form label {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.bot-start-form input[type="number"] {
  width: 64px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
}

.bot-start-form .bot-check input {
  width: auto;
}

.bot-controls button {
  min-height: 36px;
  min-width: 82px;
}

.bot-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.bot-state {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  color: white;
  background: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.bot-state-running {
  background: var(--good);
}

.bot-state-paused {
  background: var(--warn);
}

.bot-state-stopped {
  background: var(--muted);
}

.bot-pids,
.bot-workers {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.bot-workers {
  font-weight: 800;
}

.upload-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.split-upload input:not([type="file"]) {
  width: 180px;
}

button,
.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  color: white;
  background: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover {
  background: var(--accent-dark);
}

.danger {
  background: var(--bad);
}

.danger:hover {
  background: #8f2a21;
}

.ghost-danger {
  border: 1px solid rgba(176, 54, 44, 0.28);
  color: var(--bad);
  background: #fff;
}

.ghost-danger:hover:not(:disabled) {
  color: #fff;
  background: var(--bad);
}

.ghost-danger:disabled {
  opacity: 0.48;
  cursor: default;
}

.ghost {
  color: var(--text);
  background: #e7edf1;
}

.ghost:hover {
  background: #d8e1e7;
}

input[type="file"],
textarea,
select,
.login-form input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: white;
}

textarea,
select {
  width: 100%;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.wide {
  grid-row: span 2;
}

.connector-panel {
  grid-column: 1 / -1;
  grid-row: auto;
}

.connector-grid,
.connector-lists {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 16px;
}

.connector-lists {
  border-top: 1px solid var(--line);
}

.connector-box h3,
.connector-lists h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.connector-box p {
  margin: 0 0 12px;
  color: var(--muted);
}

.connector-box code {
  display: block;
  overflow: auto;
  margin-top: 12px;
  border-radius: 6px;
  padding: 10px;
  color: #24323b;
  background: #edf3f5;
  font-size: 12px;
}

.command-box {
  display: grid;
  gap: 8px;
  padding: 0 16px 16px;
}

.command-box code {
  display: block;
  overflow: auto;
  border-radius: 6px;
  padding: 10px;
  color: #24323b;
  background: #edf3f5;
  font-size: 12px;
}

.creator-create-panel {
  grid-row: span 3;
}

.creator-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.cover-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.cover-box {
  display: grid;
  width: 96px;
  height: 116px;
  place-items: center;
  border: 1px dashed #f28a3c;
  border-radius: 6px;
  color: #f26b10;
  background: #fff8f2;
  font-size: 12px;
  text-align: center;
}

.cover-box input {
  width: 88px;
  font-size: 10px;
}

.cover-row p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: #394957;
  font-size: 12px;
  font-weight: 600;
}

.field small {
  color: var(--muted);
  font-size: 12px;
}

.field.full {
  grid-column: 1 / -1;
}

.field input,
.field textarea,
.field select,
.alt-row input,
.alt-row textarea,
.alt-row select {
  width: 100%;
}

.alt-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 10px;
}

.genre-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.genre-grid label {
  display: flex;
  align-items: center;
  min-height: 32px;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 12px;
}

.genre-grid input {
  width: auto;
  min-height: 0;
}

.form-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.three-cols {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.creator-actions {
  display: flex;
  justify-content: flex-end;
}

.creator-actions button {
  min-width: 220px;
  background: #ff6a00;
}

.creator-actions button:hover {
  background: #df5d00;
}

.stack-form {
  display: grid;
  gap: 10px;
}

.inline-form {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 10px;
}

.auth-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.auth-form button {
  min-height: 40px;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  color: #394957;
  font-size: 13px;
  font-weight: 600;
}

.check-field input {
  width: auto;
  min-height: auto;
}

.explorer-tools {
  display: grid;
  gap: 12px;
}

.explorer-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 10px;
}

.explorer-form button {
  min-height: 40px;
}

.folder-list {
  display: grid;
  gap: 6px;
  padding: 0 16px 16px;
}

.folder-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 8px 0;
}

.folder-list strong {
  word-break: break-word;
}

.folder-list span {
  color: var(--muted);
  white-space: nowrap;
}

.mini-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mini-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.mini-list span {
  color: var(--muted);
  white-space: nowrap;
}

.panel {
  min-width: 0;
  overflow: hidden;
  margin-bottom: 16px;
}

.summary-box {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 10px;
  padding: 16px;
  align-items: baseline;
}

.summary-box strong {
  font-size: 24px;
}

.summary-box span {
  color: var(--muted);
}

.form-pad {
  padding: 16px;
}

.pad-list {
  padding: 8px 16px 16px;
}

.text-link {
  color: var(--accent-dark);
  text-decoration: none;
  font-size: 13px;
}

.empty-state {
  padding: 24px 16px;
}

.empty-state h3 {
  margin: 0 0 6px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.gallery {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.explorer-gallery {
  gap: 8px;
}

.manga-folder,
.chapter-folder {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(18, 32, 45, 0.04);
}

.manga-folder > summary,
.chapter-folder > summary {
  display: grid;
  grid-template-columns: 24px 30px minmax(180px, 1fr) minmax(120px, auto) 64px;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 10px 16px;
  cursor: pointer;
  list-style: none;
  transition: background 140ms ease, box-shadow 140ms ease;
}

.manga-folder > summary:hover,
.chapter-folder > summary:hover {
  background: #f7faf9;
}

.manga-folder > summary::-webkit-details-marker,
.chapter-folder > summary::-webkit-details-marker {
  display: none;
}

.manga-folder > summary::after,
.chapter-folder > summary::after {
  content: "Open";
  display: inline-flex;
  grid-column: 5;
  align-items: center;
  justify-content: center;
  justify-self: end;
  width: 54px;
  min-height: 26px;
  border: 1px solid #a8d8cf;
  border-radius: 999px;
  color: var(--accent-dark);
  background: #e8f6f3;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.manga-folder[open] > summary::after,
.chapter-folder[open] > summary::after {
  content: "Close";
  color: #50606b;
  border-color: #cfd9df;
  background: #f1f5f7;
}

.select-box {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  cursor: pointer;
}

.select-box input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.manga-folder.selected,
.chapter-folder.selected,
.image-tile.selected {
  outline: 2px solid rgba(36, 122, 107, 0.55);
  outline-offset: -1px;
  background: #eefaf6;
}

.manga-folder.drop-target > summary,
.chapter-folder.drop-target > summary {
  background: #dff5ef;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.moving-selection [data-library-drop-target] > summary {
  cursor: copy;
}

.folder-title {
  overflow: hidden;
  min-width: 0;
  color: #10202c;
  font-size: 14px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-meta {
  overflow: hidden;
  justify-self: end;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-icon {
  position: relative;
  width: 24px;
  height: 18px;
  border-radius: 3px;
  background: #f7b928;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

.folder-icon::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 2px;
  width: 12px;
  height: 7px;
  border-radius: 3px 3px 0 0;
  background: #f7b928;
}

.folder-icon.small {
  width: 20px;
  height: 15px;
}

.chapter-list-view {
  display: grid;
  gap: 8px;
  padding: 10px 16px 16px 46px;
  border-top: 1px solid var(--line);
  background: #f8fafb;
}

.chapter-folder {
  background: white;
}

.chapter-folder > summary {
  min-height: 48px;
  grid-template-columns: 24px 28px minmax(160px, 1fr) minmax(120px, auto) 64px;
  padding: 8px 14px;
}

.folder-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.inline-action,
.image-actions {
  min-width: 0;
}

.inline-action > summary,
.image-actions > summary {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  cursor: pointer;
  color: var(--accent-dark);
  background: white;
  font-size: 12px;
  font-weight: 700;
  list-style: none;
}

.inline-action > summary::-webkit-details-marker,
.image-actions > summary::-webkit-details-marker {
  display: none;
}

.inline-action form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
}

.danger-action > summary {
  color: var(--bad);
}

.chapter-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfcfd;
}

.chapter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.chapter-head strong {
  word-break: break-word;
}

.chapter-head span {
  color: var(--muted);
  white-space: nowrap;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px;
  background: white;
}

.image-tile {
  position: relative;
  display: grid;
  gap: 8px;
  min-width: 0;
  align-content: start;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px;
  background: #ffffff;
}

.select-box.floating {
  position: absolute;
  z-index: 2;
  top: 8px;
  left: 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.92);
}

.image-tile img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.file-tile-preview {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent-dark);
  background: white;
  text-decoration: none;
}

.file-tile-preview span {
  max-width: calc(100% - 20px);
  overflow: hidden;
  font-size: 18px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-tile > span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-tile > small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rename-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.rename-form input {
  min-width: 0;
}

.tile-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.tile-actions button,
.rename-form button {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  font-size: 12px;
}

.image-actions {
  display: grid;
  gap: 8px;
}

.image-actions[open] {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 8px;
  background: #f8fafb;
}

.image-actions > .button,
.image-actions .rename-form,
.image-actions .tile-actions {
  margin-top: 8px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.library-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.library-head-actions > span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.library-panel-head {
  min-height: 64px;
  background: #fbfcfd;
}

.library-panel-head h2 {
  color: #142331;
  font-size: 17px;
  font-weight: 800;
}

.library-panel-head .icon-button {
  min-height: 34px;
  border: 1px solid rgba(184, 57, 45, 0.22);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
}

.library-panel-head .icon-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.panel h2 {
  font-size: 16px;
}

.table-wrap {
  overflow: auto;
  max-height: 620px;
}

.compact-table {
  max-height: 360px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #f8fafb;
  font-weight: 600;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  color: white;
  background: var(--muted);
}

.status-completed,
.status-filtered,
.status-uploaded {
  background: var(--good);
}

.status-failed,
.status-rejected,
.status-create_failed {
  background: var(--bad);
}

.status-filtering,
.status-uploading,
.status-translating,
.status-pending,
.status-metadata_ready {
  background: var(--warn);
}

.status-created,
.status-existing {
  background: var(--good);
}

.status-sent {
  background: var(--good);
}

.status-not_sent {
  background: var(--muted);
}

.mini-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.rules-list {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.site-add-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  border-bottom: 1px solid var(--line);
}

.site-add-form label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.site-add-form button {
  min-height: 40px;
}

.rule-site {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.rule-site-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.rule-site h3 {
  margin: 0;
}

.rule-site p {
  margin: 4px 0 14px;
  color: var(--muted);
}

.rule-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.rule-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin: 10px 0;
}

.rule-items {
  display: grid;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.rule-items li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 6px 0;
}

.rule-items span {
  word-break: break-word;
  font-size: 12px;
}

.file-list,
.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 292px;
  overflow: auto;
}

.file-list.compact,
.event-list.compact {
  max-height: 260px;
}

.output-list {
  max-height: none;
}

.file-list li,
.event-list li {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.file-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.file-list a {
  color: var(--accent-dark);
  text-decoration: none;
  word-break: break-word;
}

.event-list span,
.event-list strong,
.file-list span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.event-list p {
  margin: 4px 0 0;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(420px, calc(100% - 32px));
}

.login-panel {
  padding: 24px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.alert {
  margin-top: 18px;
  border-radius: 6px;
  padding: 10px 12px;
  color: #702016;
  background: #ffe8e3;
}

@media (max-width: 920px) {
  .app-shell,
  .page-head {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar nav {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics,
  .metrics.three,
  .grid,
  .system-grid,
  .site-add-form,
  .rule-cols,
  .rule-site-head,
  .auth-form,
  .explorer-form,
  .genre-grid,
  .form-cols,
  .three-cols,
  .alt-row,
  .cover-row,
  .connector-grid,
  .connector-lists {
    grid-template-columns: 1fr;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .split-upload input:not([type="file"]) {
    width: 100%;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .manga-folder > summary,
  .chapter-folder > summary {
    grid-template-columns: 24px minmax(0, 1fr);
  }

  .manga-folder summary span:last-child,
  .chapter-folder summary span:last-child,
  .manga-folder > summary::after,
  .chapter-folder > summary::after {
    grid-column: 2;
  }

  .chapter-list-view {
    padding-left: 12px;
  }
}

/* Professional dashboard polish: CSS-only, no extra assets or client libraries. */
:root {
  --bg: #eef3f6;
  --panel: #ffffff;
  --text: #17212a;
  --muted: #667483;
  --line: #d7e0e7;
  --line-soft: #e8eef2;
  --accent: #176f62;
  --accent-dark: #10574d;
  --accent-soft: #e6f3f0;
  --warn: #9d640d;
  --bad: #b0362c;
  --good: #1f7a4d;
  --shadow: 0 1px 2px rgba(20, 35, 45, 0.04), 0 8px 22px rgba(20, 35, 45, 0.05);
}

body {
  font-size: 14px;
  line-height: 1.45;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  padding: 14px 28px;
  box-shadow: 0 1px 0 var(--line-soft);
}

.topbar h1 {
  font-size: 20px;
  font-weight: 750;
}

.topbar p {
  font-size: 13px;
}

.topbar form span {
  color: var(--muted);
  font-size: 13px;
}

.app-shell {
  min-height: calc(100vh - 72px);
}

.sidebar {
  background: #f8fafb;
}

.sidebar nav {
  gap: 6px;
  padding: 16px 10px;
}

.sidebar a {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: #34424f;
  font-size: 13px;
  font-weight: 650;
}

.sidebar a:hover {
  border-color: var(--line);
  background: white;
}

.sidebar a.active {
  border-color: var(--accent-dark);
  color: white;
  background: var(--accent);
}

.layout {
  padding: 22px;
}

.page-head {
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.page-head h2 {
  font-size: 22px;
  font-weight: 760;
}

.page-head p {
  font-size: 13px;
}

.page-head code,
.command-box code,
.connector-box code {
  border: 1px solid var(--line-soft);
  background: #f3f7f9;
}

.metrics {
  gap: 14px;
}

.metrics article,
.panel,
.login-panel {
  border-color: var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 14px 16px;
}

.metrics span {
  font-size: 12px;
  font-weight: 650;
}

.metrics strong {
  margin-top: 4px;
  font-size: 26px;
  letter-spacing: 0;
}

.panel-head {
  min-height: 50px;
  padding: 13px 16px;
  background: #fbfcfd;
}

.panel-head h2 {
  font-weight: 760;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.source-links-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.source-links-actions form {
  margin: 0;
}

button,
.button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 700;
}

button:focus-visible,
.button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid rgba(23, 111, 98, 0.28);
  outline-offset: 2px;
}

.bot-controls button {
  min-width: 148px;
  color: #0f3f37;
  border-color: #9ccfc5;
  background: var(--accent-soft);
}

.bot-controls button:hover {
  color: white;
  background: var(--accent);
}

.bot-controls .danger {
  color: white;
  border-color: #c4493f;
  background: var(--bad);
}

.bot-controls .ghost {
  color: var(--text);
  border-color: var(--line);
  background: #f3f6f8;
}

.ghost {
  border-color: var(--line);
  background: #f3f6f8;
}

.ghost:hover {
  background: #e8eef2;
}

.danger {
  border-color: #c4493f;
}

input[type="file"],
input:not([type]),
input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select,
.login-form input {
  min-height: 38px;
  border-color: #cfd9e0;
  border-radius: 7px;
  color: var(--text);
}

input::placeholder,
textarea::placeholder {
  color: #8c98a4;
}

.grid {
  gap: 18px;
}

.form-pad,
.creator-form,
.gallery {
  padding: 16px;
}

.manga-folder,
.chapter-folder {
  border-color: var(--line);
  background: white;
}

.manga-folder > summary,
.chapter-folder > summary {
  transition: background 120ms ease, border-color 120ms ease;
}

.manga-folder > summary:hover,
.chapter-folder > summary:hover {
  background: #f7fafb;
}

.manga-folder[open] > summary {
  border-bottom: 1px solid var(--line-soft);
  background: #f8fbfc;
}

.chapter-folder[open] > summary {
  border-bottom: 1px solid var(--line-soft);
  background: #fbfcfd;
}

.manga-folder > summary::after,
.chapter-folder > summary::after {
  border: 1px solid #b9d8d2;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--accent-soft);
  font-size: 11px;
}

.manga-folder summary strong,
.chapter-folder summary strong {
  font-weight: 720;
}

.folder-icon,
.folder-icon::before {
  background: #e6ad24;
}

.chapter-list-view {
  padding-top: 12px;
}

.folder-toolbar {
  background: #f8fafb;
}

.inline-action > summary,
.image-actions > summary {
  min-height: 30px;
  border-radius: 6px;
  background: #ffffff;
}

.image-grid {
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 14px;
  padding: 14px;
}

.image-tile {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.image-tile img {
  border-color: var(--line-soft);
  background: #f8fafb;
}

.rename-form {
  gap: 8px;
}

.tile-actions {
  gap: 8px;
}

.status {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.compact-actions {
  gap: 6px;
}

.compact-actions .button,
.compact-actions button {
  min-height: 30px;
  padding: 0 9px;
}

.error-panel {
  overflow: hidden;
}

.error-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  padding: 14px;
}

.error-card {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #ffffff;
}

.error-shot {
  display: grid;
  place-items: center;
  width: 128px;
  min-height: 96px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafb;
  overflow: hidden;
}

.error-shot img {
  width: 100%;
  height: 100%;
  max-height: 140px;
  object-fit: contain;
}

.empty-shot {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.error-body {
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
}

.error-body strong,
.error-body code {
  word-break: break-word;
}

.error-body code {
  display: block;
  max-height: 96px;
  overflow: auto;
  padding: 8px;
  border-radius: 6px;
  color: #d9fff5;
  background: #08251f;
  font-size: 12px;
}

.file-manager {
  overflow: hidden;
}

.folder-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line-soft);
}

.folder-tabs a {
  display: grid;
  gap: 4px;
  min-height: 66px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
  text-decoration: none;
}

.folder-tabs a:hover,
.folder-tabs a.active {
  border-color: #9ccfc5;
  background: var(--accent-soft);
}

.folder-tabs span,
td small {
  color: var(--muted);
  font-size: 12px;
  word-break: break-word;
}

.table-wrap {
  overflow-x: auto;
}

table {
  font-size: 13px;
}

th {
  color: #506172;
  background: #f7fafb;
}

td {
  color: #25333f;
}

.empty-state {
  color: #364653;
  background: #fbfcfd;
}

.metadata-preview-list {
  display: grid;
  gap: 12px;
}

.metadata-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.metadata-preview > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  cursor: pointer;
  background: #f8fbfc;
}

.metadata-preview > summary strong {
  flex: 1;
}

.metadata-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 14px;
  border-top: 1px solid var(--line-soft);
}

.metadata-form .full {
  grid-column: 1 / -1;
}

.metadata-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.status-completed {
  color: #0d6b52;
  background: #dff6ef;
}

.status-failed {
  color: #9d2f27;
  background: #ffe7e4;
}

@media (max-width: 1120px) {
  .page-head {
    grid-template-columns: 1fr;
  }

  .page-head code {
    white-space: normal;
  }
}

/* Downloader operations header */
.downloader-head {
  display: grid;
  grid-template-columns: minmax(260px, 0.55fr) minmax(520px, 1fr);
  gap: 16px;
  align-items: stretch;
}

.page-title-block {
  min-width: 0;
}

.page-title-block h2 {
  margin-bottom: 8px;
}

.page-title-block p {
  display: inline-flex;
  max-width: 100%;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: #435466;
  background: #f8fbfc;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: normal;
}

.control-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.control-panel {
  padding: 12px;
}

.bot-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-content: start;
}

.bot-status-line,
.bot-action-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.bot-status-line {
  min-height: 30px;
}

.bot-start-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
  align-items: end;
}

.bot-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.bot-options label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.bot-options input[type="number"] {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  color: var(--text);
  background: white;
}

.bot-options .wide-option {
  grid-column: 1 / -1;
}

.bot-options .wide-option input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  color: var(--text);
  background: white;
}

.bot-options .bot-check {
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.bot-options .bot-check input[type="hidden"] {
  display: none;
}

.bot-options .bot-check input[type="checkbox"] {
  width: 14px;
  height: 14px;
}

.bot-controls button {
  width: 100%;
  min-width: 0;
}

.bot-action-line {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bot-action-line form {
  display: block;
}

@media (max-width: 1320px) {
  .downloader-head {
    grid-template-columns: minmax(260px, 0.8fr) minmax(520px, 1.2fr);
  }
}

@media (max-width: 900px) {
  .downloader-head,
  .bot-start-form,
  .bot-options,
  .bot-action-line {
    grid-template-columns: 1fr;
  }
}

/* Final explorer layout pass for multi-select file management. */
.library-panel-head {
  min-height: 64px;
  background: #fbfcfd;
}

.library-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.library-head-actions > span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.library-panel-head .icon-button {
  min-height: 34px;
  border: 1px solid rgba(176, 54, 44, 0.24);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 750;
}

.explorer-gallery {
  gap: 8px;
}

.manga-folder,
.chapter-folder {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 1px 2px rgba(18, 32, 45, 0.04);
}

.manga-folder > summary,
.chapter-folder > summary {
  display: grid;
  grid-template-columns: 24px 30px minmax(0, 1fr) max-content 64px;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 10px 16px;
}

.chapter-folder > summary {
  grid-template-columns: 24px 28px minmax(0, 1fr) max-content 64px;
  min-height: 48px;
  padding: 8px 14px;
}

.manga-folder > summary > .select-box,
.chapter-folder > summary > .select-box {
  grid-column: 1;
  grid-row: 1;
}

.manga-folder > summary > .folder-icon,
.chapter-folder > summary > .folder-icon {
  grid-column: 2;
  grid-row: 1;
}

.manga-folder > summary::after,
.chapter-folder > summary::after {
  display: inline-flex;
  grid-column: 5;
  grid-row: 1;
  align-items: center;
  justify-content: center;
  justify-self: end;
  width: 54px;
  min-height: 26px;
  border: 1px solid #a8d8cf;
  border-radius: 999px;
  padding: 0;
  color: var(--accent-dark);
  background: #e8f6f3;
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
}

.manga-folder[open] > summary::after,
.chapter-folder[open] > summary::after {
  color: #50606b;
  border-color: #cfd9df;
  background: #f1f5f7;
}

.folder-title {
  grid-column: 3;
  grid-row: 1;
  overflow: hidden;
  min-width: 0;
  color: #10202c;
  font-size: 14px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-meta {
  grid-column: 4;
  grid-row: 1;
  overflow: hidden;
  justify-self: end;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-list-view {
  padding: 10px 16px 16px 46px;
  border-top: 1px solid var(--line);
  background: #f8fafb;
}

@media (max-width: 900px) {
  .library-panel-head,
  .library-head-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .manga-folder > summary,
  .chapter-folder > summary {
    grid-template-columns: 24px 30px minmax(0, 1fr) 64px;
  }

  .manga-folder > summary > .select-box,
  .chapter-folder > summary > .select-box {
    grid-column: 1;
  }

  .manga-folder > summary > .folder-icon,
  .chapter-folder > summary > .folder-icon {
    grid-column: 2;
  }

  .folder-title {
    grid-column: 3;
  }

  .folder-meta {
    grid-column: 3 / 5;
    grid-row: 2;
    justify-self: start;
    text-align: left;
  }

  .manga-folder > summary::after,
  .chapter-folder > summary::after {
    grid-column: 4;
    grid-row: 1;
  }

  .chapter-list-view {
    padding-left: 12px;
  }
}

/* Explorer row fix: keep folder title directly beside the folder icon. */
.manga-folder > summary,
.chapter-folder > summary {
  display: flex;
  align-items: center;
  gap: 10px;
}

.manga-folder > summary > .select-box,
.chapter-folder > summary > .select-box {
  flex: 0 0 24px;
}

.manga-folder > summary > .folder-icon,
.chapter-folder > summary > .folder-icon {
  flex: 0 0 auto;
}

.folder-title {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: 2px;
}

.folder-meta {
  flex: 0 0 auto;
  max-width: 220px;
  margin-left: auto;
}

.manga-folder > summary::after,
.chapter-folder > summary::after {
  flex: 0 0 54px;
  margin-left: 10px;
}

@media (max-width: 900px) {
  .manga-folder > summary,
  .chapter-folder > summary {
    flex-wrap: wrap;
  }

  .folder-title {
    flex-basis: calc(100% - 140px);
  }

  .folder-meta {
    flex-basis: 100%;
    max-width: none;
    margin-left: 64px;
    text-align: left;
  }
}

/* Hard guarantee: folder icon and title must stay side-by-side. */
.explorer-gallery .manga-folder > summary,
.explorer-gallery .chapter-folder > summary {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
}

.explorer-gallery .folder-label {
  display: inline-flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 10px !important;
  min-width: 0 !important;
}

.explorer-gallery .folder-label .folder-icon {
  display: inline-block !important;
  flex: 0 0 auto !important;
}

.explorer-gallery .folder-label .folder-title {
  display: block !important;
  flex: 0 1 auto !important;
  min-width: 0 !important;
  margin: 0 !important;
  text-align: left !important;
  white-space: nowrap !important;
}

.explorer-gallery .folder-toggle {
  width: 54px !important;
  max-width: 54px !important;
  flex: 0 0 54px !important;
}

/* Canonical folder row layout. Keep this last to neutralize older summary rules. */
.manga-folder > summary,
.chapter-folder > summary {
  display: flex !important;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 10px 16px;
}

.chapter-folder > summary {
  min-height: 48px;
  padding: 8px 14px;
}

.manga-folder > summary::after,
.chapter-folder > summary::after {
  content: none !important;
  display: none !important;
}

.manga-folder > summary > .select-box,
.chapter-folder > summary > .select-box {
  flex: 0 0 22px;
}

.folder-label {
  display: inline-flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.folder-label .folder-icon {
  flex: 0 0 auto;
}

.folder-label .folder-title {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: #10202c;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-meta {
  flex: 0 0 auto;
  max-width: 240px;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  white-space: nowrap;
}

.folder-toggle {
  display: inline-flex;
  flex: 0 0 54px;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border: 1px solid #a8d8cf;
  border-radius: 999px;
  color: var(--accent-dark);
  background: #e8f6f3;
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
}

.folder-toggle .when-open {
  display: none;
}

.manga-folder[open] > summary .folder-toggle,
.chapter-folder[open] > summary .folder-toggle {
  color: #50606b;
  border-color: #cfd9df;
  background: #f1f5f7;
}

.manga-folder[open] > summary .folder-toggle .when-open,
.chapter-folder[open] > summary .folder-toggle .when-open {
  display: inline;
}

.manga-folder[open] > summary .folder-toggle .when-closed,
.chapter-folder[open] > summary .folder-toggle .when-closed {
  display: none;
}

@media (max-width: 900px) {
  .manga-folder > summary,
  .chapter-folder > summary {
    flex-wrap: wrap;
  }

  .folder-label {
    flex: 1 1 calc(100% - 96px);
  }

  .folder-meta {
    flex: 1 1 100%;
    max-width: none;
    margin-left: 32px;
    text-align: left;
  }
}
