:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #f1f4f7;
  --ink: #16202a;
  --muted: #6b7682;
  --line: #e3e7ec;
  --line-soft: #eef1f4;
  --accent: #2f6f73;
  --accent-dark: #225557;
  --accent-soft: #e7f1f0;
  --danger: #b84242;
  --danger-soft: #fae8e8;
  --shadow-sm: 0 1px 2px rgba(15, 23, 30, 0.04), 0 2px 6px rgba(15, 23, 30, 0.05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 30, 0.10);
  --radius: 10px;
  --radius-sm: 6px;
  --pill: 999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1416;
    --panel: #181f22;
    --panel-soft: #20272a;
    --ink: #e8edee;
    --muted: #8b969c;
    --line: #262e32;
    --line-soft: #20272a;
    --accent: #5fb6b9;
    --accent-dark: #87ccce;
    --accent-soft: #1d3033;
    --danger: #d97373;
    --danger-soft: #3a1f1f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px clamp(12px, 3vw, 32px) calc(env(safe-area-inset-bottom) + 100px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand strong { font-weight: 700; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-sm);
}

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

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Icon button */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease,
    opacity 160ms ease, transform 120ms ease;
}

.icon-btn:hover:not(:disabled),
.icon-btn:focus-visible:not(:disabled) {
  background: var(--panel-soft);
  border-color: var(--line);
}

.icon-btn:active:not(:disabled) { transform: scale(0.95); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn svg { width: 18px; height: 18px; }

/* Path bar */
.path-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-sm);
  min-height: 50px;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding: 0 4px;
  white-space: nowrap;
  mask-image: linear-gradient(to right, transparent 0, black 12px, black calc(100% - 12px), transparent 100%);
}

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

.crumb {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 160ms ease, color 160ms ease;
}

.crumb:hover, .crumb:focus-visible {
  background: var(--panel-soft);
  color: var(--ink);
}

.crumb.current {
  color: var(--ink);
  font-weight: 600;
  cursor: default;
}

.crumb.root svg { width: 16px; height: 16px; }
.crumb.root .root-label { font-weight: 600; }

.crumb-sep {
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  flex: 0 0 auto;
  opacity: 0.55;
}

.crumb-sep svg { width: 14px; height: 14px; }

/* Table */
.table-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-head, .file-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 110px 140px 56px;
  align-items: center;
  gap: 12px;
}

.table-head {
  min-height: 44px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.file-list { min-height: 200px; }

.file-row {
  min-height: 58px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-soft);
  transition: background 120ms ease;
}

.file-row:last-child { border-bottom: 0; }
.file-row:hover { background: var(--panel-soft); }

.check-cell {
  display: grid;
  place-items: center;
  height: 100%;
}

.check-cell input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.name-cell {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.file-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
  color: var(--muted);
}

.file-icon.folder {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

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

.name-button {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 8px 0;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
}

.name-button:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.folder-name {
  color: var(--accent-dark);
  font-weight: 600;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
}

.row-action {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  transition: background 160ms ease, color 160ms ease, transform 120ms ease;
}

.row-action:hover, .row-action:focus-visible {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.row-action:active { transform: scale(0.94); }
.row-action svg { width: 16px; height: 16px; }

.empty-state {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 220px;
  color: var(--muted);
  text-align: center;
  padding: 40px 16px;
}

.empty-state strong {
  color: var(--ink);
  font-size: 15px;
}

/* Floating download bar */
.download-bar {
  position: fixed;
  left: 50%;
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--pill);
  box-shadow: var(--shadow-lg);
  z-index: 30;
  max-width: calc(100vw - 24px);
  animation: slideUp 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 18px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.selection-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

/* Buttons */
.primary-btn, .ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--pill);
  font-weight: 600;
  font-size: 14px;
  transition: background 160ms ease, color 160ms ease, transform 120ms ease;
}

.primary-btn {
  background: var(--accent);
  color: white;
}

.primary-btn:hover, .primary-btn:focus-visible {
  background: var(--accent-dark);
}

.primary-btn:active { transform: scale(0.97); }
.primary-btn svg { width: 16px; height: 16px; }

.ghost-btn {
  background: transparent;
  color: var(--muted);
  padding: 0 14px;
}

.ghost-btn:hover, .ghost-btn:focus-visible {
  background: var(--panel-soft);
  color: var(--ink);
}

/* Toast */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(80px, calc(env(safe-area-inset-bottom) + 72px));
  margin: 0 auto;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  font-size: 14px;
  animation: fadeIn 200ms ease;
}

.toast.error { background: var(--danger); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Login */
.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  min-height: 100vh;
}

.login-shell { width: min(400px, 100%); }

.login-panel {
  display: grid;
  gap: 16px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  text-align: left;
}

.login-panel .brand-mark {
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
}

.login-panel .brand-mark svg { width: 24px; height: 24px; }

.login-panel h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.login-copy {
  margin: 0 0 4px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.login-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  background: var(--panel);
  color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.login-form input:focus-visible {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.full {
  width: 100%;
  justify-content: center;
}

.notice {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}

.notice.error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Mobile */
@media (max-width: 720px) {
  .app {
    padding: 14px 12px calc(env(safe-area-inset-bottom) + 96px);
    gap: 12px;
  }

  .topbar { gap: 8px; }
  .brand strong { font-size: 15px; }
  .brand-mark { width: 36px; height: 36px; }

  .table-head { display: none; }

  .file-row {
    grid-template-columns: 36px minmax(0, 1fr) 44px;
    grid-template-areas:
      "check name actions"
      "check meta actions";
    column-gap: 10px;
    row-gap: 0;
    min-height: 64px;
    padding: 8px 12px;
  }

  .file-row .check-cell { grid-area: check; }
  .file-row .name-cell { grid-area: name; }
  .file-row .row-actions { grid-area: actions; align-self: center; }

  .file-row .meta.size-cell {
    grid-area: meta;
    padding-left: 48px;
    font-size: 12px;
  }

  .modified-cell { display: none; }

  .name-cell { gap: 12px; }
  .file-icon { width: 36px; height: 36px; }

  .crumb { max-width: 130px; padding: 8px 10px; }
  .crumb.root .root-label { display: none; }
  .crumb.root { padding: 8px; }

  .download-bar {
    left: 12px;
    right: 12px;
    transform: none;
    max-width: none;
    border-radius: var(--radius);
    padding: 10px 12px 10px 18px;
    bottom: max(12px, env(safe-area-inset-bottom));
    animation: slideUpMobile 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .selection-count { flex: 1; }

  @keyframes slideUpMobile {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .toast {
    bottom: max(88px, calc(env(safe-area-inset-bottom) + 80px));
  }
}
