:root {
  --bg: #141414;
  --surface: #1d1d1d;
  --surface-2: #262626;
  --surface-3: #2f2f2f;
  --border: #3a3a3a;
  --text: #efefef;
  --muted: #a6a6a6;
  --primary: #3c8b5d;
  --primary-2: #336e4c;
  --danger: #a84040;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Bahnschrift", "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.35;
}

.app-shell {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.topbar__main {
  font-size: 20px;
  font-weight: 600;
}

.topbar__sub {
  color: var(--muted);
  margin-top: 4px;
}

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

.grid-top {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 14px;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.panel-title {
  font-weight: 600;
  margin-bottom: 10px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.collapse-btn {
  height: 30px;
  padding: 0 10px;
  border: 1px solid #505050;
  background: var(--surface-3);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

.panel-collapsible.is-collapsed .panel-content {
  display: none;
}

.limit-scroll {
  max-height: 70vh;
  overflow: auto;
  padding-right: 2px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.metric {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}

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

.runtime-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.runtime-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.row > input,
.row > select {
  flex: 1 1 auto;
  min-width: 0;
}

.row > button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.row--actions {
  margin-top: 10px;
}

.row--filters {
  align-items: flex-end;
  margin-bottom: 10px;
}

.filter {
  min-width: 220px;
  flex: 1 1 220px;
}

.filter--short {
  min-width: 170px;
  flex-basis: 170px;
}

.filter--wide {
  min-width: 380px;
  flex-basis: 380px;
}

.label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}

input,
select {
  height: 38px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 10px;
}

input:focus,
select:focus {
  outline: 2px solid #4e7f62;
  outline-offset: 1px;
}

button {
  height: 38px;
  border: 1px solid var(--primary-2);
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
}

button.button-secondary {
  background: var(--surface-3);
  border-color: #505050;
}

button.button-danger {
  background: var(--danger);
  border-color: #8a3434;
}

button:hover:enabled {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.feedback {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
}

.logbox {
  margin: 0;
  background: #161616;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 170px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.table-wrapper {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: calc(70vh - 110px);
}

table {
  width: 100%;
  border-collapse: collapse;
}

#pagesTable {
  min-width: 980px;
}

#imagesTable {
  min-width: 1400px;
}

#activityTable,
#serverErrorsTable {
  min-width: 780px;
}

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

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
}

tbody tr:hover {
  background: #232323;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sorted-asc::after {
  content: " ▲";
  color: #bdbdbd;
}

th.sorted-desc::after {
  content: " ▼";
  color: #bdbdbd;
}

td.url-cell,
td.long-cell {
  max-width: 480px;
  word-break: break-word;
}

a {
  color: #9fcbad;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid transparent;
}

.status-pending {
  background: #3a2a17;
  border-color: #9b6023;
  color: #f1b36f;
}

.status-processing {
  background: #3b3513;
  border-color: #b89c22;
  color: #f2dc7f;
}

.status-scraped {
  background: #1a3a23;
  border-color: #2f9d62;
  color: #8cd3a5;
}

.status-failed {
  background: #3a1818;
  border-color: #b14545;
  color: #e69696;
}

.status-duplicate {
  background: #313131;
  border-color: #777777;
  color: #d6d6d6;
}

.error {
  color: #d88d8d;
}

.preview {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #151515;
}

.preview--empty {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1080px) {
  .grid-top {
    grid-template-columns: 1fr;
  }

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

  .row {
    flex-wrap: wrap;
  }

  .row > input,
  .row > select {
    flex-basis: 100%;
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding: 10px;
  }

  .panel {
    padding: 10px;
  }

  .topbar {
    padding: 12px;
  }

  .topbar__main {
    font-size: 18px;
  }

  .status-grid {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  }

  .filter,
  .filter--wide,
  .filter--short {
    min-width: 100%;
    flex-basis: 100%;
  }

  .row > button,
  .row--actions > button {
    width: 100%;
  }

  .panel-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .collapse-btn {
    width: 100%;
  }

  .runtime-url {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .table-wrapper {
    max-height: calc(70vh - 130px);
  }
}

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

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

  th,
  td {
    padding: 8px 7px;
  }

  .preview,
  .preview--empty {
    width: 48px;
    height: 48px;
  }
}
