:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-soft: #fbfbfa;
  --text: #171717;
  --muted: #737373;
  --line: #e7e7e4;
  --line-strong: #d7d7d2;
  --accent: #3157d5;
  --accent-soft: #eef2ff;
  --danger: #c83d3d;
  --danger-soft: #fff1f1;
  --shadow: 0 18px 50px rgba(20, 20, 20, 0.06);
  --radius: 16px;
  --control: 11px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.35; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
:focus-visible { outline: 3px solid rgba(49, 87, 213, .24); outline-offset: 2px; }

.app-shell { min-height: 100vh; }
.page { width: min(1120px, 100%); margin: 0 auto; padding: 18px 16px 42px; }
.login-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
.login-panel { width: min(100%, 360px); }
.brand { margin: 0 0 28px; font-size: 24px; font-weight: 650; letter-spacing: 0; }
.form-stack { display: grid; gap: 14px; }
.field { display: grid; gap: 7px; }
.field span { color: var(--muted); font-size: 13px; }
.input, .select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--control);
  background: var(--surface);
  color: var(--text);
  padding: 0 13px;
}
.input:focus, .select:focus { border-color: rgba(49, 87, 213, .58); }

.btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--control);
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}
.btn:hover { border-color: var(--line-strong); background: var(--surface-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #294bc2; }
.btn.danger { color: var(--danger); border-color: rgba(200, 61, 61, .28); background: var(--danger-soft); }
.btn.ghost { background: transparent; }
.btn.icon { width: 42px; padding: 0; flex: 0 0 42px; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; }
.link-action {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 28px;
  padding: 0;
  justify-self: center;
  font-size: 12px;
}
.link-action:hover { color: var(--text); }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.topbar-title { font-size: 18px; font-weight: 650; }
.topbar-actions { display: flex; align-items: center; gap: 9px; min-width: 0; }
.username { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }

.upload-zone {
  min-height: 210px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  display: grid;
  place-items: center;
  padding: 24px;
  box-shadow: var(--shadow);
  transition: border-color 140ms ease, background 140ms ease;
}
.upload-zone.dragging { border-color: rgba(49, 87, 213, .62); background: #f8faff; }
.upload-inner { display: grid; justify-items: center; gap: 12px; text-align: center; }
.upload-title { font-size: 19px; font-weight: 620; }
.upload-icon, .file-icon { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.progress-wrap { width: min(520px, 100%); display: grid; gap: 9px; color: var(--muted); font-size: 13px; }
.progress-meta { display: flex; justify-content: space-between; gap: 10px; }
.progress-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-track { height: 7px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 140ms ease; }

.section-head { margin: 34px 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-head h1, .section-head h2 { margin: 0; font-size: 20px; font-weight: 650; }
.file-list, .admin-list, .activity-list { display: grid; gap: 8px; }
.empty { color: var(--muted); padding: 28px 0; }
.row {
  min-height: 58px;
  display: grid;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 10px 12px;
}
.file-row { grid-template-columns: auto minmax(0, 1fr) auto auto; }
.file-main { min-width: 0; display: grid; gap: 3px; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 560; }
.file-size, .row-sub { color: var(--muted); font-size: 13px; }
.badge {
  min-width: 42px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #2647ad;
  font-size: 12px;
  font-weight: 650;
}

.admin-layout { display: grid; grid-template-columns: 1fr; gap: 18px; }
.tabs { display: flex; gap: 7px; }
.tab { min-height: 38px; padding: 0 13px; border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--muted); }
.tab.active { color: var(--text); background: var(--surface); border-color: var(--line); }
.admin-user-row { grid-template-columns: minmax(0, 1.35fr) minmax(90px, .8fr) minmax(70px, .55fr) minmax(90px, .75fr) auto auto; cursor: pointer; }
.admin-user-row:hover { border-color: var(--line-strong); }
.user-delete { color: var(--muted); background: transparent; border-color: transparent; }
.user-delete:hover { color: var(--danger); border-color: rgba(200, 61, 61, .24); background: var(--danger-soft); }
.status { display: inline-flex; align-items: center; justify-content: center; min-height: 28px; padding: 0 9px; border-radius: 999px; font-size: 12px; background: #f0f7ef; color: #32713b; }
.status.off { background: var(--danger-soft); color: var(--danger); }
.activity-row { grid-template-columns: minmax(120px, .75fr) minmax(100px, .8fr) minmax(90px, .7fr) minmax(0, 1fr); }

.drawer-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23, 23, 23, .18);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
  animation: fade-in 140ms ease;
}
.drawer {
  width: min(520px, 100%);
  height: 100%;
  background: var(--surface);
  padding: 18px;
  overflow: auto;
  box-shadow: var(--shadow);
  animation: slide-in 150ms ease;
}
.drawer-head, .modal-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.drawer-title, .modal-title { font-size: 18px; font-weight: 650; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.detail-item { border: 1px solid var(--line); border-radius: 13px; padding: 11px; }
.detail-label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.detail-value { font-weight: 600; overflow-wrap: anywhere; }

.modal-backdrop { align-items: center; justify-content: center; padding: 18px; }
.modal {
  width: min(430px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: auto;
  background: var(--surface);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: modal-in 150ms ease;
}
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.copy-feedback { color: var(--muted); font-size: 12px; min-height: 16px; margin-right: auto; }
.code-box { border: 1px solid var(--line); border-radius: 14px; padding: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; background: var(--surface-soft); }
.switch-row { display: flex; align-items: center; gap: 10px; min-height: 46px; }
.switch-row input { width: 20px; height: 20px; }

.toast-region { position: fixed; left: 16px; right: 16px; bottom: 16px; display: grid; justify-items: center; gap: 8px; z-index: 40; pointer-events: none; }
.toast { max-width: min(520px, 100%); background: #171717; color: white; border-radius: 999px; padding: 10px 14px; box-shadow: var(--shadow); animation: toast-in 160ms ease; }
.app-footer { margin-top: 44px; text-align: center; color: var(--muted); font-size: 12px; font-weight: 400; }
.login-page .app-footer { margin-top: 36px; }

@media (min-width: 760px) {
  .page { padding: 24px 28px 56px; }
  .topbar { height: 74px; }
  .upload-zone { min-height: 260px; }
  .admin-layout { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .file-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .file-row .delete-direct { display: none; }
  .admin-user-row { grid-template-columns: minmax(0, 1fr) auto auto; }
  .admin-user-row .hide-mobile, .activity-row .hide-mobile { display: none; }
  .activity-row { grid-template-columns: minmax(0, 1fr) auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .drawer { width: 100%; }
  .section-head { margin-top: 26px; }
}

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

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(16px); opacity: .7; } to { transform: translateX(0); opacity: 1; } }
@keyframes modal-in { from { transform: translateY(8px); opacity: .7; } to { transform: translateY(0); opacity: 1; } }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
