/* Shared base styles */
:root {
  color-scheme: light;
  --background: #f7f8f8;
  --foreground: #202625;
  --card: #ffffff;
  --card-soft: #f1f3f2;
  --muted: #edf0ef;
  --muted-foreground: #66716e;
  --subtle: #89928f;
  --border: #dfe4e2;
  --border-strong: #c8cfcc;
  --primary: #42675c;
  --primary-strong: #35564c;
  --primary-soft: #e9efec;
  --success: #42675c;
  --danger: #a34b4b;
  --ring: 0 0 0 2px rgba(66, 103, 92, 0.22);
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --radius: 4px;
  --radius-lg: 6px;
  --radius-xl: 6px;
  --font-sans: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui,
    -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1, h2, h3, p, dl, dd, ul {
  margin: 0;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: var(--primary);
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Shared components */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--card);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  color: var(--muted-foreground);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--card);
  color: var(--foreground);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
}

.btn-outline:hover:not(:disabled),
.btn-ghost:hover:not(:disabled) {
  background: var(--muted);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted-foreground);
}

.btn-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.btn-danger-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
  background: #f8eeee;
}

.btn-sm {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--card);
  color: var(--foreground);
  font-size: 13px;
}

.input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: var(--ring);
}

.input::placeholder {
  color: var(--subtle);
}

input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span {
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 600;
}

.field-sm {
  max-width: 108px;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.form-hint {
  color: var(--subtle);
  font-size: 11.5px;
}

.textarea {
  height: auto;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  resize: vertical;
}

.hidden-form {
  display: none;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

/* Access form */
.page-auth {
  background: var(--background);
}

.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.auth-card {
  width: min(100%, 400px);
  padding: 28px 25px 34px;
  border: 0;
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 4px 14px rgba(25, 35, 32, 0.12);
}

.auth-title {
  margin-bottom: 8px;
  font-size: 21px;
  letter-spacing: -0.01em;
}

.card-sub {
  margin-bottom: 26px;
  color: #58645f;
  font-size: 14px;
  line-height: 1.7;
}

.input-wrap {
  display: block;
  height: 38px;
  overflow: hidden;
  border: 1px solid #e2e5e3;
  border-radius: 2px;
  background: #fff;
}

.input-wrap:focus-within {
  border-color: #c8d1cd;
}

.input-wrap.is-invalid {
  border-color: var(--danger);
}

.input-wrap .input {
  width: 100%;
  height: 100%;
  padding: 0 10px;
  border: 0;
  border-radius: 0;
  font-size: 14px;
}

.field-error {
  min-height: 21px;
  margin: 6px 2px 4px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
}

.auth-card .btn-block {
  min-height: 38px;
  margin-top: 14px;
  border-color: #16b7a5;
  border-radius: 2px;
  background: #16b7a5;
  font-size: 13px;
}

.auth-card .btn-block:hover:not(:disabled) {
  border-color: #119f90;
  background: #119f90;
}

.hint {
  margin-top: 12px;
  color: var(--subtle);
  font-size: 11.5px;
  text-align: center;
}

.hint a {
  color: var(--muted-foreground);
  text-decoration: none;
}

.hint a:hover {
  color: var(--primary);
}

/* Download page */
.shell {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}

.topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
  padding: 11px 13px;
  border-left: 2px solid var(--primary);
  background: var(--primary-soft);
  color: var(--foreground);
  font-size: 12.5px;
  line-height: 1.6;
}

.notice svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  margin-top: 1px;
  color: var(--primary);
}

.notice-body {
  min-width: 0;
}

.notice-body p,
.notice-body div {
  margin: 0 0 6px;
}

.notice-body p:last-child,
.notice-body div:last-child {
  margin-bottom: 0;
}

.notice-body ul,
.notice-body ol {
  margin: 6px 0;
  padding-left: 20px;
}

.notice-body a {
  color: var(--primary);
  text-decoration: underline;
}

.notice-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.notice-body pre {
  margin: 6px 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.04);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
}

.notice-body blockquote {
  margin: 6px 0;
  padding-left: 10px;
  border-left: 3px solid var(--border-strong);
  color: var(--muted-foreground);
}

.explorer {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
}

.exp-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
}

.exp-crumb {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--muted-foreground);
  font-size: 12.5px;
  font-weight: 600;
}

.exp-crumb svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: var(--primary);
}

.crumb-sep {
  color: var(--border-strong);
}

.crumb-current {
  overflow: hidden;
  color: var(--foreground);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exp-total {
  flex: 0 0 auto;
  color: var(--muted-foreground);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.exp-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  color: var(--muted-foreground);
}

.search:focus-within {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.search svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 13px;
}

.exp-tip {
  flex: 0 0 auto;
  color: var(--subtle);
  font-size: 11.5px;
  white-space: nowrap;
}

.exp-body {
  min-height: 120px;
  padding: 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 46px;
  padding: 7px 9px 7px calc(8px + var(--depth, 0) * 18px);
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
}

.row:hover {
  background: var(--card-soft);
}

.row:active {
  background: var(--primary-soft);
}

.row:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--primary);
}

.chev {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  color: var(--subtle);
  transition: transform 0.16s ease;
}

.folder-row[aria-expanded="true"] .chev {
  transform: rotate(90deg);
  color: var(--primary);
}

.row-ico {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  color: var(--muted-foreground);
}

.row-ico svg {
  width: 16px;
  height: 16px;
}

.ico-folder {
  color: var(--primary);
}

.row-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-row .row-label {
  font-weight: 650;
}

.row-meta {
  flex: 0 0 auto;
  color: var(--subtle);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.row-count {
  flex: 0 0 auto;
  color: var(--subtle);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.file-row .row-action {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--primary);
}

.file-row .row-action svg {
  width: 14px;
  height: 14px;
}

.file-row:hover .row-action {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.empty-row {
  padding: 9px 10px 9px calc(8px + var(--depth, 0) * 18px);
  color: var(--subtle);
  font-size: 12px;
}

.tree-group {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.16s ease;
}

.tree-group.is-open {
  grid-template-rows: 1fr;
}

.tree-group-inner {
  overflow: hidden;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 34px 20px;
  color: var(--muted-foreground);
  text-align: center;
}

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

.empty-state span {
  font-size: 12px;
}

.exp-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted-foreground);
  font-size: 11.5px;
}

.status-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.status-right {
  font-variant-numeric: tabular-nums;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 2px 0;
  color: var(--subtle);
  font-size: 11.5px;
}

.footer-links {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 14px;
}

.footer a {
  color: var(--muted-foreground);
  text-decoration: none;
}

.footer a:hover {
  color: var(--primary);
}

/* Responsive */
@media (max-width: 760px) {
  .auth-card {
    width: min(100%, 400px);
  }
}

@media (max-width: 560px) {
  .shell {
    padding-inline: 12px;
  }

  .auth {
    padding-inline: 16px;
  }

  .auth-card {
    padding: 22px 18px;
  }

  .topbar .badge {
    display: none;
  }

  .exp-titlebar,
  .exp-toolbar {
    padding-inline: 12px;
  }

  .row {
    min-height: 50px;
    padding-left: calc(6px + var(--depth, 0) * 14px);
    gap: 7px;
  }

  .empty-row {
    padding-left: calc(6px + var(--depth, 0) * 14px);
  }

  .row-meta {
    display: none;
  }

  .exp-tip {
    display: none;
  }

  .exp-body {
    padding: 6px;
  }

  .field-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .field-sm {
    max-width: none;
  }

  .footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (hover: none) {
  .row:hover {
    background: transparent;
  }
}

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