:root {
  color-scheme: light dark;
  --bg: #f4f7fa;
  --surface: #ffffff;
  --surface-soft: #edf2f7;
  --text: #17212b;
  --muted: #526170;
  --line: #cdd7e1;
  --line-strong: #8da0b2;
  --primary: #175cd3;
  --primary-strong: #124aab;
  --on-primary: #ffffff;
  --success: #08725f;
  --success-soft: #e5f6f1;
  --warning: #8a4b08;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --focus: #f5a524;
  --radius: 6px;
  --control: 44px;
  --header: 64px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111820;
    --surface: #18222c;
    --surface-soft: #202d38;
    --text: #f2f6f9;
    --muted: #b8c5d0;
    --line: #354554;
    --line-strong: #7890a3;
    --primary: #75a7ff;
    --primary-strong: #9bbfff;
    --on-primary: #0a2448;
    --success: #72d8c1;
    --success-soft: #153b34;
    --warning: #ffc376;
    --danger: #ffb4ab;
    --danger-soft: #461a17;
    --focus: #ffd166;
  }
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { min-height: 100dvh; margin: 0; color: var(--text); background: var(--bg); line-height: 1.5; }
button, input, select { font: inherit; letter-spacing: 0; }
button, a, input, select { touch-action: manipulation; }
a { color: inherit; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: var(--on-primary);
  background: var(--primary);
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

:where(a, button, input, select):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control);
  padding: 8px 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out;
}
.button:hover, .icon-button:hover { background: var(--surface-soft); border-color: var(--primary); }
.button:active, .icon-button:active { background: var(--line); }
.button:disabled, .icon-button:disabled { opacity: .5; cursor: not-allowed; }
.button--primary { color: var(--on-primary); background: var(--primary); border-color: var(--primary); }
.button--primary:hover { color: var(--on-primary); background: var(--primary-strong); }
.button--danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }
.button--quiet { border-color: transparent; background: transparent; }
.button--wide { width: 100%; }
.icon-button { min-width: var(--control); padding-inline: 12px; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  min-height: var(--header);
  padding: 8px max(20px, calc((100vw - 1280px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.app-brand { display: inline-flex; align-items: center; gap: 10px; margin-right: 32px; text-decoration: none; }
.app-brand > span, .brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--on-primary);
  background: var(--primary);
  border-radius: var(--radius);
  font-weight: 800;
}
.app-header nav { display: flex; align-self: stretch; gap: 4px; }
.app-header nav a { display: grid; place-items: center; min-width: 72px; padding: 0 16px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.app-header nav a:hover { color: var(--text); background: var(--surface-soft); }
.app-header nav a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }
.app-header > .button { margin-left: auto; }

.workspace-main { width: min(1280px, 100%); margin: 0 auto; padding: 32px 20px 64px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { margin: 0 0 4px; font-size: 1.75rem; line-height: 1.2; letter-spacing: 0; }
.page-heading p { max-width: 68ch; margin: 0; color: var(--muted); }

.file-tabs { display: flex; gap: 20px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.file-tabs button { min-height: var(--control); padding: 8px 2px; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid transparent; cursor: pointer; }
.file-tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

.file-toolbar { display: flex; align-items: end; gap: 12px; margin-bottom: 16px; }
.file-toolbar label { display: grid; gap: 5px; color: var(--muted); font-size: .8125rem; font-weight: 700; }
.file-toolbar input, .file-toolbar select, .action-dialog input, .login-form input {
  min-height: var(--control);
  padding: 8px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.search-field { flex: 1; min-width: 240px; }

.selection-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; margin-bottom: 12px; padding: 8px 12px; background: var(--surface-soft); border: 1px solid var(--line); }
.selection-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.selection-actions .button { min-height: 40px; }

.file-surface { min-height: 280px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.file-table-wrap { overflow-x: auto; }
.file-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.file-table th { color: var(--muted); background: var(--surface-soft); font-size: .8125rem; text-align: left; }
.file-table th, .file-table td { height: 56px; padding: 8px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.file-table tbody tr:last-child td { border-bottom: 0; }
.file-table tbody tr:hover { background: var(--surface-soft); }
.file-table tbody tr[data-selected="true"] { background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.file-table input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
.select-column { width: 48px; text-align: center !important; }
.file-name-cell { min-width: 260px; }
.file-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-name > span:first-child { display: grid; place-items: center; flex: none; width: 32px; height: 36px; color: var(--primary); background: var(--surface-soft); border-radius: 4px; font-size: .6875rem; font-weight: 800; }
.file-name a, .file-name strong { min-width: 0; overflow-wrap: anywhere; }
.file-name a { color: var(--text); font-weight: 650; text-decoration: none; }
.file-name a:hover { color: var(--primary); text-decoration: underline; }
.status-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .75rem; font-weight: 700; }
.status-badge--public { color: var(--success); background: var(--success-soft); border-color: var(--success); }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.row-actions .button { min-height: 38px; padding-inline: 10px; font-size: .8125rem; }
.file-empty { display: grid; place-items: center; align-content: center; min-height: 280px; gap: 4px; padding: 24px; color: var(--muted); text-align: center; }
.file-empty strong { color: var(--text); }
.file-loading { display: grid; gap: 1px; }
.file-loading span { display: block; height: 56px; background: linear-gradient(90deg, var(--surface-soft), var(--surface), var(--surface-soft)); background-size: 200% 100%; animation: loading 1.2s linear infinite; }
@keyframes loading { to { background-position: -200% 0; } }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-main { width: min(420px, 100%); }
.login-panel { padding: 32px; background: var(--surface); border-top: 4px solid var(--primary); border-radius: var(--radius); box-shadow: 0 4px 8px rgba(20, 36, 52, .12); }
.login-heading { margin: 24px 0; }
.login-heading h1 { margin: 0 0 4px; font-size: 1.75rem; letter-spacing: 0; }
.login-heading p { margin: 0; color: var(--muted); }
.login-form { display: grid; gap: 10px; }
.login-form > label, .action-dialog label { font-weight: 700; }
.password-field { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.field-error { min-height: 24px; margin: 0; color: var(--danger); font-size: .875rem; }

dialog { color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(8, 15, 23, .56); }
.action-dialog, .conflict-dialog { width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); }
.action-dialog form, .conflict-dialog form { display: grid; gap: 20px; padding: 24px; }
.action-dialog h2, .action-dialog p, .conflict-dialog h2, .conflict-dialog p { margin: 0; }
.action-dialog label { display: grid; gap: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.conflict-list { display: grid; gap: 12px; max-height: 50vh; overflow: auto; }
.conflict-item { display: grid; gap: 8px; padding: 12px; background: var(--surface-soft); border: 1px solid var(--line); }
.conflict-item strong { overflow-wrap: anywhere; }
.conflict-item select { min-height: var(--control); color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); }
.check-row { display: flex; align-items: center; gap: 10px; min-height: var(--control); }
.check-row input { width: 20px; height: 20px; }

.sr-only, .app-live { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .app-header { padding-inline: 12px; }
  .app-brand { margin-right: 8px; }
  .app-brand strong { display: none; }
  .app-header nav { flex: 1; }
  .app-header nav a { min-width: 64px; padding-inline: 10px; }
  .workspace-main { padding: 24px 12px 48px; }
  .page-heading { align-items: stretch; }
  .file-toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; min-width: 0; }
  .selection-bar { align-items: stretch; flex-direction: column; }
  .selection-actions .button { flex: 1 1 calc(50% - 8px); }
  .file-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .file-table, .file-table tbody, .file-table tr, .file-table td { display: block; width: 100%; }
  .file-table tr { position: relative; display: grid; grid-template-columns: 44px 1fr auto; gap: 2px 10px; padding: 12px; border-bottom: 1px solid var(--line); }
  .file-table td { height: auto; padding: 2px 0; border: 0; }
  .file-table td.select-column { position: absolute; top: 14px; left: 12px; width: 32px; }
  .file-table td.file-name-cell { grid-column: 2 / -1; min-width: 0; padding-right: 4px; }
  .file-table td[data-label] { grid-column: 2 / -1; display: grid; grid-template-columns: 76px 1fr; align-items: center; color: var(--muted); font-size: .8125rem; }
  .file-table td[data-label]::before { content: attr(data-label); font-weight: 700; }
  .file-table td.row-actions { grid-column: 2 / -1; justify-content: flex-start; margin-top: 6px; }
  .file-name > span:first-child { display: none; }
}

@media (max-width: 430px) {
  .app-header > .button { padding-inline: 9px; }
  .page-heading { flex-direction: column; }
  .page-heading > .button { width: 100%; }
  .login-panel { padding: 24px 20px; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
}

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