/* ---------- tokens ---------- */
:root {
  --ground: #f9fafb; --surface: #ffffff; --raised: #f3f4f6; --active: #eeeeee;
  --border: #e8e8e8; --rule: #f2f2f2; --control: #d1d5db;
  --text: #111111; --muted: #5f6368; --faint: #6b6b6b;
  --primary: #1d1f20; --primary-hover: #3a3d40; --primary-ink: #ffffff;
  --accent: #0b7a75; --accent-ring: rgba(11, 122, 117, .28);
  --positive: #247b50; --negative: #c4242a;
  --neg-bg: #ffedea; --neg-ink: #831c1e; --neg-border: #f6c9c4;
  --ok-bg: #dcfae5; --ok-ink: #04250e; --ok-border: #a6e6bd;
  --warn-bg: #fffbeb; --warn-ink: #92400e; --warn-border: #fde68a;
  --drive: #1d1f20; --drive-top: #3a3d40; --drive-plate: #f3f4f6; --drive-led: #14b8a6;
  --radius-card: 8px; --radius-control: 6px;
  --control-h: 36px; --field-h: 40px;
  --font: "Segoe UI Variable Text", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0b0b0c; --surface: #141415; --raised: #1c1c1e; --active: #232325;
    --border: #2a2a2c; --rule: #1f1f21; --control: #4a4a4d;
    --text: #f2f2f2; --muted: #b4b4b4; --faint: #949494;
    --primary: #f2f2f2; --primary-hover: #d4d4d4; --primary-ink: #111111;
    --accent: #4fd1c5; --accent-ring: rgba(79, 209, 197, .35);
    --positive: #3fc07a; --negative: #ef6b7f;
    --neg-bg: #2c1a20; --neg-ink: #ff9aa5; --neg-border: #4b2630;
    --ok-bg: #172a1d; --ok-ink: #7fe0a5; --ok-border: #24432e;
    --warn-bg: #2a2210; --warn-ink: #f2c66b; --warn-border: #5c4a14;
    --drive: #2a2a2c; --drive-top: #3a3a3d; --drive-plate: #141415; --drive-led: #4fd1c5;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/20px var(--font); background: var(--ground); color: var(--text); }
h1, h2, p { margin: 0; }
h1 { font-size: 24px; line-height: 32px; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 16px; line-height: 24px; font-weight: 600; }
a { color: inherit; }
.muted { color: var(--muted); font-size: 13px; }
.sr-only, input.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; margin: -1px !important; padding: 0 !important; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0 !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-weight: 500; min-height: var(--control-h); padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--control); background: var(--surface); color: var(--text);
  border-radius: var(--radius-control); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .12s, border-color .12s, transform .08s;
}
button:hover, .btn:hover { background: var(--raised); }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
button.primary:hover, .btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.danger { background: var(--negative); border-color: var(--negative); color: #fff; }
button.danger:hover { filter: brightness(.92); }
button.link, .btn.link { border-color: transparent; background: none; min-height: 28px; padding: 0 8px; color: var(--muted); }
button.link:hover, .btn.link:hover { background: var(--raised); color: var(--text); }
button.link.danger-text { color: var(--negative); }
button:disabled, button[aria-disabled="true"] { background: var(--raised); border-color: var(--border); color: var(--muted); cursor: not-allowed; transform: none; }
button.primary:disabled { background: var(--raised); color: var(--muted); }
button[aria-busy="true"]::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- form ---------- */
.field + .field { margin-top: 16px; }
.field label { display: block; font-weight: 500; margin-bottom: 8px; }
input[type="text"], input[type="password"], input:not([type]) {
  font: inherit; width: 100%; height: var(--field-h); padding: 0 12px;
  border: 1px solid var(--control); border-radius: var(--radius-control);
  background: var(--surface); color: var(--text);
  transition: border-color .12s, outline-color .12s;
}
input::placeholder { color: var(--faint); }
input:hover { border-color: var(--faint); }
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[aria-invalid="true"] { border-color: var(--negative); }
input[aria-invalid="true"]:focus-visible { outline-color: var(--negative); border-color: var(--negative); }
input:disabled { background: var(--raised); color: var(--muted); cursor: not-allowed; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
.error { color: var(--negative); font-size: 13px; margin-top: 8px; font-weight: 500; }
.check { display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; cursor: pointer; color: var(--muted); }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.form-actions { margin-top: 24px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.form-actions button.primary { min-width: 132px; }

/* ---------- notices (inline, inside the block they belong to) ---------- */
.notice { padding: 10px 12px; border-radius: var(--radius-control); border: 1px solid var(--border); background: var(--raised); color: var(--text); font-size: 13px; line-height: 20px; }
.notice + .notice, .notice + form, form + .notice { margin-top: 16px; }
.notice.error { color: var(--neg-ink); background: var(--neg-bg); border-color: var(--neg-border); font-weight: 400; margin-top: 0; }
.notice.success { color: var(--ok-ink); background: var(--ok-bg); border-color: var(--ok-border); }
.notice.warn { color: var(--warn-ink); background: var(--warn-bg); border-color: var(--warn-border); }
.err { color: var(--neg-ink); background: var(--neg-bg); border: 1px solid var(--neg-border); border-radius: var(--radius-control); padding: 10px 12px; font-size: 13px; margin-bottom: 16px; }

/* password rules: neutral until met, then a filled marker (text label for screen readers) */
.rules { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.rules li { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: 13px; }
.rules li::before { content: ""; flex: none; width: 14px; height: 14px; margin-top: 3px; border-radius: 50%; border: 1.5px solid var(--control); }
.rules li[data-met="true"] { color: var(--text); }
.rules li[data-met="true"]::before { border-color: var(--positive); background: var(--positive) center / 10px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 5.2 4.2 7.4 8 3' fill='none' stroke='white' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }

/* ---------- app bar ---------- */
.bar { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; text-decoration: none; border-radius: var(--radius-control); }
.brand img { width: 24px; height: 24px; display: block; }
.spacer { flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot.on { background: var(--accent); }
.dot.off { background: var(--negative); }
.banner { padding: 10px 24px; font-size: 13px; font-weight: 500; border-bottom: 1px solid var(--border); }
.banner.offline { background: var(--neg-bg); color: var(--neg-ink); border-color: var(--neg-border); }
.banner.nodrive { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-border); }

/* ---------- file view ---------- */
main { max-width: 1000px; margin: 0 auto; padding: 24px 24px 120px; }
.crumbs { margin-bottom: 12px; word-break: break-all; color: var(--muted); }
.crumbs button.link { font-size: 14px; color: var(--text); padding: 0 4px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.drop { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); min-height: 160px; }
.drop.over { outline: 2px dashed var(--accent); outline-offset: -2px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--rule); }
tr:last-child td { border-bottom: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.name button { font-size: 14px; text-align: left; word-break: break-all; color: var(--text); font-weight: 500; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn.link, td.actions button.link { font-weight: 400; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty.big { font-size: 16px; color: var(--text); }
.uploads { position: fixed; right: 16px; bottom: 16px; width: 340px; max-height: 50vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 4px 16px; box-shadow: 0 6px 24px rgba(0, 0, 0, .12); }
.up { padding: 10px 0; border-bottom: 1px solid var(--rule); font-size: 13px; }
.up:last-child { border-bottom: 0; }
.up progress { width: 100%; height: 6px; accent-color: var(--accent); }
.up .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.up .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }

/* ---------- dialogs (they float, so they may carry a shadow) ---------- */
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 24px; max-width: min(92vw, 480px); width: 100%; box-shadow: 0 12px 40px rgba(0, 0, 0, .2); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin-bottom: 8px; word-break: break-all; }
dialog p { margin-bottom: 16px; word-break: break-all; color: var(--muted); }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
dialog.preview { max-width: min(96vw, 1100px); }
dialog.preview img, dialog.preview video { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; }
dialog.preview audio { width: 100%; }
dialog.preview iframe { width: 100%; height: 75vh; border: 0; }
dialog.preview pre { max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; font: 13px/1.5 ui-monospace, Consolas, monospace; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }
.auth-main { display: flex; flex-direction: column; padding: 28px 48px 28px; min-height: 100vh; }
.auth-form { width: 100%; max-width: 360px; margin: auto 0; padding: 48px 0; }
.auth-form h1 { margin-bottom: 8px; }
.auth-form > p { color: var(--muted); margin-bottom: 28px; }
.auth-form .form-actions { margin-top: 24px; }
.auth-form .form-actions button { width: 100%; min-height: 40px; }
.auth-foot { color: var(--muted); font-size: 13px; }
.auth-side { background: var(--raised); display: flex; flex-direction: column; justify-content: center; gap: 40px; padding: 48px; }
.auth-side svg { width: 100%; max-width: 660px; height: auto; display: block; }
.facts { display: grid; gap: 20px; max-width: 660px; }
.facts h2 { margin-bottom: 2px; }
.facts p { color: var(--muted); }

/* ---------- settings (password) ---------- */
.settings { max-width: 1000px; margin: 0 auto; padding: 32px 24px 96px; }
.settings > header { margin-bottom: 8px; }
.settings > header p { color: var(--muted); margin-top: 4px; }
.setting { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 48px; padding-top: 32px; margin-top: 32px; border-top: 1px solid var(--border); }
.setting-info p { color: var(--muted); margin-top: 4px; }
.summary { margin: 20px 0 0; display: grid; gap: 12px; }
.summary dt { color: var(--muted); font-size: 13px; }
.summary dd { margin: 2px 0 0; font-weight: 500; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 24px; max-width: 560px; }
.panel .notice { margin-bottom: 20px; }
.panel .notice:empty { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-main { min-height: 100vh; padding: 20px; }
  .setting { grid-template-columns: 1fr; gap: 24px; }
}
@media (max-width: 640px) {
  :root { --control-h: 44px; --field-h: 44px; }
  input[type="text"], input[type="password"] { font-size: 16px; }
  .bar { padding: 8px 16px; }
  .banner { padding: 10px 16px; }
  main { padding: 16px 16px 120px; }
  .settings { padding: 24px 16px 72px; }
  .panel { padding: 16px; }
  .form-actions button.primary { width: 100%; }
  th:nth-child(3), td:nth-child(3) { display: none; }
  th, td { padding: 10px 12px; }
  .uploads { left: 12px; right: 12px; width: auto; }
  button.link, .btn.link { min-height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  button[aria-busy="true"]::before { animation-duration: 2s; }
}
