:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #171a1d;
  --panelStrong: #1f2327;
  --line: #30363d;
  --lineSoft: #252a2f;
  --text: #e8edf2;
  --muted: #9ba5af;
  --accent: #4ea1ff;
  --accentStrong: #2f87e6;
  --danger: #ef5b5b;
  --success: #5ac18e;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panelStrong: #eef1f4;
  --line: #ccd3da;
  --lineSoft: #e1e6eb;
  --text: #171b20;
  --muted: #65717d;
  --accent: #176ecb;
  --accentStrong: #1158a8;
  --danger: #c93232;
  --success: #207d58;
  --shadow: 0 18px 50px rgba(40, 55, 70, 0.15);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

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 {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panelStrong);
  color: var(--text);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 120ms ease;
}

button:hover {
  border-color: var(--accent);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--text);
  padding: 0 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.loginView {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.loginPanel {
  width: min(390px, 100%);
  display: grid;
  gap: 18px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brandBlock {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brandBlock h1,
.brandBlock p {
  margin: 0;
}

.brandBlock h1 {
  font-size: 24px;
}

.brandBlock p {
  color: var(--muted);
  font-size: 13px;
}

.brandBlock.compact {
  gap: 10px;
}

.brandMark {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background:
    linear-gradient(135deg, transparent 0 55%, rgba(78, 161, 255, 0.35) 55% 100%),
    var(--panelStrong);
  display: inline-block;
}

.primaryButton {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 700;
}

.primaryButton:hover {
  background: var(--accentStrong);
}

.ghostButton {
  background: transparent;
}

.dangerButton {
  border-color: rgba(239, 91, 91, 0.55);
  color: var(--danger);
}

.formError {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.appShell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-height: 100vh;
}

.sidebarHeader,
.topbar,
.contentHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.sidebarHeader {
  padding: 18px;
  border-bottom: 1px solid var(--lineSoft);
}

.mainNav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--lineSoft);
}

.mainNav button {
  background: transparent;
}

.mainNav button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.iconButton {
  width: 36px;
  min-width: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
}

.folderActions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--lineSoft);
}

.folderActions button:first-child {
  grid-column: span 2;
}

.folderTree {
  overflow: auto;
  padding: 10px;
}

.folderNode {
  margin-left: calc(var(--depth) * 14px);
}

.folderButton {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  justify-content: flex-start;
  margin: 2px 0;
  padding: 8px 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.folderButton.active {
  background: var(--panelStrong);
  border-color: var(--line);
}

.folderIcon {
  width: 16px;
  height: 12px;
  border: 1px solid var(--muted);
  border-top-width: 5px;
  border-radius: 2px;
  flex: 0 0 auto;
}

.logoutButton {
  margin: 14px;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
}

.topbar {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar h2 {
  margin: 0;
  font-size: 24px;
}

.viewSwitch,
.segmentedControl {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
}

.viewSwitch button,
.segmentedControl button {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0 14px;
}

.viewSwitch button.active,
.segmentedControl button.active {
  background: var(--accent);
  color: white;
}

.uploadPanel {
  display: grid;
  grid-template-columns: minmax(260px, 430px) minmax(0, 1fr);
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--lineSoft);
  background: color-mix(in srgb, var(--panel) 84%, var(--bg));
}

.dropZone {
  min-height: 132px;
  display: grid;
  place-content: center;
  gap: 8px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.dropZone strong {
  color: var(--text);
  font-size: 16px;
}

.dropZone.dragOver {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}

.uploadControls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 130px minmax(160px, 240px) auto;
  gap: 14px;
  align-items: end;
}

.checkboxLine {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
}

.checkboxLine input {
  width: auto;
  min-height: auto;
}

.uploadQueue {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.queueItem {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.progressTrack {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--lineSoft);
}

.progressBar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 140ms ease;
}

.contentHeader {
  padding: 14px 24px;
  color: var(--muted);
}

.contentHeader strong {
  color: var(--text);
}

.imageGrid {
  min-height: 0;
  overflow: auto;
  padding: 0 24px 26px;
}

.imageGrid.gridMode {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 14px;
  align-content: start;
}

.imageGrid.listMode {
  display: grid;
  gap: 8px;
  align-content: start;
}

.imageCard {
  border: 1px solid var(--lineSoft);
  border-radius: 6px;
  background: var(--panel);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease;
}

.imageCard:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.gridMode .imageCard {
  display: grid;
  grid-template-rows: 154px auto auto;
}

.gridMode .listExtra {
  padding: 0 10px 10px;
}

.listMode .imageCard {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  align-items: center;
}

.thumbFrame {
  background:
    linear-gradient(45deg, var(--panelStrong) 25%, transparent 25% 75%, var(--panelStrong) 75%),
    linear-gradient(45deg, var(--panelStrong) 25%, transparent 25% 75%, var(--panelStrong) 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
}

.thumbFrame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.listMode .thumbFrame {
  width: 72px;
  height: 58px;
}

.imageMeta {
  min-width: 0;
  padding: 10px;
}

.imageMeta strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.imageMeta span,
.listExtra {
  color: var(--muted);
  font-size: 12px;
}

.listExtra {
  padding-right: 14px;
}

.emptyState {
  display: grid;
  place-content: center;
  gap: 8px;
  min-height: 240px;
  color: var(--muted);
  text-align: center;
}

.emptyState strong {
  color: var(--text);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--lineSoft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

.loadingState {
  display: grid;
  place-content: center;
  place-items: center;
  gap: 11px;
  min-height: 240px;
  color: var(--muted);
  font-size: 13px;
}

.statsLoading {
  display: grid;
  place-items: center;
  padding: 56px 0;
}

.statsDashboard {
  min-height: 0;
  overflow: auto;
  padding: 20px 24px 28px;
}

.statsHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.statsHeader h3 {
  margin: 0;
  font-size: 22px;
}

.statsCards {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.statCard,
.statsPanel {
  border: 1px solid var(--lineSoft);
  border-radius: 6px;
  background: var(--panel);
}

.statCard {
  min-height: 104px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 14px;
}

.statCard span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.statCard strong {
  font-size: 25px;
}

.statCard small {
  color: var(--muted);
  font-size: 12px;
}

.statsGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.statsPanel {
  min-width: 0;
  padding: 14px;
}

.statsPanel.wide {
  grid-column: 1 / -1;
}

.panelTitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panelTitle span {
  color: var(--muted);
  font-size: 12px;
}

.trafficChart {
  height: 210px;
  display: grid;
  grid-template-columns: repeat(14, minmax(16px, 1fr));
  align-items: end;
  gap: 8px;
  padding-top: 8px;
}

.trafficBarWrap {
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  height: 100%;
}

.trafficBarStack {
  display: flex;
  align-items: end;
  height: 100%;
  background: var(--panelStrong);
  border: 1px solid var(--lineSoft);
  border-radius: 4px;
  overflow: hidden;
}

.trafficBarStack > div {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.trafficBarOut,
.trafficBarIn {
  width: 100%;
  min-height: 2px;
}

.trafficBarOut {
  background: var(--accent);
}

.trafficBarIn {
  background: var(--success);
}

.trafficBarLabel {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breakdownList,
.compactTable {
  display: grid;
  gap: 9px;
}

.breakdownRow,
.tableRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.breakdownRow strong,
.tableRow strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter {
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--lineSoft);
}

.meterFill {
  height: 100%;
  background: var(--accent);
}

.mutedText {
  color: var(--muted);
  font-size: 13px;
}

.appDialog {
  width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
}

.appDialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.appDialogInner {
  padding: 22px;
  display: grid;
  gap: 16px;
}

.appDialogTitle {
  font-size: 16px;
}

.appDialogBody {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.appDialogActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.appDialogActions button {
  padding: 0 18px;
}

.imageDialog {
  width: min(1040px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
}

.imageDialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialogTopbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.dialogTopbar strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialogBody {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  min-height: 420px;
}

.previewFrame {
  display: grid;
  place-items: center;
  min-width: 0;
  background: #050607;
}

.previewFrame img {
  max-width: 100%;
  max-height: calc(100vh - 150px);
  object-fit: contain;
}

.detailPanel {
  border-left: 1px solid var(--line);
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 16px;
}

.detailPanel dl {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 10px 12px;
  margin: 0;
}

.detailPanel dt {
  color: var(--muted);
  font-size: 12px;
}

.detailPanel dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.dialogActions {
  display: grid;
  gap: 8px;
}

.toastHost {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  z-index: 50;
}

.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
}

.toast.error {
  border-left-color: var(--danger);
}

@media (max-width: 900px) {
  .appShell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .folderTree {
    max-height: 190px;
  }

  .uploadPanel {
    grid-template-columns: 1fr;
  }

  .statsCards,
  .statsGrid {
    grid-template-columns: 1fr;
  }

  .uploadControls {
    grid-template-columns: 1fr 1fr;
  }

  .dialogBody {
    grid-template-columns: 1fr;
  }

  .detailPanel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .topbar,
  .contentHeader,
  .sidebarHeader {
    align-items: stretch;
    flex-direction: column;
  }

  .uploadControls {
    grid-template-columns: 1fr;
  }

  .listMode .imageCard {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .listExtra {
    display: none;
  }
}
