:root {
  color-scheme: light;
  --page: #f5f6f2;
  --surface: #ffffff;
  --surface-soft: #f8f9f5;
  --surface-strong: #eef2e9;
  --ink: #19211c;
  --muted: #667168;
  --subtle: #8b948c;
  --line: #dce3dc;
  --line-strong: #bcc8be;
  --green: #2d7556;
  --green-soft: #e5f3eb;
  --teal: #23777f;
  --teal-soft: #e1f2f3;
  --blue: #345f98;
  --blue-soft: #e5edfb;
  --amber: #9a6a1f;
  --amber-soft: #fff1d6;
  --coral: #b34b42;
  --coral-soft: #ffe7e2;
  --shadow: 0 18px 42px rgba(25, 33, 28, 0.08);
  --radius: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family:
    "Inter",
    "Segoe UI Variable Text",
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(25, 33, 28, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(25, 33, 28, 0.035) 1px, transparent 1px),
    var(--page);
  background-size: 34px 34px;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

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

h1,
h2,
h3,
p,
dl,
dd {
  margin: 0;
}

input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.hidden,
[hidden] {
  display: none !important;
}

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

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

.app-shell {
  width: min(1680px, 100%);
  height: 100vh;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  gap: var(--space-4);
  margin: 0 auto;
  padding: var(--space-4);
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: var(--space-5);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.brand.compact {
  display: none;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--radius);
  color: #ffffff;
  background: #245d46;
  font-weight: 850;
}

.brand h1 {
  overflow: hidden;
  font-size: 1.35rem;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  display: inline-block;
  color: var(--subtle);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.nav-list {
  display: grid;
  align-content: start;
  gap: var(--space-2);
}

.nav-item,
.mobile-tab,
.icon-button,
.primary-button,
.secondary-button,
.text-button,
.queue-action,
.file-picker,
.folder-picker {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius);
  font-weight: 760;
  transition:
    transform 160ms var(--ease),
    background 160ms var(--ease),
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease);
}

.nav-item {
  justify-content: start;
  width: 100%;
  padding: 0 var(--space-3);
  color: var(--muted);
  background: transparent;
}

.nav-item:hover,
.nav-item.is-active {
  color: var(--green);
  background: var(--green-soft);
}

.nav-item.is-active {
  box-shadow: inset 3px 0 0 var(--green);
}

.sidebar-footer {
  display: grid;
  gap: var(--space-3);
}

.status-card {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.status-card div {
  min-width: 0;
}

.status-card strong,
.status-card span:last-child {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-card span:last-child {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--blue);
  box-shadow: 0 0 0 4px rgba(52, 95, 152, 0.13);
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(45, 117, 86, 0.14);
}

.status-dot.offline {
  background: var(--coral);
  box-shadow: 0 0 0 4px rgba(179, 75, 66, 0.14);
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr;
}

.mobile-topbar {
  display: none;
}

.view {
  min-width: 0;
  min-height: 0;
  display: none;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--space-4);
}

.view.is-active {
  display: grid;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 96px;
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.view-header div:first-child {
  min-width: 0;
}

.view-header h2 {
  margin-top: 3px;
  font-size: clamp(1.55rem, 2vw, 2.25rem);
  line-height: 1.05;
}

.view-header p {
  max-width: 720px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.work-grid,
.theme-grid,
.status-grid {
  min-height: 0;
  display: grid;
  gap: var(--space-4);
}

.work-grid {
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
}

.theme-grid,
.status-grid {
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
}

.tool-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: var(--space-4);
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 2px rgba(25, 33, 28, 0.06);
}

.queue-panel,
.action-panel {
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.panel-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
}

.panel-title h3 {
  margin-top: 3px;
  font-size: 1.15rem;
  line-height: 1.15;
}

.icon-button,
.secondary-button,
.file-picker,
.folder-picker,
.queue-action {
  border: 1px solid var(--line);
  background: #ffffff;
}

.icon-button,
.secondary-button {
  padding: 0 var(--space-3);
}

.icon-button.wide {
  width: 100%;
}

.icon-button:hover,
.secondary-button:hover,
.queue-action:hover,
.file-picker:hover,
.folder-picker:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 8px 22px rgba(25, 33, 28, 0.08);
}

.primary-button {
  padding: 0 var(--space-4);
  color: #ffffff;
  background: var(--green);
  box-shadow: 0 12px 26px rgba(45, 117, 86, 0.18);
}

.primary-button:hover {
  transform: translateY(-1px);
  background: #246347;
}

.text-button {
  min-height: 34px;
  padding: 0 var(--space-2);
  color: var(--green);
  background: transparent;
}

.text-button:hover {
  background: var(--green-soft);
}

.metric-pill,
.soft-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  max-width: 100%;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.86rem;
  font-weight: 760;
  white-space: nowrap;
}

.metric-pill {
  color: var(--teal);
  border-color: #b9dadd;
  background: var(--teal-soft);
}

.drop-zone {
  position: relative;
  min-height: 176px;
  display: grid;
  place-items: center;
  gap: var(--space-2);
  padding: var(--space-5);
  overflow: hidden;
  text-align: center;
  border: 1px dashed #a9c7b6;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(229, 243, 235, 0.74), rgba(255, 255, 255, 0.92)),
    var(--surface);
}

.drop-zone:hover,
.drop-zone.is-dragover {
  border-color: var(--green);
  box-shadow: 0 14px 30px rgba(45, 117, 86, 0.12);
}

.drop-zone.is-disabled {
  pointer-events: none;
}

.drop-visual {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid #b9d5c4;
  border-radius: var(--radius);
  color: var(--green);
  background: #ffffff;
}

.drop-zone strong {
  font-size: 1.05rem;
}

.drop-zone span:last-child,
.queue-meta span {
  color: var(--muted);
}

.folder-picker {
  position: relative;
  justify-content: start;
  min-height: 44px;
  padding: 0 var(--space-3);
  overflow: hidden;
  color: var(--green);
  background: var(--green-soft);
  border-color: #b9d5c4;
}

.folder-picker input {
  cursor: pointer;
}

.queue-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 48px;
  padding-block: var(--space-3);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.queue-meta strong {
  white-space: nowrap;
}

.file-list,
.theme-list,
.workflow-form,
.theme-form,
.manual-theme-form,
.capability-list {
  display: grid;
  gap: var(--space-3);
}

.file-list {
  min-height: 0;
  max-height: min(420px, calc(100vh - 445px));
  overflow: auto;
  padding-right: 2px;
}

.empty-state {
  min-height: 70px;
  display: grid;
  align-items: center;
  padding: var(--space-4);
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.file-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 64px;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.file-order {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--teal);
  background: var(--teal-soft);
  font-size: 0.86rem;
  font-weight: 820;
}

.file-info {
  min-width: 0;
}

.file-info strong,
.theme-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-info span,
.theme-row span {
  color: var(--muted);
  font-size: 0.88rem;
}

.file-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.queue-action {
  width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--muted);
}

.queue-action.danger {
  color: var(--coral);
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field span {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 760;
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: #ffffff;
}

.field.compact input {
  min-height: 42px;
}

.field input:focus {
  border-color: #8ab99e;
  box-shadow: 0 0 0 4px rgba(45, 117, 86, 0.12);
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 76px;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.action-row div {
  min-width: 0;
}

.action-row strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-panel {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.state-panel h3 {
  margin-top: 3px;
}

.state-panel p {
  color: var(--muted);
  line-height: 1.45;
}

.state-panel.pending {
  border-color: #b9d5c4;
  background: #f5fbf7;
}

.state-panel.success {
  border-color: #b9d5c4;
  background: #f3faf5;
}

.state-panel.error {
  border-color: #efbeb8;
  background: #fff6f4;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.progress-track span {
  width: 0%;
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--teal), var(--amber));
  transition: width 220ms var(--ease);
}

.state-panel.pending .progress-track span {
  width: 68%;
  animation: progressSlide 1.2s ease-in-out infinite alternate;
}

@keyframes progressSlide {
  from {
    transform: translateX(-34%);
  }

  to {
    transform: translateX(48%);
  }
}

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

.theme-list {
  max-height: min(520px, calc(100vh - 265px));
  overflow: auto;
  padding-right: 2px;
}

.theme-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 62px;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.theme-row.is-active {
  border-color: #b9d5c4;
  background: var(--green-soft);
}

.theme-row.is-editing {
  grid-template-columns: minmax(0, 1fr);
}

.theme-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: var(--space-1);
}

.theme-rename-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-3);
}

.secondary-button.compact {
  min-height: 34px;
  padding: 0 var(--space-2);
  font-size: 0.86rem;
}

.file-picker {
  position: relative;
  justify-content: start;
  min-height: 48px;
  padding: 0 var(--space-3);
  overflow: hidden;
  color: var(--muted);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.manual-theme-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.data-grid div {
  min-width: 0;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--line);
}

.data-grid dt {
  color: var(--subtle);
  font-size: 0.75rem;
  font-weight: 820;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.data-grid dd {
  margin-top: 5px;
  overflow: hidden;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.capability-list div {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 66px;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--line);
}

.capability-list .app-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: var(--blue);
  background: var(--blue-soft);
}

.capability-list .app-icon svg {
  width: 18px;
  height: 18px;
}

.capability-list strong,
.capability-list span {
  display: block;
}

.capability-list span {
  color: var(--muted);
}

.toast-region {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 40;
  display: grid;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: grid;
  gap: 3px;
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.toast span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.toast.success {
  border-color: #b9d5c4;
}

.toast.error {
  border-color: #efbeb8;
}

@media (max-width: 1180px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: minmax(0, 1fr);
    overflow: visible;
  }

  .sidebar {
    display: none;
  }

  .workspace {
    gap: var(--space-4);
  }

  .mobile-topbar {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
  }

  .brand.compact {
    display: flex;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-2);
  }

  .mobile-tab {
    min-height: 42px;
    color: var(--muted);
    border: 1px solid var(--line);
    background: #ffffff;
  }

  .mobile-tab.is-active {
    color: var(--green);
    border-color: #b9d5c4;
    background: var(--green-soft);
  }

  .view {
    min-height: auto;
  }

  .file-list,
  .theme-list {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 920px) {
  .app-shell {
    padding: var(--space-3);
  }

  .view-header,
  .work-grid,
  .theme-grid,
  .status-grid,
  .data-grid,
  .manual-theme-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .view-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions,
  .action-row,
  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button,
  .icon-button,
  .folder-picker {
    width: 100%;
  }

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

  .theme-rename-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .theme-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
  }

  .file-order {
    width: 100%;
  }

  .file-actions,
  .result-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .queue-action {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: var(--space-2);
  }

  .view-header,
  .tool-panel {
    padding: var(--space-4);
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .view-header h2 {
    font-size: 1.45rem;
  }

  .queue-meta {
    align-items: start;
    flex-direction: column;
  }
}
