:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #111827;
  --muted: #64748b;
  --line: #d7dee9;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #047857;
  --amber: #b45309;
  --red: #b91c1c;
  --shadow: 0 16px 38px rgba(15, 23, 42, 0.08);
}

* { 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;
  font-size: 15px;
}

button, input { font: inherit; }

input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }

h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 18px; }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

button {
  min-height: 40px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

button:hover { background: var(--blue-dark); }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
button.secondary:hover { border-color: var(--blue); color: var(--blue); }
button.danger { background: var(--red); border-color: var(--red); }
button.danger:hover { background: #991b1b; }

.status-strip {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 0.8fr;
  gap: 12px;
  margin-bottom: 16px;
}

.status-strip > div,
.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.status-strip > div {
  min-width: 0;
  padding: 14px 16px;
}

.status-strip span,
.card span,
.meta-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 7px;
}

.status-strip strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.config-panel { margin-bottom: 16px; }

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

.path-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  align-items: center;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.path-card span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.path-card strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.config-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.card { padding: 16px; }
.card strong { display: block; font-size: 28px; line-height: 1.1; }
.card small { display: block; color: var(--muted); margin-top: 8px; }
.card.accent { border-color: color-mix(in srgb, var(--blue) 45%, var(--line)); }
.card.warn { border-color: color-mix(in srgb, var(--amber) 45%, var(--line)); }
.card.history { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

.panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  align-items: center;
  gap: 16px;
}

.panel-head.split {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 14px;
}

.panel-head p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.meter {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width 180ms ease;
}

.errors {
  margin: 14px 0 0;
  max-height: 180px;
  overflow: auto;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f2;
  color: var(--red);
  padding: 12px;
  white-space: pre-wrap;
}

.groups {
  display: grid;
  gap: 12px;
}

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

.group {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.group-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 14px 16px;
  background: var(--surface-soft);
}

.group-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.badge {
  border-radius: 999px;
  padding: 4px 9px;
  background: #dbeafe;
  color: #1e40af;
  font-size: 12px;
  font-weight: 800;
}

.badge.history { background: #d1fae5; color: #065f46; }
.badge.warn { background: #fef3c7; color: #92400e; }

.group-head p {
  color: var(--muted);
  line-height: 1.45;
}

.group-stats {
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
}

.file-list {
  display: grid;
}

.file-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.file-row.keep { background: #f8fafc; }
.file-row input { width: 18px; height: 18px; }
.file-main { min-width: 0; }
.file-path {
  overflow-wrap: anywhere;
  font-weight: 750;
}
.file-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.action-pill {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.action-pill.keep { background: #e0f2fe; color: #075985; }
.action-pill.remove { background: #fee2e2; color: #991b1b; }

.history-list {
  padding: 0 16px 12px 62px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 920px) {
  .topbar, .panel-head, .panel-head.split { grid-template-columns: 1fr; display: grid; }
  .actions { justify-content: stretch; }
  .actions button, .panel-head button { width: 100%; }
  .status-strip, .cards, .config-grid { grid-template-columns: 1fr 1fr; }
  .browser-layout { grid-template-columns: 1fr; }
  .browser-roots { grid-template-columns: repeat(2, minmax(0, 1fr)); border-right: 0; border-bottom: 1px solid var(--line); }
  .group-head, .file-row { grid-template-columns: 1fr; }
  .group-stats { text-align: left; }
}

@media (max-width: 560px) {
  .shell { width: min(100vw - 24px, 1440px); padding-top: 18px; }
  .status-strip, .cards, .config-grid, .path-card, .browser-roots, .browser-toolbar, .modal-head, .modal-foot { grid-template-columns: 1fr; }
  .modal-head, .modal-foot { display: grid; }
  .path-card button, .modal-foot button { width: 100%; }
  h1 { font-size: 24px; }
}


.icon-only {
  width: 40px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.48);
}

.modal-panel {
  width: min(980px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.28);
}

.modal-head,
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-foot p {
  color: var(--muted);
  line-height: 1.45;
}

.browser-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 420px;
  overflow: hidden;
}

.browser-roots {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 12px;
}

.browser-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
}

.browser-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.browser-toolbar strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.root-row,
.directory-row {
  min-height: 48px;
  display: grid;
  gap: 4px;
  text-align: left;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.root-row:hover,
.directory-row:hover,
.root-row.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #eff6ff;
}

.root-row span,
.directory-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.root-row small,
.directory-row small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 600;
}

.directory-list {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
  padding: 12px;
}

.directory-list.empty {
  color: var(--muted);
  place-items: center;
  text-align: center;
}


@media (max-width: 920px) {
  .browser-layout { grid-template-columns: 1fr; }
  .browser-roots {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .status-strip, .cards, .config-grid, .path-card, .browser-roots, .browser-toolbar, .modal-head, .modal-foot { grid-template-columns: 1fr; }
  .modal-head, .modal-foot { display: grid; }
  .path-card button, .modal-foot button { width: 100%; }
}
