:root {
  --bg: #1c1c1e;
  --side: #242426;
  --panel: #202022;
  --raised: #2c2c2e;
  --line: rgba(255, 255, 255, .07);
  --text: #f2f2f7;
  --text-2: rgba(242, 242, 247, .55);
  --fill: rgba(255, 255, 255, .08);
  --fill-2: rgba(255, 255, 255, .14);
  --accent: #30d158;
  --accent-hover: #3ee066;
  --accent-soft: rgba(48, 209, 88, .16);
  --on-accent: #062a10;
  --danger: #ff453a;
  --danger-hover: #ff5b52;
  --blue: #0a84ff;
  --indigo: #5e5ce6;
  --warn-soft: rgba(255, 159, 10, .12);
  --warn-edge: rgba(255, 159, 10, .35);
  --glass: rgba(44, 44, 46, .82);
  --glass-edge: rgba(255, 255, 255, .1);
  --scrim: rgba(0, 0, 0, .5);
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  color-scheme: dark;
}
@media (prefers-contrast: more) {
  :root { --line: rgba(255, 255, 255, .3); --text-2: rgba(242, 242, 247, .8); --glass-edge: rgba(255, 255, 255, .4); }
}

* { box-sizing: border-box; }
/* our display rules would otherwise beat the UA's [hidden] */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

h1 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin: 0; }
h2 { font-size: 11px; font-weight: 600; color: var(--text-2); margin: 16px 8px 4px; }
h3 { font-size: 11px; font-weight: 600; color: var(--text-2); margin: 16px 0 6px; }
h3:empty { display: none; }
p { margin: 0 0 4px; }
.muted { color: var(--text-2); }
.tiny { font-size: 11px; line-height: 1.4; }
.path { word-break: break-all; font-size: 11px; }
.big { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.error { color: var(--danger); }

/* ------------------------------------------------------------- controls */

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
}
textarea { width: 100%; resize: vertical; margin-top: 6px; }
button {
  background: var(--fill);
  border: 0;
  border-radius: 7px;
  padding: 5px 11px;
  cursor: default;
  transition: transform 120ms var(--ease-out), background-color 120ms ease;
}
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .4; }
button.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
button.destructive { background: var(--danger); color: var(--text); font-weight: 600; }
button.danger { color: var(--danger); }
button.wide { width: 100%; margin-top: 6px; }
@media (hover: hover) and (pointer: fine) {
  button:hover:not(:disabled) { background: var(--fill-2); }
  button.primary:hover:not(:disabled) { background: var(--accent-hover); }
  button.destructive:hover:not(:disabled) { background: var(--danger-hover); }
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: -1px; }
summary { color: var(--text-2); font-size: 11px; padding: 4px 8px; }

.seg { display: flex; gap: 2px; padding: 2px; background: var(--fill); border-radius: 8px; }
.seg button { background: none; padding: 3px 12px; border-radius: 6px; color: var(--text-2); }
.seg button.on { background: var(--fill-2); color: var(--text); font-weight: 600; }

.row { display: flex; gap: 6px; margin-top: 6px; }
.row input { flex: 1; min-width: 0; }

.bar { display: flex; width: 100%; height: 8px; border-radius: 4px; overflow: hidden; background: var(--raised); }
.bar i { display: block; height: 100%; }

.callout {
  display: flex; gap: 8px; align-items: flex-start;
  margin: 8px 0; padding: 8px 10px; border-radius: 8px;
  background: var(--accent-soft); border: 1px solid var(--accent-soft);
  font-size: 12px;
}
.callout span { flex: 1; }
.callout button { padding: 1px 8px; }

/* --------------------------------------------------------------- toolbar */

#topbar {
  position: relative; z-index: 5;
  height: 46px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line);
}
#crumbs { flex: 1; min-width: 0; display: flex; gap: 2px; align-items: center; overflow: hidden; white-space: nowrap; }
#crumbs button { background: none; padding: 2px 6px; color: var(--text-2); }
#crumbs button:last-child { color: var(--text); font-weight: 600; }
#crumbs span { color: var(--text-2); }
#filter { width: 200px; background: var(--fill); border-color: transparent; }

/* ---------------------------------------------------------------- layout */

main { display: flex; height: calc(100% - 46px); }
#rail {
  width: 220px; flex: none; overflow-y: auto;
  padding: 6px 8px 16px;
  background: var(--side); border-right: 1px solid var(--line);
}
#center { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#inspector {
  width: 280px; flex: none; overflow-y: auto;
  display: flex; flex-direction: column;
  padding: 16px;
  background: var(--panel); border-left: 1px solid var(--line);
}

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  background: none; padding: 5px 8px; border-radius: 6px;
}
.nav button.on { background: var(--accent-soft); color: var(--accent); }
.badge {
  margin-left: auto; min-width: 18px; padding: 0 6px; border-radius: 9px;
  background: var(--accent); color: var(--on-accent);
  font-size: 11px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums;
}
#choose-more { margin-top: 2px; }
#choose-more .row, #choose-more textarea { margin-left: 8px; width: calc(100% - 8px); }

.banner {
  display: flex; gap: 8px; align-items: center;
  margin: 8px 0; padding: 8px 10px; border-radius: 8px;
  background: var(--warn-soft); border: 1px solid var(--warn-edge);
  font-size: 12px;
}
.banner span { flex: 1; }

/* ---------------------------------------------------------------- panels */

.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 18px 20px; overflow: auto; animation: fade-in 150ms ease-out; }
@keyframes fade-in { from { opacity: 0; } }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h1 { margin-right: auto; }

.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.hero h1 { font-size: 28px; }
#w-bar { max-width: 420px; height: 10px; border-radius: 5px; }
#w-used { background: var(--blue); }
.tiles { display: flex; gap: 10px; margin-top: 8px; }
.tile {
  width: 190px; padding: 14px; text-align: left;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 12px;
}
.tile b { font-size: 15px; }
.tile span { color: var(--text-2); }
.indet { max-width: 320px; }
.indet i { width: 30%; background: var(--accent); border-radius: 4px; animation: indet 1.1s linear infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
body.dropping::after {
  content: ""; position: fixed; inset: 6px; z-index: 50; pointer-events: none;
  border: 2px solid var(--accent); border-radius: 12px;
}

#mapview { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#title { margin-bottom: 12px; }
#title-sub { margin-top: 2px; }
#diskbar { max-width: 360px; height: 4px; margin-top: 8px; }
#disk-scan { background: var(--accent); }
#disk-other { background: var(--indigo); }
#disk-meta { margin-top: 4px; }
#viewbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
#status { margin-left: auto; font-size: 11px; }
#more-btn.on { background: var(--fill-2); font-weight: 600; }
#stage { position: relative; flex: 1; min-height: 0; border-radius: 10px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); }
#stage canvas { position: absolute; inset: 0; display: block; }
#overlay { pointer-events: none; }
#busy { position: absolute; top: 0; left: 0; z-index: 2; max-width: none; height: 3px; border-radius: 0; background: transparent; }
#dupe-busy { margin: 6px 0 10px; }
#image { transition: transform 180ms ease-out, opacity 120ms; }

/* -------------------------------------------------------------- popovers */

.pop-wrap { position: relative; }
.pop {
  position: absolute; top: calc(100% + 6px); z-index: 20;
  min-width: 200px; padding: 6px; border-radius: 10px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-edge); box-shadow: var(--shadow);
  opacity: 0; transform: scale(.96); visibility: hidden;
  transition: opacity 120ms ease-out, transform 120ms ease-out, visibility 0s 120ms;
}
/* ponytail: data-open toggle instead of @starting-style; works on every
   webview Tauri targets, and visibility keeps closed popovers out of tab order. */
.pop[data-open] {
  opacity: 1; transform: none; visibility: visible;
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}
#more-pop { left: 0; transform-origin: top left; }
#display-pop { right: 0; transform-origin: top right; min-width: 290px; }
#more-pop button { display: block; width: 100%; text-align: left; background: none; }
#more-pop button.on { color: var(--accent); }
#display-pop label { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 6px; color: var(--text-2); }
#display-pop select { min-width: 150px; }
#depth { width: 110px; vertical-align: middle; }

/* ------------------------------------------------------------- inspector */

#insp-empty { margin: auto 0; text-align: center; }
#i-name { font-size: 15px; font-weight: 600; word-break: break-all; margin: 0 0 2px; }
#i-size { margin: 10px 0 0; }
#add-cleanup { margin-top: 14px; }
#i-details { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12px; margin: 0; }
#i-details dt { color: var(--text-2); }
#i-details dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
#i-children { list-style: none; margin: 0; padding: 0; font-size: 12px; }
#i-children li { padding: 3px 0; }
#i-children .top { display: flex; justify-content: space-between; gap: 8px; }
#i-children .cname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#i-children .bar { display: block; height: 3px; margin-top: 3px; background: var(--fill-2); }
.hint { margin-top: auto; padding-top: 14px; font-size: 11px; color: var(--text-2); }

/* ----------------------------------------------------------------- lists */

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 7px 4px; border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.list .name, .list .p, .list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li.click { border-radius: 6px; }
@media (hover: hover) and (pointer: fine) { .list li.click:hover { background: var(--fill); } }
#wins small { color: var(--text-2); }
#typebar { height: 10px; margin-bottom: 12px; }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
#snaps li { justify-content: flex-start; }
.row2 { display: flex; justify-content: space-between; gap: 10px; width: 100%; min-width: 0; }
.plus { color: var(--accent); font-weight: 600; }
.minus { color: var(--danger); font-weight: 600; }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin-right: 6px; }
.list li.member { color: var(--text-2); padding-left: 16px; font-size: 12px; }
.shared { color: var(--blue); }

#mon-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
#mon-path { flex: 1; }
#mon-list .k { width: 68px; flex: none; color: var(--text-2); font-size: 11px; }
#mon-list .d { width: 88px; flex: none; text-align: right; }
#mon-list .d.up { color: var(--accent); }
#mon-list .p { font-size: 11px; }

/* --------------------------------------------------------------- cleanup */

#steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 4px 0 8px; counter-reset: s; }
#steps li { flex: 1; padding: 6px 10px; border-radius: 8px; background: var(--fill); color: var(--text-2); counter-increment: s; }
#steps li::before { content: counter(s) " · "; }
#steps li[data-active] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; margin-top: 14px; }
.cols h2 { margin: 0 0 6px; }
#tray-total { font-weight: 600; margin-top: 8px; }
#tray button.drop { background: none; color: var(--text-2); padding: 0 4px; }
@media (hover: hover) and (pointer: fine) { #tray button.drop:hover { color: var(--danger); } }
#stage-btn { flex: 2; }
#tray-clear { flex: 1; }
#pending li { flex-wrap: wrap; }
#pending .acts { display: flex; gap: 4px; flex: none; }
#pending button { padding: 2px 8px; font-size: 12px; }

/* ------------------------------------------------------------------ apps */

#apps-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#apps-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
#apps-head label { display: flex; align-items: center; gap: 6px; color: var(--text-2); margin: 0; }
#apps-refresh { margin-left: auto; }
#apps-body { flex: 1; display: grid; grid-template-columns: minmax(240px, 340px) 1fr; min-height: 0; }
#apps-list { list-style: none; margin: 0; padding: 6px; overflow: auto; background: var(--side); border-right: 1px solid var(--line); }
#apps-list li { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 8px; }
@media (hover: hover) and (pointer: fine) { #apps-list li:hover { background: var(--fill); } }
#apps-list li.on { background: var(--accent-soft); }
#apps-list .an { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#apps-list .as { font-variant-numeric: tabular-nums; }
#apps-list .al { display: block; font-size: 11px; font-weight: 400; color: var(--text-2); }
#app-detail { overflow: auto; padding: 20px 24px; }
#app-detail .foot { display: flex; gap: 26px; align-items: flex-end; margin: 6px 0 14px; }
#app-detail .foot .big { font-size: 26px; }
#app-detail .split { flex: 1; max-width: 420px; }
#app-detail .bar .b1 { background: var(--accent); }
#app-detail .bar .b2 { background: var(--indigo); }
#app-detail .keys { display: flex; gap: 16px; margin-top: 5px; font-size: 11px; color: var(--text-2); }
#app-detail .keys i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
#app-detail .grp { margin: 0 0 4px; }
#app-detail ul, #sheet-body ul { list-style: none; margin: 0 0 12px; padding: 0; }
#app-detail li, #sheet-body li { display: flex; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--line); }
#app-detail li .p, #sheet-body li .p { flex: 1; word-break: break-all; font-size: 11px; }
#app-detail li .ev, #sheet-body li .ev { display: block; color: var(--text-2); font-size: 10px; }
#app-detail li .b, #sheet-body li .b { min-width: 76px; text-align: right; align-self: flex-start; font-variant-numeric: tabular-nums; }
#app-detail li.locked, #sheet-body li.locked { opacity: .55; }

/* ----------------------------------------------------------------- sheet */

#sheet {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: var(--scrim);
  opacity: 0; visibility: hidden;
  transition: opacity 150ms ease-out, visibility 0s 150ms;
}
#sheet[data-open] { opacity: 1; visibility: visible; transition: opacity 200ms ease-out; }
#sheet-box {
  width: min(620px, 88vw); max-height: 80vh; overflow: auto;
  padding: 20px 24px; border-radius: 14px;
  background: var(--raised); border: 1px solid var(--glass-edge); box-shadow: var(--shadow);
  transform: translateY(8px) scale(.98);
  transition: transform 150ms ease-out;
}
#sheet[data-open] #sheet-box { transform: none; transition: transform 220ms var(--ease-out); }
#sheet-box h2 { font-size: 17px; color: var(--text); margin: 0 0 4px; }
#sheet-body { margin: 12px 0; }
#sheet-body:empty { display: none; }
.sheet-actions { justify-content: flex-end; margin-top: 14px; }
#sheet-note:empty { display: none; }

/* --------------------------------------------------- toast, tip, quicklook */

#toast {
  position: fixed; left: 50%; bottom: 20px; z-index: 40;
  display: flex; gap: 12px; align-items: center;
  padding: 10px 14px; border-radius: 12px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-edge); box-shadow: var(--shadow);
  transform: translate(-50%, calc(100% + 24px)); visibility: hidden;
  transition: transform 180ms ease-out, visibility 0s 180ms;
}
#toast[data-open] { transform: translate(-50%, 0); visibility: visible; transition: transform 250ms var(--ease-out); }
#toast button { background: none; color: var(--accent); border: 1px solid var(--glass-edge); padding: 4px 10px; }

#tip {
  position: absolute; z-index: 20; pointer-events: none;
  display: flex; gap: 10px; max-width: 360px;
  padding: 8px 10px; border-radius: 10px; font-size: 12px;
  background: var(--glass); border: 1px solid var(--glass-edge); box-shadow: var(--shadow);
}
#tip img { width: 96px; height: 96px; object-fit: contain; border-radius: 6px; background: var(--bg); }
#tip b { display: block; margin-bottom: 2px; }

#ql { max-width: 80vw; padding: 16px; border-radius: 14px; background: var(--raised); color: var(--text); border: 1px solid var(--glass-edge); }
#ql::backdrop { background: var(--scrim); }
#ql img { display: block; max-width: 100%; max-height: 70vh; margin-bottom: 8px; }

/* ------------------------------------------------------- accessibility */

@media (prefers-reduced-transparency: reduce) {
  #topbar, .pop, #toast, #tip { background: var(--raised); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  button:active:not(:disabled) { transform: none; }
  .pop, #sheet-box { transform: none; }
  #toast { transform: translate(-50%, 0); opacity: 0; transition: opacity 150ms, visibility 0s 150ms; }
  #toast[data-open] { opacity: 1; transition: opacity 150ms; }
  #image { transition: none; }
  .indet i { animation: none; width: 100%; opacity: .5; }
}
