/* DataCenter — UI styles. Light tokens by default, dark via system or toggle. */

:root {
  --bg:            #f7f8fa;
  --bg-sunken:     #eef0f4;
  --surface:       #ffffff;
  --surface-2:     #f2f4f7;
  --surface-hover: #e9ecf1;
  --border:        #dce0e7;
  --border-strong: #c3c9d4;
  --text:          #171a1f;
  --text-2:        #5b6472;
  --text-3:        #8b93a1;
  --accent:        #1f6feb;
  --accent-text:   #ffffff;
  --accent-soft:   #e3edfd;
  --danger:        #c8372d;
  --danger-soft:   #fcebe9;
  --ok:            #1a7f4b;
  --shadow-1: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-2: 0 4px 12px rgba(16,24,40,.10), 0 2px 4px rgba(16,24,40,.06);
  --shadow-3: 0 16px 40px rgba(16,24,40,.18);
  --radius: 10px;
  --radius-sm: 7px;
  --gutter: 16px;
  --topbar-h: 104px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0d1117;
    --bg-sunken:     #090c11;
    --surface:       #161b22;
    --surface-2:     #1c2230;
    --surface-hover: #232b3a;
    --border:        #2a313d;
    --border-strong: #3a434f;
    --text:          #e8edf4;
    --text-2:        #9aa5b4;
    --text-3:        #6e7888;
    --accent:        #4f8ff7;
    --accent-text:   #06121f;
    --accent-soft:   #16263f;
    --danger:        #f06a5d;
    --danger-soft:   #2a1614;
    --ok:            #46c07d;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 4px 14px rgba(0,0,0,.45);
    --shadow-3: 0 18px 48px rgba(0,0,0,.6);
  }
}

:root[data-theme="dark"] {
  --bg:            #0d1117;
  --bg-sunken:     #090c11;
  --surface:       #161b22;
  --surface-2:     #1c2230;
  --surface-hover: #232b3a;
  --border:        #2a313d;
  --border-strong: #3a434f;
  --text:          #e8edf4;
  --text-2:        #9aa5b4;
  --text-3:        #6e7888;
  --accent:        #4f8ff7;
  --accent-text:   #06121f;
  --accent-soft:   #16263f;
  --danger:        #f06a5d;
  --danger-soft:   #2a1614;
  --ok:            #46c07d;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 4px 14px rgba(0,0,0,.45);
  --shadow-3: 0 18px 48px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

.muted { color: var(--text-2); }
.topbar-spacer { flex: 1 1 auto; }
[hidden] { display: none !important; }

.i { width: 18px; height: 18px; flex: none; fill: none;
     stroke: currentColor; stroke-width: 1.8;
     stroke-linecap: round; stroke-linejoin: round; }

/* ───────────────────────────────────────────────────────────  buttons ──── */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px;
  font: inherit; font-weight: 500; font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background .13s, border-color .13s, transform .06s;
  white-space: nowrap;
}
.btn:hover  { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .seg:focus-visible,
input:focus-visible, .card:focus-visible, .row:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary {
  background: var(--accent); color: var(--accent-text);
  border-color: transparent;
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-block { width: 100%; justify-content: center; padding: 10px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  color: var(--text-2);
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background .13s, color .13s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.segmented { display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.seg { display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 28px; color: var(--text-2);
  background: transparent; border: 0; border-radius: 5px; cursor: pointer; }
.seg[aria-pressed="true"] { background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-1); }

/* ─────────────────────────────────────────────────────────────  login ──── */

.login { min-height: 100dvh; display: grid; place-items: center;
  padding: var(--gutter); background: var(--bg-sunken); }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 24px;
  box-shadow: var(--shadow-3); text-align: center;
}
.login-mark { display: grid; place-items: center; width: 48px; height: 48px;
  margin: 0 auto 14px; color: var(--accent);
  background: var(--accent-soft); border-radius: 12px; }
.login-mark svg { width: 26px; height: 26px; fill: none;
  stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.01em; }
.login-card .muted { margin: 0 0 18px; font-size: 13.5px; }
.login-error { margin: 0 0 12px; padding: 8px 10px; font-size: 13px;
  color: var(--danger); background: var(--danger-soft);
  border: 1px solid var(--danger); border-radius: var(--radius-sm); }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field-label { display: block; margin-bottom: 5px; font-size: 12.5px;
  font-weight: 500; color: var(--text-2); }
.field input {
  width: 100%; padding: 9px 11px;
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
.field input:focus { border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft); }

/* ────────────────────────────────────────────────────────────  topbar ──── */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red, blue)) {
  .topbar { background: var(--bg); }
}
.topbar-row { display: flex; align-items: center; gap: 10px;
  padding: 10px var(--gutter); }
.topbar-actions { display: flex; align-items: center; gap: 7px; }
.topbar-meta { display: flex; align-items: center; gap: 12px;
  padding: 0 var(--gutter) 9px; font-size: 12.5px; min-height: 20px; }

.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: nowrap;
  overflow-x: auto; scrollbar-width: none; min-width: 0; }
.crumbs::-webkit-scrollbar { display: none; }
.crumb { padding: 4px 7px; font-size: 14px; font-weight: 500;
  color: var(--text-2); background: none; border: 0;
  border-radius: 6px; cursor: pointer; white-space: nowrap; }
.crumb:hover { background: var(--surface-hover); color: var(--text); }
.crumb[aria-current] { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--text-3); flex: none; }

.search { position: relative; display: flex; align-items: center;
  width: clamp(160px, 24vw, 300px); }
.search-icon { position: absolute; left: 9px; color: var(--text-3);
  width: 16px; height: 16px; pointer-events: none; }
.search input {
  width: 100%; padding: 7px 30px 7px 31px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; -webkit-appearance: none; appearance: none;
}
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { background: var(--surface); border-color: var(--accent);
  outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.search-clear { position: absolute; right: 5px; display: grid;
  place-items: center; width: 22px; height: 22px; padding: 0;
  color: var(--text-3); background: none; border: 0; border-radius: 50%;
  cursor: pointer; }
.search-clear:hover { background: var(--surface-hover); color: var(--text); }
.search-clear .i { width: 14px; height: 14px; }

.usage { display: inline-flex; align-items: center; gap: 8px; }
.usage-bar { width: 110px; height: 5px; background: var(--surface-2);
  border-radius: 999px; overflow: hidden; }
.usage-fill { display: block; height: 100%; width: 0;
  background: var(--accent); border-radius: 999px; transition: width .4s; }

/* ────────────────────────────────────────────────────────────  selbar ──── */

.selbar {
  position: sticky; top: var(--topbar-h); z-index: 25;
  display: flex; align-items: center; gap: 9px;
  padding: 9px var(--gutter);
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
}
.sel-count { font-size: 14px; font-weight: 600; }

/* ─────────────────────────────────────────────────────────────  main ──── */

main { padding: 18px var(--gutter) 64px; }

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: border-color .13s, box-shadow .13s, transform .08s;
  text-align: left;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2);
  transform: translateY(-1px); }
.card[data-selected="true"] { border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-2); }

.thumb { position: relative; aspect-ratio: 4/3; display: grid;
  place-items: center; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .25s; }
.thumb img.loaded { opacity: 1; }
.thumb .glyph { width: 34px; height: 34px; color: var(--text-3);
  stroke-width: 1.5; }
.card[data-kind="folder"] .thumb { background: var(--accent-soft); }
.card[data-kind="folder"] .glyph { color: var(--accent); }

.badge { position: absolute; bottom: 6px; right: 6px;
  padding: 2px 6px; font-size: 11px; font-weight: 600;
  color: #fff; background: rgba(0,0,0,.66); border-radius: 5px;
  backdrop-filter: blur(4px); }

.card-body { padding: 8px 10px 10px; min-width: 0; }
.card-name { font-size: 13.5px; font-weight: 500; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word; }
.card-meta { margin-top: 3px; font-size: 11.5px; color: var(--text-3); }

.check {
  position: absolute; top: 7px; left: 7px; z-index: 2;
  width: 21px; height: 21px; display: grid; place-items: center;
  background: rgba(255,255,255,.9); border: 1px solid var(--border-strong);
  border-radius: 5px; cursor: pointer; opacity: 0; transition: opacity .12s;
}
.card:hover .check, .check[data-on="true"],
.row:hover .check, .grid[data-selecting="true"] .check { opacity: 1; }
.check[data-on="true"] { background: var(--accent); border-color: var(--accent); }
.check svg { width: 13px; height: 13px; color: #fff; opacity: 0;
  stroke-width: 3; fill: none; stroke: currentColor; }
.check[data-on="true"] svg { opacity: 1; }

/* list view */
.table { width: 100%; border-collapse: collapse;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-1); }
.table thead th {
  position: sticky; top: var(--topbar-h); z-index: 5;
  padding: 9px 12px; font-size: 12px; font-weight: 600; text-align: left;
  color: var(--text-2); background: var(--surface-2);
  border-bottom: 1px solid var(--border); cursor: pointer;
  white-space: nowrap;
}
.table thead th:hover { color: var(--text); }
.table th .arrow { opacity: .35; }
.table th[aria-sort] .arrow { opacity: 1; color: var(--accent); }
.row { cursor: pointer; }
.row:hover { background: var(--surface-hover); }
.row[data-selected="true"] { background: var(--accent-soft); }
.row td { padding: 8px 12px; font-size: 13.5px;
  border-bottom: 1px solid var(--border); vertical-align: middle; }
.row:last-child td { border-bottom: 0; }
.cell-name { display: flex; align-items: center; gap: 9px; min-width: 0; }
.cell-name .glyph { width: 17px; height: 17px; flex: none; color: var(--text-3); }
.row[data-kind="folder"] .glyph { color: var(--accent); }
.cell-name .label { overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.col-size, .col-date { color: var(--text-2); white-space: nowrap;
  font-variant-numeric: tabular-nums; }
.col-actions { width: 38px; text-align: right; }
.table .check { position: static; opacity: 1; background: transparent;
  border-color: var(--border-strong); }
.table .check[data-on="true"] { background: var(--accent); }

.rowmenu { position: relative; }

/* states */
.state { display: grid; place-items: center; gap: 10px;
  padding: 64px var(--gutter); text-align: center; color: var(--text-2); }
.state svg { width: 34px; height: 34px; color: var(--text-3); }
.state h2 { margin: 0; font-size: 16px; color: var(--text); }
.state p { margin: 0; font-size: 14px; max-width: 42ch; }

.skeleton-grid { display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.sk { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; }
.sk-thumb { aspect-ratio: 4/3; background: var(--surface-2); }
.sk-line { height: 9px; margin: 10px; border-radius: 5px;
  background: var(--surface-2); }
.sk-line.short { width: 50%; }
.sk, .sk-thumb, .sk-line { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.section-label { margin: 2px 0 10px; font-size: 12px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }

/* ──────────────────────────────────────────────────────────  dropzone ──── */

.dropzone { position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: var(--gutter);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(6px); }
.dropzone-inner { display: grid; place-items: center; gap: 10px;
  width: min(460px, 100%); padding: 42px 24px; text-align: center;
  color: var(--accent); border: 2px dashed var(--accent);
  border-radius: 16px; background: var(--surface); }
.dropzone-inner .i { width: 34px; height: 34px; }
.dropzone-inner p { margin: 0; font-size: 15px; font-weight: 500;
  color: var(--text); }

/* ──────────────────────────────────────────────────────────  lightbox ──── */

.lightbox { position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: #06080c; }
.lb-bar { position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; color: #e8edf4;
  background: linear-gradient(to bottom, rgba(0,0,0,.72), transparent); }
.lb-bar .icon-btn { color: #cbd3de; }
.lb-bar .icon-btn:hover { background: rgba(255,255,255,.14); color: #fff; }
.lb-title { font-size: 14px; font-weight: 500; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; max-width: 52vw; }
.lb-count { color: #9aa5b4 !important; font-size: 12.5px; }
.lb-stage { display: grid; place-items: center;
  width: 100%; height: 100%; padding: 56px 16px 24px; }
.lb-stage img, .lb-stage video {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 6px; background: #000; }
.lb-stage audio { width: min(520px, 90vw); }
.lb-stage iframe { width: 100%; height: 100%; border: 0; border-radius: 6px;
  background: #fff; }
.lb-stage pre { max-width: 100%; max-height: 100%; margin: 0;
  padding: 16px; overflow: auto; font-size: 13px; line-height: 1.55;
  color: #e8edf4; background: #11161d; border-radius: 8px;
  white-space: pre-wrap; }
.lb-fallback { display: grid; place-items: center; gap: 12px;
  color: #cbd3de; text-align: center; }
.lb-fallback .i { width: 38px; height: 38px; }
.lb-nav { position: absolute; z-index: 2; top: 50%;
  transform: translateY(-50%);
  display: grid; place-items: center; width: 42px; height: 68px;
  color: #e8edf4; background: rgba(0,0,0,.4); border: 0;
  border-radius: 8px; cursor: pointer; }
.lb-nav:hover { background: rgba(0,0,0,.66); }
.lb-nav .i { width: 24px; height: 24px; }
.lb-prev { left: 10px; } .lb-next { right: 10px; }
.lb-spinner { width: 26px; height: 26px; border: 2.5px solid rgba(255,255,255,.2);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────────────────────────  modal ──── */

.modal { position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: var(--gutter);
  background: rgba(8,11,16,.55); backdrop-filter: blur(3px); }
.modal-card { width: min(400px, 100%); padding: 22px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-3); }
.modal-card h2 { margin: 0 0 6px; font-size: 17px; }
.modal-card .muted { margin: 0 0 16px; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ───────────────────────────────────────────────────────────  uploads ──── */

.uploads { position: fixed; right: var(--gutter); bottom: var(--gutter);
  z-index: 70; width: min(330px, calc(100vw - 2 * var(--gutter)));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-3); overflow: hidden; }
.uploads-head { display: flex; align-items: center; gap: 8px;
  padding: 10px 8px 10px 14px; font-size: 14px;
  border-bottom: 1px solid var(--border); }
.uploads-head strong { flex: 1 1 auto; font-size: 13.5px; }
.uploads-list { max-height: 240px; margin: 0; padding: 6px;
  overflow-y: auto; list-style: none; }
.up-item { padding: 7px 8px; font-size: 13px; }
.up-row { display: flex; gap: 8px; align-items: baseline; }
.up-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.up-pct { font-size: 11.5px; color: var(--text-3);
  font-variant-numeric: tabular-nums; }
.up-bar { height: 4px; margin-top: 5px; background: var(--surface-2);
  border-radius: 999px; overflow: hidden; }
.up-fill { display: block; height: 100%; width: 0; background: var(--accent);
  transition: width .2s; }
.up-item[data-state="done"] .up-fill   { background: var(--ok); }
.up-item[data-state="error"] .up-fill  { background: var(--danger); }
.up-item[data-state="error"] .up-pct   { color: var(--danger); }

/* ────────────────────────────────────────────────────────────  toasts ──── */

.toasts { position: fixed; left: 50%; bottom: 20px; z-index: 100;
  display: grid; gap: 8px; transform: translateX(-50%);
  width: min(420px, calc(100vw - 2 * var(--gutter))); }
.toast { display: flex; align-items: center; gap: 9px;
  padding: 10px 13px; font-size: 13.5px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-3);
  animation: toast-in .18s ease-out; }
.toast[data-kind="error"] { border-left-color: var(--danger); }
.toast[data-kind="ok"]    { border-left-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ────────────────────────────────────────────────────────  responsive ──── */

.only-mobile { display: none; }

@media (max-width: 900px) {
  .btn-text { display: none; }
  .btn { padding: 7px 9px; }
  .search { width: auto; flex: 1 1 120px; }
}

@media (max-width: 680px) {
  :root { --topbar-h: 96px; }
  .only-mobile { display: inline-flex; }
  .topbar-row { flex-wrap: wrap; }
  .crumbs { order: 1; width: 100%; }
  .search { order: 3; flex: 1 1 100%; }
  .topbar-actions { order: 2; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
  .col-date { display: none; }
  .lb-title { max-width: 40vw; }
  .lb-nav { width: 36px; height: 56px; }
  main { padding-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun  { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
  :root[data-theme="light"] .i-sun  { display: block; }
  :root[data-theme="light"] .i-moon { display: none; }
}
