:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1b1f27;
  --muted: #646c7a;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefd;
  --danger: #c4314b;
  --ok: #1f8a4c;
  --folder: #5b8def;
  --shadow: 0 8px 30px rgba(20, 28, 45, 0.12);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318; --surface: #191c23; --surface-2: #20242d; --border: #2c313c; --text: #e8eaef;
    --muted: #9aa2b1; --accent: #6d8ff5; --accent-ink: #0d1020; --accent-soft: #232c45; --danger: #f06a80;
    --ok: #4cc37f; --folder: #7aa2f7; --shadow: 0 8px 30px rgba(0, 0, 0, 0.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111318; --surface: #191c23; --surface-2: #20242d; --border: #2c313c; --text: #e8eaef;
  --muted: #9aa2b1; --accent: #6d8ff5; --accent-ink: #0d1020; --accent-soft: #232c45; --danger: #f06a80;
  --ok: #4cc37f; --folder: #7aa2f7; --shadow: 0 8px 30px rgba(0, 0, 0, 0.5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.hidden { display: none !important; }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--muted); line-height: 0; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=url], select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .row:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

/* Auth screens */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand svg { width: 28px; height: 28px; }
.auth-card .brand { margin-bottom: 22px; }
.auth-card .btn.primary { width: 100%; justify-content: center; padding: 10px; }

/* App layout */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 4px 8px 16px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.quota { margin-top: auto; padding: 10px; font-size: 12.5px; color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; gap: 12px; align-items: center; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .search { flex: 1; max-width: 520px; }
.topbar .menu-btn { display: none; }
.content { padding: 20px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .spacer { flex: 1; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 18px; font-weight: 600; }
.crumbs a { color: var(--muted); padding: 2px 4px; border-radius: 6px; }
.crumbs a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.crumbs .sep { color: var(--muted); }
.crumbs .cur { padding: 2px 4px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* File list */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-head, .row { display: grid; grid-template-columns: 1fr 120px 110px 44px; align-items: center; gap: 12px; padding: 0 12px; }
.list-head { height: 36px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.row { min-height: 48px; border-bottom: 1px solid var(--border); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row .name span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.ficon { width: 26px; height: 26px; flex: none; }
.empty { padding: 56px 16px; text-align: center; color: var(--muted); }
.empty svg { width: 46px; height: 46px; opacity: 0.6; margin-bottom: 8px; }
.drop-hint { position: fixed; inset: 0; background: color-mix(in srgb, var(--accent) 14%, transparent); border: 3px dashed var(--accent); z-index: 50; display: grid; place-items: center; font-size: 18px; font-weight: 600; color: var(--accent); pointer-events: none; }

/* Menus, dialogs, toasts */
.menu { position: fixed; z-index: 60; min-width: 180px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.menu button { display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.wide { width: min(980px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 14, 22, 0.45); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-body { padding: 18px 20px; overflow: auto; max-height: calc(100vh - 170px); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.section + .section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > input, .inline > select { flex: 1; }
.inline > select.role { flex: 0 0 120px; }
.people { margin-top: 10px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.person:last-child { border-bottom: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.person .who { flex: 1; min-width: 0; }
.person .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbox { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.linkbox .url { display: flex; gap: 8px; align-items: center; }
.linkbox .url input { font-family: ui-monospace, monospace; font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview { display: grid; place-items: center; min-height: 300px; background: var(--surface-2); border-radius: 10px; overflow: hidden; }
.preview img, .preview video { max-width: 100%; max-height: 70vh; display: block; }
.preview iframe { width: 100%; height: 72vh; border: 0; background: #fff; }
.preview pre { margin: 0; padding: 16px; width: 100%; max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12.5px/1.5 ui-monospace, monospace; align-self: start; }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px; }
.toast.error { background: var(--danger); color: #fff; }
.uploads { position: fixed; right: 16px; bottom: 16px; width: 320px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 40; overflow: hidden; }
.uploads .uh { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-weight: 600; border-bottom: 1px solid var(--border); }
.uploads .ui { padding: 8px 12px; font-size: 13px; }
.uploads .ui .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; max-width: 760px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple td, table.simple th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.simple th { color: var(--muted); font-weight: 500; font-size: 12px; }
.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font: 12px/1.5 ui-monospace, monospace; white-space: pre-wrap; word-break: break-all; }
.feed .item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.feed .item:last-child { border-bottom: 0; }
.feed .when { color: var(--muted); font-size: 12.5px; width: 130px; flex: none; }
.public-wrap { max-width: 960px; margin: 0 auto; padding: 20px 16px 60px; }
.public-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.dropzone { border: 2px dashed var(--border); border-radius: 14px; padding: 40px 16px; text-align: center; background: var(--surface); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; width: 260px; transform: translateX(-100%); transition: transform 0.18s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar { padding: 10px 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px 16px 60px; }
  .list-head, .row { grid-template-columns: 1fr 44px; }
  .list-head .c-size, .list-head .c-mod, .row .c-size, .row .c-mod { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .feed .when { width: 90px; }
  .hide-sm { display: none; }
}

.pill.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; margin: 16px 0 12px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
table.simple.mod td:first-child { min-width: 180px; }
table.simple td.actions > * { margin: 0 0 6px 6px; }
table.simple td.actions { text-align: right; min-width: 220px; }
.ficon-sm svg { width: 20px; height: 20px; color: var(--muted); }
textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font: inherit; color: inherit; resize: vertical; }
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.prose h2 { margin-top: 18px; }
.prose ol { padding-left: 20px; margin: 0; }
.prose li { margin: 4px 0; }
table.simple.mod td { overflow-wrap: anywhere; }
table.simple.mod td.actions { min-width: 140px; }
table.simple.mod td.actions > .btn { display: flex; width: max-content; margin: 0 0 6px auto; }
.nav .badge { margin-left: auto; background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.banner:hover { text-decoration: none; filter: brightness(1.03); }
.pill.warn { background: color-mix(in srgb, #e8a33a 18%, transparent); color: #b7791f; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg .icon-btn { border-radius: 0; padding: 7px 9px; }
.seg .icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.card-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; cursor: pointer; min-width: 0; }
.card-item:hover { background: var(--surface-2); }
.card-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.gpreview { aspect-ratio: 4 / 3; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; margin-bottom: 8px; }
.gthumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.gicon .ficon { width: 52px; height: 52px; }
.gname { display: flex; align-items: center; gap: 4px; font-weight: 500; }
.gname .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb-sm { width: 26px; height: 26px; object-fit: cover; border-radius: 4px; flex: none; }
.snippet { flex-basis: 100%; font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: normal; }
.snippet mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--text); border-radius: 3px; padding: 0 2px; }
.row .name:has(.snippet) { flex-wrap: wrap; row-gap: 0; padding: 6px 0; }
@media (max-width: 760px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.topbar .search { position: relative; }
.kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 11px/1 ui-monospace, monospace; color: var(--muted); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 3px 6px; background: var(--surface-2); pointer-events: none; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; max-height: min(70vh, 480px); overflow: auto; }
.sopt { display: flex; gap: 10px; align-items: flex-start; padding: 7px 9px; border-radius: 7px; cursor: pointer; }
.sopt[aria-selected="true"] { background: var(--accent-soft); }
.sopt .ficon { width: 22px; height: 22px; }
.stext { min-width: 0; flex: 1; }
.sname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.sopt .snippet { margin: 2px 0 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sall { color: var(--accent); font-size: 13px; border-top: 1px solid var(--border); border-radius: 0 0 7px 7px; margin-top: 3px; }

/* setup + posture */
.health { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.health li { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; display: grid; gap: 4px; }
.health .pill { margin-right: 8px; }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, #d98a00 18%, transparent); color: #b36b00; }
@media (prefers-color-scheme: dark) { .pill.warn { color: #f0b34a; } }
.profiles { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin: 0 0 12px; display: grid; gap: 8px; }
.profile, .check { display: flex; gap: 10px; align-items: flex-start; }
.check { align-items: center; margin-bottom: 12px; }
.profile input, .check input { width: auto; margin-top: 3px; }
.check input { margin-top: 0; }
.pill.error { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
