:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --text: #172033;
  --muted: #697386;
  --line: #dbe3ee;
  --blue: #2364aa;
  --blue-2: #1f7cc4;
  --teal: #168a76;
  --green: #2f855a;
  --amber: #b7791f;
  --red: #c53030;
  --ink: #111827;
  --shadow: 0 16px 42px rgba(31, 50, 77, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.theme-dark {
  color-scheme: dark;
  --bg: #121821;
  --surface: #182232;
  --surface-2: #202c3d;
  --text: #f4f7fb;
  --muted: #aeb9c8;
  --line: #314158;
  --blue: #65a8e9;
  --blue-2: #8abdea;
  --teal: #55c7b4;
  --green: #69c28e;
  --amber: #f0bc62;
  --red: #f07878;
  --ink: #f4f7fb;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 230px minmax(260px, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px);
}

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

.brand img {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
}

.brand span {
  display: grid;
  line-height: 1.05;
}

.brand strong {
  font-size: 1.1rem;
  letter-spacing: 0;
}

.brand small {
  color: var(--muted);
  font-size: 0.76rem;
}

.search {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.system-pill,
.status-dot,
.tool-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.install-button {
  min-height: 40px;
  padding: 0 12px;
}

.status-dot {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green) 35%, var(--line));
}

.tool-badge {
  color: var(--blue);
  border-color: color-mix(in srgb, var(--blue) 35%, var(--line));
}

.icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.icon-button:hover,
.text-button:hover,
.secondary-button:hover,
.view-switcher button:hover {
  border-color: color-mix(in srgb, var(--blue) 40%, var(--line));
}

.icon-button.ghost {
  width: 34px;
  height: 34px;
  background: transparent;
}

.workspace {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
  padding: 18px;
}

.sidebar,
.inspector,
.upload-panel,
.tool-runner,
.tool-library {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sidebar,
.inspector {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 106px);
  overflow: auto;
}

.sidebar {
  padding: 14px;
}

.sidebar-header,
.library-header,
.section-title,
.file-toolbar,
.runner-actions,
.range-label,
.tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-header {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
}

.category-nav {
  display: grid;
  gap: 7px;
}

.category-button {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.category-button:hover,
.category-button.active {
  border-color: var(--line);
  background: var(--surface-2);
}

.category-button .count {
  min-width: 28px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  font-size: 0.75rem;
}

.main-panel {
  min-width: 0;
  display: grid;
  gap: 18px;
}

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

.metric {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric span {
  color: var(--muted);
  font-size: 0.82rem;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.35rem, 3vw, 2rem);
  letter-spacing: 0;
}

.metric:nth-child(1) strong {
  color: var(--blue);
}

.metric:nth-child(2) strong {
  color: var(--teal);
}

.metric:nth-child(3) strong {
  color: var(--amber);
}

.metric:nth-child(4) strong {
  color: var(--green);
}

.workbench {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 18px;
}

.upload-panel,
.tool-runner,
.tool-library,
.inspector {
  padding: 16px;
}

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

.section-title h1,
.section-title h2,
.library-header h2 {
  margin: 0;
  font-size: 1.24rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.section-title h1 {
  font-size: 1.42rem;
}

.compact-title h2 {
  font-size: 1rem;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.dropzone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 202px;
  padding: 20px;
  border: 2px dashed color-mix(in srgb, var(--blue) 38%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--blue) 7%, var(--surface));
  color: var(--text);
  text-align: center;
}

.dropzone.dragover {
  border-color: var(--teal);
  background: color-mix(in srgb, var(--teal) 10%, var(--surface));
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.dropzone strong {
  font-size: 1.06rem;
}

.dropzone small {
  max-width: 28rem;
  color: var(--muted);
  line-height: 1.45;
}

.drop-icon {
  width: 48px;
  height: 48px;
  color: var(--blue);
}

.drop-icon svg {
  width: 48px;
  height: 48px;
  stroke-width: 1.7;
}

.file-toolbar {
  min-height: 44px;
  color: var(--muted);
  font-size: 0.88rem;
}

.text-button,
.secondary-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: var(--radius);
  font-weight: 700;
}

.text-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--red);
}

.primary-button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--blue-2);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

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

.file-item,
.job-item,
.api-box,
.storage-meter {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.file-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 8px 10px;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--blue) 13%, var(--surface));
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 900;
}

.file-name,
.tool-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item small,
.job-item small,
.tool-card small,
.api-box span,
.storage-meter span {
  color: var(--muted);
}

.remove-file {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
}

.remove-file:hover {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 35%, var(--line));
}

.runner-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 0.55fr);
  gap: 12px;
}

label {
  min-width: 0;
}

.runner-grid label,
.notes-area {
  display: grid;
  gap: 7px;
}

.runner-grid label span,
.notes-area span,
.option-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  outline: 0;
}

input[type="text"],
input[type="password"],
select {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  min-height: 112px;
  padding: 10px 11px;
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus,
.search:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent);
}

.option-block {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.segmented,
.view-switcher {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segmented button,
.view-switcher button {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segmented button {
  padding: 0 12px;
}

.view-switcher button {
  width: 36px;
}

.segmented button.active,
.view-switcher button.active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

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

.advanced-grid {
  margin-top: 14px;
}

[hidden] {
  display: none !important;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.check-row input {
  accent-color: var(--teal);
}

.runner-actions {
  margin-top: 16px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.tool-library {
  min-width: 0;
}

.library-header {
  margin-bottom: 14px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.tool-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.tool-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 82px;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.tool-card:hover,
.tool-card.active {
  border-color: color-mix(in srgb, var(--blue) 50%, var(--line));
  box-shadow: 0 10px 28px rgba(35, 100, 170, 0.14);
}

.tool-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.96rem;
}

.tool-card .chip {
  align-self: start;
  padding: 4px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--teal) 12%, var(--surface-2));
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
}

.tool-card[data-tier="AI"] .chip {
  color: var(--blue);
  background: color-mix(in srgb, var(--blue) 12%, var(--surface-2));
}

.tool-card[data-tier="Security"] .chip {
  color: var(--red);
  background: color-mix(in srgb, var(--red) 11%, var(--surface-2));
}

.tool-card[data-tier="Business"] .chip {
  color: var(--amber);
  background: color-mix(in srgb, var(--amber) 14%, var(--surface-2));
}

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

.tabs {
  justify-content: stretch;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.tabs button {
  flex: 1;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tabs button.active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 12px;
}

.job-item {
  display: grid;
  gap: 5px;
  padding: 12px;
}

.job-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.job-status {
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--amber) 16%, var(--surface));
  color: var(--amber);
  font-size: 0.72rem;
  font-weight: 900;
}

.job-status.done {
  color: var(--green);
  background: color-mix(in srgb, var(--green) 14%, var(--surface));
}

.job-status.failed {
  color: var(--red);
  background: color-mix(in srgb, var(--red) 12%, var(--surface));
}

.job-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.job-links a {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  max-width: 100%;
  padding: 0 9px;
  border: 1px solid color-mix(in srgb, var(--blue) 35%, var(--line));
  border-radius: 999px;
  color: var(--blue);
  background: var(--surface);
  font-size: 0.76rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.storage-meter {
  display: grid;
  gap: 9px;
  padding: 12px;
}

.storage-meter strong {
  font-size: 1rem;
}

.meter {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--blue) 10%, var(--surface));
}

.meter span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--blue);
}

.meter.green span {
  background: var(--green);
}

.api-box {
  display: grid;
  gap: 8px;
  padding: 12px;
}

code {
  overflow-wrap: anywhere;
  color: var(--blue);
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.offline-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.offline-page h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: 0;
}

.offline-page p {
  max-width: 34rem;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .inspector {
    position: static;
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 930px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .search {
    grid-column: 1 / -1;
    order: 3;
  }

  .workspace,
  .workbench {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .category-nav {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }

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

@media (max-width: 620px) {
  .topbar,
  .workspace {
    padding: 12px;
  }

  .brand small,
  .system-pill {
    display: none;
  }

  .metrics-band,
  .runner-grid,
  .split-controls {
    grid-template-columns: 1fr;
  }

  .install-button {
    width: 40px;
    padding: 0;
    gap: 0;
    font-size: 0;
  }

  .install-button .icon {
    width: 18px;
    height: 18px;
  }

  .section-title,
  .library-header {
    align-items: flex-start;
  }

  .tool-grid,
  .tool-grid.compact {
    grid-template-columns: 1fr;
  }

  .dropzone {
    min-height: 168px;
  }
}
