:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --sidebar: #ffffff;
  --line: #d7dde6;
  --line-soft: #e8edf3;
  --text: #151922;
  --muted: #667085;
  --accent: #2f80da;
  --danger: #b42318;
  --ok: #0f766e;
  --warn: #9a6700;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 9px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 9px 13px;
  white-space: nowrap;
}

button.secondary,
.secondary-link {
  border: 1px solid var(--line);
  background: white;
  color: #344054;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 0;
}

button.danger {
  width: 100%;
  background: var(--danger);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: white;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

code {
  font-size: 12px;
}

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

.login-panel {
  width: min(420px, calc(100vw - 32px));
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

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

.stack {
  display: grid;
  gap: 14px;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 16px 12px;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 12px;
  min-height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 10px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-link {
  color: var(--text);
  font-weight: 800;
}

.primary-wide {
  width: 100%;
  border-radius: 2px;
  background: var(--accent);
  font-weight: 700;
}

.folder-create {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.folder-create button {
  padding: 0;
  font-size: 20px;
}

.folder-list {
  display: grid;
  align-content: start;
  gap: 2px;
}

.folder-list a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #415166;
  padding: 5px 8px 5px calc(8px + ((var(--depth, 0)) * 18px));
  border-radius: 2px;
  overflow-wrap: anywhere;
  line-height: 1.25;
  font-size: 14px;
}

.folder-list a.active,
.folder-list a:hover {
  background: #eef3fb;
}

.sidebar-bottom {
  align-self: end;
  display: grid;
  gap: 8px;
}

.settings-button {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  padding: 10px 12px;
  text-align: center;
}

.content {
  padding: 28px 36px 22px;
  display: grid;
  gap: 16px;
  align-content: start;
}

.site-header {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 38px;
  padding: 0 0 18px;
}

.site-header span {
  display: block;
  margin-bottom: 7px;
  color: #a0a6ad;
  font-size: 13px;
  font-weight: 700;
}

.site-header strong {
  color: #3a414b;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  align-items: center;
  min-height: 66px;
  border: 1px solid var(--line);
  background: white;
  padding: 0 24px;
  gap: 26px;
}

.tabs a {
  color: #555f6c;
  height: 66px;
  display: inline-flex;
  align-items: center;
  border-bottom: 3px solid transparent;
}

.tabs a.active {
  color: #111827;
  border-bottom-color: var(--accent);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 25px;
}

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

.dashboard {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.metric strong {
  font-size: 24px;
}

.usage-panel {
  padding: 12px;
}

.usage-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.usage-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  padding: 10px 12px;
  background: #fbfcfe;
  color: #405169;
  white-space: nowrap;
}

.usage-item span {
  color: var(--muted);
  font-size: 12px;
}

.usage-item strong {
  color: var(--text);
  font-size: 16px;
}

.usage-item em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.service-status-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.service-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  padding: 10px 12px;
  background: #fbfcfe;
  color: #405169;
}

.service-status::before {
  content: "";
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 999px;
  background: #98a2b3;
}

.service-status.ok::before {
  background: #12b76a;
}

.service-status.warn::before {
  background: #f79009;
}

.service-status.error::before {
  background: #f04438;
}

.service-status span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.service-status strong {
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel,
.explorer,
.file-manager {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.panel {
  padding: 16px;
}

.panel-title,
.explorer-toolbar,
.manager-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  margin-bottom: 14px;
}

.panel-title h2 {
  margin: 0;
  font-size: 18px;
}

.panel-note {
  margin: 0;
  color: var(--muted);
}

.explorer-toolbar,
.manager-toolbar {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.pathbar {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow-wrap: anywhere;
  color: #435168;
  flex: 1 1 auto;
}

.file-count {
  flex: 0 0 auto;
  margin-left: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 3px 8px;
  background: #f4f6fa;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

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

.file-search {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto;
  gap: 8px;
  align-items: end;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.file-search label {
  min-width: 0;
}

.file-search input {
  min-height: 38px;
}

.search-result {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  padding: 9px 2px;
}

.hidden-upload {
  display: none;
}

.icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 2px;
  background: transparent;
  color: #8b98aa;
  font-size: 20px;
}

.icon-button:hover {
  background: #eef3fb;
  color: var(--accent);
}

.upload-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px;
  width: min(520px, 100%);
}

.file-table {
  display: grid;
}

.file-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 100px 160px 110px minmax(220px, .8fr);
  gap: 12px;
  min-height: 36px;
  padding: 7px 12px;
  border-top: 1px solid var(--line-soft);
  align-items: center;
  color: #405169;
  font-size: 14px;
}

.file-row:first-child {
  border-top: 0;
}

.file-head {
  background: #f4f6fa;
  color: #333b46;
  font-size: 12px;
  font-weight: 600;
}

.sort-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-align: left;
  padding: 0;
  cursor: pointer;
}

.sort-button:hover {
  color: var(--accent);
}

.sort-button.active::after {
  content: " ↑";
  color: var(--accent);
}

.sort-button.active[data-direction="desc"]::after {
  content: " ↓";
}

.file-row:not(.file-head):hover,
.file-row.selected {
  background: #eef5ff;
}

.back-row {
  color: #8b98aa;
}

.file-name,
.file-name a {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.file-icon {
  width: 22px;
  flex: 0 0 22px;
  text-align: center;
  height: 18px;
  position: relative;
}

.tree-folder,
.folder-icon {
  display: inline-block;
  width: 18px;
  height: 13px;
  border-radius: 2px;
  background: #c6c8cb;
}

.tree-folder::before,
.folder-icon::before {
  content: "";
  position: absolute;
}

.tree-folder {
  position: relative;
}

.tree-folder::before,
.folder-icon::before {
  width: 8px;
  height: 4px;
  background: #c6c8cb;
  border-radius: 2px 2px 0 0;
  left: 1px;
  top: -3px;
}

.folder-icon {
  margin-top: 2px;
  position: relative;
}

.doc-icon {
  display: inline-flex;
  width: 18px;
  height: 21px;
  border: 1px solid #b7c2cf;
  border-radius: 2px;
  background: #eef5fb;
}

.doc-icon::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -1px;
  border-top: 7px solid white;
  border-left: 7px solid #c9d3df;
}

.doc-icon.srt {
  background: #fff1f0;
  border-color: #ffaaa2;
}

.back-icon {
  color: #95a3b8;
  font-size: 18px;
}

.badge,
.status {
  display: inline-block;
  min-width: 68px;
  text-align: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 12px;
}

.badge.done,
.status.done {
  background: #e7f5f2;
  color: var(--ok);
}

.badge.queued,
.badge.wait,
.badge.jp,
.status.queued {
  background: #fff5d6;
  color: var(--warn);
}

.badge.running,
.status.running {
  background: #e9f3ff;
  color: #276aa8;
}

.badge.failed,
.status.failed {
  background: #fff0ed;
  color: var(--danger);
}

.status.skipped {
  background: #eef2f6;
  color: var(--muted);
}

.status.idle {
  background: #eef2f6;
  color: var(--muted);
}

.process-cell {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: #5f6f83;
  font-size: 12px;
}

.process-cell span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.process-cell progress {
  width: 100%;
  height: 6px;
}

.empty {
  padding: 18px;
  color: var(--muted);
}

.drop-hint {
  display: none;
  margin: 12px;
  padding: 18px;
  border: 2px dashed #8dbdf1;
  background: #f2f8ff;
  color: #2466a8;
  text-align: center;
}

.drop-hint.show,
.file-manager.dragging .drop-hint {
  display: block;
}

.viewer-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.viewer-meta div {
  min-width: 0;
  background: white;
  padding: 13px 14px;
}

.viewer-meta span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.viewer-meta strong {
  display: block;
  color: var(--text);
  overflow-wrap: anywhere;
  font-size: 14px;
}

.file-viewer,
.file-editor-form {
  border: 1px solid var(--line);
  background: #101820;
  color: #e7edf4;
  overflow: auto;
  max-height: calc(100vh - 230px);
}

.file-viewer pre {
  margin: 0;
  padding: 18px 20px;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.file-editor-form {
  display: grid;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid #263442;
  background: #151f29;
}

.editor-toolbar button {
  padding: 7px 12px;
}

.code-editor {
  min-height: calc(100vh - 310px);
  border: 0;
  border-radius: 0;
  background: #101820;
  color: #e7edf4;
  padding: 18px 20px;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  tab-size: 2;
  resize: vertical;
  outline: none;
}

.CodeMirror {
  min-height: calc(100vh - 310px);
  height: auto;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.file-manager.dragging {
  outline: 2px dashed #8dbdf1;
  outline-offset: -6px;
}

.context-menu {
  position: fixed;
  z-index: 1000;
  display: none;
  min-width: 180px;
  padding: 6px;
  border: 1px solid #cfd8e3;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.18);
}

.context-menu.open {
  display: grid;
}

.context-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  color: #2f3a4a;
  text-align: left;
  border-radius: 2px;
}

.context-menu button span {
  color: #96a1b3;
}

.context-menu hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line-soft);
  margin: 5px 0;
}

.context-menu button:hover {
  background: #eef3fb;
}

.context-menu .danger-action {
  color: var(--danger);
}

.alert {
  padding: 12px 14px;
  border-radius: 6px;
  background: #e7f5f2;
  color: #0b4f48;
  border: 1px solid #b7e2db;
}

.alert.error {
  background: #fff0ed;
  color: var(--danger);
  border-color: #ffd1c8;
}

.file-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
}

.file-dialog::backdrop {
  background: rgba(15, 23, 42, 0.28);
}

.file-dialog h3 {
  margin: 0 0 16px;
  font-size: 18px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.job-list {
  display: grid;
  gap: 8px;
}

.job-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 12px;
  align-items: center;
}

.job-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.job-progress {
  display: grid;
  gap: 8px;
}

.sync-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  color: #405169;
  font-size: 14px;
}

.history-table,
.compare-table {
  display: grid;
  border: 1px solid var(--line);
  overflow: auto;
}

.history-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-top: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.page-nav a,
.page-nav span {
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: #405169;
  font-size: 13px;
}

.page-nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.page-nav a.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.page-nav a.disabled {
  pointer-events: none;
  opacity: 0.42;
}

.page-nav span {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.history-row,
.compare-row {
  display: grid;
  gap: 12px;
  align-items: start;
  border-top: 1px solid var(--line-soft);
  color: #405169;
  font-size: 14px;
}

.history-row {
  grid-template-columns: minmax(260px, 1fr) 190px 90px 150px 150px;
  padding: 9px 12px;
}

.compare-row {
  grid-template-columns: 64px 230px minmax(280px, 1fr) minmax(280px, 1fr);
  padding: 10px 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.history-row:first-child,
.compare-row:first-child {
  border-top: 0;
}

.history-head,
.compare-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f4f6fa;
  color: #333b46;
  font-size: 12px;
  font-weight: 700;
  white-space: normal;
}

a.history-row:hover {
  background: #eef5ff;
}

.history-file {
  color: var(--text);
  overflow-wrap: anywhere;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

progress {
  width: 100%;
  height: 9px;
  accent-color: var(--accent);
}

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

.grid-form .wide,
.grid-form button {
  grid-column: 1 / -1;
}

.user-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fbfcfe;
}

.user-row form {
  margin: 0;
}

.user-form {
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}

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

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

  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .usage-list {
    grid-template-columns: 1fr;
  }

  .service-status-list {
    grid-template-columns: 1fr;
  }

  .viewer-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar,
  .explorer-toolbar,
  .manager-toolbar,
  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .file-row,
  .job-row,
  .grid-form,
  .upload-row,
  .file-search,
  .history-row,
  .compare-row {
    grid-template-columns: 1fr;
  }
}
