:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #687385;
  --line: #d9dee7;
  --brand: #0f766e;
  --brand-dark: #0b5f59;
  --danger: #b42318;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
}

button:hover {
  border-color: var(--brand);
}

button.primary,
.source-form button {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

button.primary:hover,
.source-form button:hover {
  background: var(--brand-dark);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  color: var(--brand);
  background: #fff;
  text-decoration: none;
  white-space: nowrap;
}

.button-link:hover {
  background: #eefaf7;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 0 12px;
}

.shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 24px auto;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr minmax(360px, 560px);
  gap: 24px;
  align-items: end;
  margin-bottom: 16px;
}

h1 {
  margin: 0 0 4px;
  font-size: 30px;
}

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

.source-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

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

.metric {
  padding: 12px;
}

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

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.tab.active {
  border-color: var(--brand);
  color: var(--brand);
}

.export-download {
  display: inline-grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  width: 154px;
  min-height: 42px;
  margin-left: 12px;
  border: 5px solid #18df10;
  background: #fff;
  color: #05635a;
  text-decoration: none;
  font-weight: 700;
  line-height: 1.1;
}

.export-download + .export-download {
  margin-left: 10px;
}

.export-download span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.export-download:hover {
  background: #eefaf7;
}

.export-download.disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.65;
}

.panel {
  display: none;
  padding: 14px;
}

.panel.active {
  display: block;
}

.panel-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

#sourceSelect {
  min-width: 360px;
}

#routeTypeFilter {
  min-width: 220px;
}

#templateFilter {
  min-width: 260px;
}

.group-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -2px 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.group-info span {
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.id-input {
  width: 150px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  max-height: 62vh;
}

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

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

th {
  position: sticky;
  top: 0;
  background: #eef2f7;
  z-index: 1;
}

td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.action-cell {
  max-width: 96px;
  width: 96px;
}

.menu-name {
  display: inline-block;
  min-width: 220px;
  font-weight: 600;
}

.pager {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 12px;
}

.file-manager {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(360px, 1fr) minmax(280px, 360px);
  gap: 12px;
  min-height: 56vh;
}

.file-tree-panel,
.file-list-panel,
.file-preview {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: auto;
}

.file-tree-panel {
  padding: 8px;
}

.file-tree {
  min-width: 210px;
}

.tree-node {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 4px;
  align-items: center;
  width: 100%;
  min-height: 32px;
  padding: 0 8px 0 calc(8px + (var(--level, 0) * 16px));
  border: 0;
  background: transparent;
  text-align: left;
}

.tree-node:hover,
.tree-node.active {
  background: #eefaf7;
  color: var(--brand);
}

.tree-toggle {
  color: var(--muted);
  text-align: center;
}

.tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-list {
  overflow: hidden;
}

.file-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 86px 132px auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  cursor: default;
}

.file-row:hover,
.file-row.selected {
  background: #f1f7f6;
}

.file-row:last-child {
  border-bottom: 0;
}

.file-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #f8fafc;
  color: #334155;
  font-size: 11px;
  font-weight: 700;
}

.file-icon-directory {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: var(--brand);
  font-size: 15px;
}

.file-icon-image {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.file-icon-pdf {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b42318;
}

.file-icon-word,
.file-icon-sheet,
.file-icon-slide {
  border-color: #c7d2fe;
  background: #eef2ff;
  color: #4338ca;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.file-preview {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.preview-image-wrap {
  display: grid;
  place-items: center;
  min-height: 240px;
  max-height: 44vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.preview-image-wrap img {
  display: block;
  max-width: 100%;
  max-height: 42vh;
  object-fit: contain;
}

.preview-frame {
  width: 100%;
  min-height: 380px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.preview-doc,
.preview-empty {
  display: grid;
  gap: 12px;
  align-content: start;
  justify-items: start;
}

.preview-empty {
  color: var(--muted);
}

.preview-doc-icon {
  display: grid;
  place-items: center;
  width: 86px;
  height: 104px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
  color: #334155;
  font-weight: 800;
}

.preview-folder .preview-doc-icon {
  height: 70px;
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: var(--brand);
}

.preview-meta {
  display: grid;
  gap: 5px;
  width: 100%;
  min-width: 0;
}

.preview-meta strong,
.preview-meta span {
  overflow-wrap: anywhere;
}

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

.error {
  color: var(--danger);
}

@media (max-width: 820px) {
  .toolbar,
  .source-form,
  .status-grid,
  .file-manager {
    grid-template-columns: 1fr;
  }

  .file-manager {
    min-height: 0;
  }

  .file-tree-panel,
  .file-list-panel,
  .file-preview {
    max-height: none;
  }

  .file-row {
    grid-template-columns: 36px minmax(0, 1fr) auto;
  }

  .file-date {
    display: none;
  }

  #sourceSelect {
    min-width: 0;
    width: 100%;
  }

  #routeTypeFilter,
  #templateFilter {
    min-width: 0;
    width: 100%;
  }

  .export-download {
    margin-left: 0;
    width: calc(50% - 3px);
  }

  .export-download + .export-download {
    margin-left: 0;
  }
}
