/* CloudDrive — design tokens. Single runtime source of truth (see DESIGN.md).
   Components must only reference these variables. */

:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --sunken: #eef1f5;
  --text: #161d24;
  --muted: #5f6b76;
  --line: #d9e0e7;
  --line-strong: #c3ccd6;
  --accent: #1e5a96;
  --accent-ink: #14406c;
  --accent-soft: #e7eef6;
  --on-accent: #ffffff;
  --warn: #8a5a17;
  --warn-soft: #f7efe1;
  --danger: #9b3b33;
  --danger-soft: #f8ebe9;
  --scrim: rgba(12, 20, 28, .44);
  --focus: color-mix(in srgb, var(--accent) 45%, transparent);
  --shadow-panel: 0 2px 6px rgba(15, 27, 38, .10);
  --shadow-overlay: 0 10px 28px rgba(10, 18, 26, .24);

  --r-control: 2px;
  --r-panel: 3px;
  --r-overlay: 4px;
  --r-chip: 2px;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --dur: 170ms;
  --ease: cubic-bezier(.2, .7, .3, 1);

  --row-grid: minmax(190px, 2.4fr) minmax(104px, 1.2fr) minmax(104px, 1fr) 88px 104px;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Cascadia Mono", Consolas, "Liberation Mono", "Courier New", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12171b;
  --surface: #181e24;
  --sunken: #1f262d;
  --text: #e6ecf1;
  --muted: #93a0ab;
  --line: #2a333b;
  --line-strong: #3a454f;
  --accent: #7fb0dc;
  --accent-ink: #d6e6f5;
  --accent-soft: #1b2a39;
  --on-accent: #0b1520;
  --warn: #d9a75a;
  --warn-soft: #33291a;
  --danger: #e08a80;
  --danger-soft: #33211f;
  --scrim: rgba(3, 7, 11, .64);
  --shadow-panel: 0 2px 6px rgba(0, 0, 0, .42);
  --shadow-overlay: 0 10px 28px rgba(0, 0, 0, .55);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #12171b;
    --surface: #181e24;
    --sunken: #1f262d;
    --text: #e6ecf1;
    --muted: #93a0ab;
    --line: #2a333b;
    --line-strong: #3a454f;
    --accent: #7fb0dc;
    --accent-ink: #d6e6f5;
    --accent-soft: #1b2a39;
    --on-accent: #0b1520;
    --warn: #d9a75a;
    --warn-soft: #33291a;
    --danger: #e08a80;
    --danger-soft: #33211f;
    --scrim: rgba(3, 7, 11, .64);
    --shadow-panel: 0 2px 6px rgba(0, 0, 0, .42);
    --shadow-overlay: 0 10px 28px rgba(0, 0, 0, .55);
  }
}

/* ---------------------------------------------------------------- base */

* { box-sizing: border-box; }

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body.overlay-open { overflow: hidden; }

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

svg { display: block; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%);
  white-space: nowrap;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.shell {
  max-width: 1280px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 62px;
  padding: 0 var(--s6);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: var(--r-control);
  background: var(--accent-soft);
  color: var(--accent);
}

.brand-mark svg { width: 17px; height: 17px; }

.search {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex: 1 1 260px;
  max-width: 520px;
  height: 38px;
  padding: 0 var(--s2) 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--bg);
  color: var(--muted);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.search:focus-within {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.search svg { width: 16px; height: 16px; flex: none; }

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

.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }

.search-clear {
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  flex: none;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.search-clear svg { width: 14px; height: 14px; }
.search-clear:hover { background: var(--sunken); color: var(--text); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-left: auto;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  min-height: 38px;
  padding: 0;
}

.icon-button svg { width: 17px; height: 17px; }

select,
button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
  padding: 0 11px;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform var(--dur) var(--ease);
}

select:hover,
button:hover { border-color: var(--line-strong); background: var(--sunken); }

button:active { transform: translateY(1px); }

.ghost-button {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 36px;
  padding: 0 var(--s3);
  background: var(--surface);
}

.ghost-button svg { width: 15px; height: 15px; color: var(--muted); }

.ghost-button[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.ghost-button[aria-expanded="true"] svg { color: var(--accent); }

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.primary:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 86%, var(--text));
  color: var(--on-accent);
}

.link-button {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button:hover { background: transparent; border-color: transparent; }

/* --------------------------------------------------------------- main */

main {
  flex: 1;
  padding: var(--s5) var(--s6) var(--s7);
}

.location {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 30px;
  margin-bottom: var(--s3);
  overflow: hidden;
}

.location-label {
  flex: none;
  font-size: 11.5px;
  letter-spacing: .09em;
  color: var(--muted);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.breadcrumbs::-webkit-scrollbar { display: none; }

.crumb {
  min-height: 26px;
  border: 0;
  background: none;
  padding: 0 2px;
  color: var(--muted);
  font-size: 13.5px;
}

.crumb:hover { background: none; border-color: transparent; color: var(--accent); }

.crumb:disabled { color: var(--text); font-weight: 620; cursor: default; }
.crumb-separator { color: var(--line-strong); font-size: 12px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  padding-bottom: var(--s3);
}

.toolbar-lead {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}

.toolbar select { max-width: 240px; }

.status {
  margin: 0 0 0 auto;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="warn"] { color: var(--warn); }

.filters {
  display: grid;
  grid-template-columns: 1.3fr 1.3fr .8fr .8fr auto;
  gap: var(--s4);
  align-items: end;
  padding: var(--s4);
  margin-bottom: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  animation: rise var(--dur) var(--ease);
}

.filters h3 {
  margin: 0 0 var(--s2);
  font-size: 11.5px;
  letter-spacing: .07em;
  color: var(--muted);
  text-transform: uppercase;
}

.filters label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12.5px;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 92px;
  overflow: auto;
}

.check {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-chip);
  background: var(--bg);
  color: var(--text) !important;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}

.check:hover { border-color: var(--line-strong); }

.check input {
  width: 14px; height: 14px;
  accent-color: var(--accent);
  margin: 0;
}

/* --------------------------------------------------------- file list */

.file-head {
  display: grid;
  grid-template-columns: var(--row-grid);
  align-items: center;
  gap: var(--s4);
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--line);
}

.head-cell {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: var(--s2) 0;
  font-size: 11.5px;
  letter-spacing: .07em;
  color: var(--muted);
  text-transform: uppercase;
}

.head-cell.head-size { justify-content: flex-end; }

.head-label { font: inherit; letter-spacing: inherit; text-transform: inherit; }

.head-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.head-sort:hover { background: none; border-color: transparent; color: var(--text); }
.head-sort:active { transform: none; }

.head-cell[aria-sort="ascending"] .head-sort,
.head-cell[aria-sort="descending"] .head-sort { color: var(--text); }

.head-caret { font-size: 10px; line-height: 1; color: var(--accent); }

.file-list { padding-bottom: var(--s5); }

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sentinel { grid-column: 1 / -1; height: 1px; list-style: none; }

.row {
  position: relative;
  display: grid;
  grid-template-columns: var(--row-grid);
  align-items: stretch;
  gap: var(--s4);
  min-height: 52px;
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--line);
  transition: background var(--dur) var(--ease);
}

.row:hover { background: var(--sunken); }

.row-open {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* stretched hit area: the whole row opens, while later positioned children
   (tag buttons) still receive their own clicks */
.row-open::after { content: ""; position: absolute; inset: 0; }

.row:has(.row-open:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.row-open:focus-visible { outline: none; }
.row-open:active { transform: none; }

.cell {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: var(--s3) 0;
}

/* explicit placement keeps columns aligned even when a cell is empty */
.cell-name { grid-column: 1; }
.cell-tags { grid-column: 2; }
.cell-origin { grid-column: 3; }
.cell-size { grid-column: 4; }
.cell-date { grid-column: 5; }

/* the "file spine": icon column rule runs the full row height */
.cell-name {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: stretch;
  padding: 0;
}

.cell-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  border-right: 1px solid var(--line);
  color: var(--accent);
}

.cell-icon svg { width: 18px; height: 18px; }

.file-name {
  display: flex;
  align-items: center;
  padding-left: var(--s3);
  font-weight: 560;
  overflow-wrap: anywhere;
}

.cell-tags { gap: 6px; flex-wrap: wrap; }

.cell-origin { gap: 6px; flex-wrap: wrap; }

.cell-size { justify-content: flex-end; color: var(--text); font-size: 12.5px; }
.cell-date { color: var(--muted); font-size: 12.5px; }

.tag,
.chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: var(--r-chip);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag { background: var(--sunken); color: var(--text); }
.chip { background: var(--surface); border-color: var(--line); color: var(--muted); }
.chip-type {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}
.chip-folder { background: var(--sunken); border-color: var(--line); color: var(--text); }
.chip-repo { background: var(--surface); border-color: var(--line); color: var(--text); }
.chip-release { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.chip-platform { background: var(--surface); border-color: var(--line); color: var(--muted); }

.tag-button {
  position: relative;
  min-height: 0;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-chip);
  background: var(--surface);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
  cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.tag-button:hover {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent-ink);
}

.tag-button:active { transform: none; }

.tag-button.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.release-group { margin-top: var(--s4); }

.release-heading {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: var(--s3) var(--s4);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 640;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}

.release-heading:hover { background: var(--sunken); border-color: var(--line); }
.release-heading:active { transform: none; }

.release-caret { width: 13px; text-align: center; color: var(--muted); font-size: 13px; }
.release-meta { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 11.5px; }

.release-heading .release-tag {
  font-family: var(--font-mono);
  color: var(--text);
  background: var(--sunken);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: var(--r-chip);
}

.release-heading .release-name {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}

/* -------------------------------------------------------- grid view */

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(186px, 1fr));
  gap: var(--s3);
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  background: var(--surface);
  overflow: hidden;
  transition: background var(--dur) var(--ease);
}

.card:hover { background: var(--sunken); }

.card-open {
  display: grid;
  align-content: start;
  gap: var(--s2);
  flex: 1;
  width: 100%;
  min-height: 130px;
  padding: var(--s4);
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.card-open::after { content: ""; position: absolute; inset: 0; }
.card:has(.card-open:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-open:focus-visible { outline: none; }
.card-open:active { transform: none; }
.sk-card { cursor: default; }

.card-icon { color: var(--accent); }
.card-icon svg { width: 22px; height: 22px; }
.card .file-name { display: block; padding: 0; font-size: 13.5px; }
.card-meta { color: var(--muted); font-size: 11.5px; }
.card-tags {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 var(--s4) var(--s4);
}

/* ---------------------------------------------------- loading / empty */

.sk {
  display: block;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--sunken) 25%, var(--line) 50%, var(--sunken) 75%);
  background-size: 240% 100%;
  animation: shimmer 1.3s linear infinite;
}

.sk-icon { width: 18px; height: 18px; border-radius: 2px; }
.sk-line { width: 62%; height: 10px; }
.sk-chip { width: 46px; height: 14px; border-radius: var(--r-chip); }
.sk-line.w40 { width: 34%; }
.sk-line.w60 { width: 52%; }

.empty {
  padding: var(--s7) var(--s5);
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  margin: 0 auto var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  color: var(--accent);
}

.empty-icon svg { width: 22px; height: 22px; }
.empty h2 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.empty p { margin: 0; font-size: 13px; }

.retry-button { margin-top: var(--s4); }

@keyframes shimmer { from { background-position: 140% 0; } to { background-position: -40% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ----------------------------------------------------------- overlays */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  justify-content: flex-end;
  background: var(--scrim);
  animation: fade-in var(--dur) var(--ease);
}

.drawer {
  position: relative;
  width: min(460px, 100%);
  min-height: 100%;
  padding: var(--s5);
  overflow: auto;
  background: var(--surface);
  box-shadow: var(--shadow-overlay);
  animation: slide-in 200ms var(--ease);
}

.close {
  position: absolute;
  top: 14px; right: 14px;
  display: grid;
  place-items: center;
  width: 32px; min-height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--muted);
}

.close:hover { background: var(--sunken); border-color: transparent; color: var(--text); }
.close svg { width: 15px; height: 15px; }

.detail-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-top: var(--s4);
}

.detail-icon {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  flex: none;
  border-radius: var(--r-control);
  background: var(--accent-soft);
  color: var(--accent);
}

.detail-icon svg { width: 20px; height: 20px; }
.drawer h2 { margin: 0; font-size: 17px; overflow-wrap: anywhere; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--s3); }

.detail-info {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 9px var(--s3);
  margin: var(--s5) 0;
  font-size: 13px;
}

.detail-info dt { color: var(--muted); }
.detail-info dd { margin: 0; overflow-wrap: anywhere; }
.detail-info dd.mono { font-size: 12.5px; }

.detail-actions { display: grid; gap: var(--s2); }
.detail-actions button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--s2);
  text-align: left;
}
.detail-actions button svg { width: 15px; height: 15px; flex: none; }

.preview,
.proxy-picker {
  position: relative;
  width: min(860px, calc(100% - 28px));
  max-height: 90vh;
  margin: auto;
  padding: var(--s5);
  overflow: auto;
  border-radius: var(--r-overlay);
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow-overlay);
  animation: fade-in var(--dur) var(--ease);
}

.preview img { max-width: 100%; max-height: 68vh; object-fit: contain; margin: 0 auto; }
.preview p { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }

.proxy-picker { width: min(420px, calc(100% - 28px)); text-align: left; }
.proxy-picker h2 { margin: var(--s4) 0 var(--s3); font-size: 15px; }
.proxy-picker p { color: var(--muted); font-size: 12.5px; }
.proxy-button {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  margin-bottom: var(--s2);
  text-align: left;
  justify-content: flex-start;
}
.proxy-button svg { width: 15px; height: 15px; flex: none; }

.toast {
  position: fixed;
  z-index: 20;
  bottom: var(--s5);
  left: 50%;
  transform: translateX(-50%);
  max-width: min(460px, calc(100% - 32px));
  padding: 10px var(--s4);
  border-radius: var(--r-control);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  box-shadow: var(--shadow-overlay);
  animation: fade-in var(--dur) var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
