:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #182033;
  --muted: #6b7280;
  --line: #e6eaf2;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn-soft: #fff7ed;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.logo {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  font-size: 20px;
  box-shadow: 0 6px 16px -6px rgba(37, 99, 235, .65);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text b { font-size: 16px; letter-spacing: .3px; }
.brand-text small { color: var(--muted); font-size: 11.5px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.user-chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 600;
}
.role-admin .user-chip { background: #eef2ff; color: #3730a3; }

/* ---------------- layout ---------------- */
.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px clamp(14px, 4vw, 32px) 40px;
  flex: 1;
}
.footer {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .6);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { margin: 4px 0 0; font-size: 26px; letter-spacing: -.4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--primary); }
.crumbs .sep { margin: 0 6px; color: #c3c9d6; }
.crumbs .current { color: var(--ink); font-weight: 600; }

.muted { color: var(--muted); }
.small-text { font-size: 12.5px; }

/* ---------------- cards ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.auth-wrap {
  min-height: 58vh;
  display: grid;
  place-items: center;
  padding: 12px 0 36px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 34px 34px 30px;
  text-align: center;
}
.auth-card h1 { margin: 12px 0 6px; font-size: 24px; letter-spacing: -.3px; }
.auth-card .muted { font-size: 13.5px; margin: 0 0 22px; }
.auth-icon { font-size: 34px; line-height: 1; }
.stack { display: flex; flex-direction: column; gap: 14px; text-align: left; }

label { font-size: 13px; font-weight: 600; color: #374151; display: flex; flex-direction: column; gap: 6px; }
label .opt { font-weight: 400; color: var(--muted); }

input[type=text], input[type=password], input:not([type]), textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d7dce8;
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
textarea { resize: vertical; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border: 1px solid #d7dce8;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #f8faff; border-color: #c3cee6; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f3c7c7; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; padding: 12px; font-size: 15px; }
.ghost {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 8px;
}
.ghost:hover { color: var(--primary); background: var(--primary-soft); text-decoration: none; }

/* ---------------- flashes ---------------- */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.flash.error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.flash.success { background: var(--ok-soft); color: #065f46; border-color: #a7f3d0; }
.flash.message, .flash.info { background: var(--primary-soft); color: #1e40af; border-color: #bfdbfe; }

/* ---------------- table ---------------- */
.table-wrap { overflow-x: auto; }
.file-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.file-table th {
  text-align: left;
  padding: 13px 16px;
  background: #fafbfe;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.file-table td { padding: 12px 16px; border-bottom: 1px solid #eef1f7; vertical-align: middle; }
.file-table tbody tr:last-child td { border-bottom: none; }
.file-table tbody tr:hover { background: #fafcff; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.ficon { font-size: 19px; width: 24px; text-align: center; flex: none; }
.fname { font-weight: 600; color: var(--ink); word-break: break-all; }
a.fname:hover { color: var(--primary); }
.size-col, .time-col { white-space: nowrap; color: var(--muted); font-size: 13px; }
.size-col { width: 110px; }
.time-col { width: 150px; }
.action-col { width: 90px; text-align: right; white-space: nowrap; }
.action-col.wide { width: 220px; }
.action-col .btn { margin-left: 4px; }
.perm-col { width: 210px; }
.perm-users { display: inline-block; max-width: 120px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; vertical-align: middle; color: var(--muted); font-size: 12px; }
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .2px;
}
.badge.public { background: var(--ok-soft); color: var(--ok); }
.badge.restricted { background: var(--warn-soft); color: #b45309; }
.badge.admin { margin-top: 8px; background: #eef2ff; color: #3730a3; padding: 4px 10px; }

.empty { padding: 56px 20px; text-align: center; }
.empty-icon { font-size: 44px; margin-bottom: 8px; }
.empty p { margin: 4px 0; font-weight: 600; }
.empty .muted { font-size: 13px; }

/* ---------------- upload / forms ---------------- */
.upload-panel, .mkdir-panel { margin-bottom: 18px; padding: 20px; }
.upload-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.upload-head h2 { margin: 0; font-size: 16px; }
.upload-options { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.field { min-width: 220px; }
.users-field { flex: 1; }
.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 30px 18px;
  text-align: center;
  background: #fafcff;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dz-icon { font-size: 30px; margin-bottom: 6px; }
.dropzone p { margin: 6px 0; font-size: 14px; }
.progress-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.progress-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.pr-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; margin-bottom: 7px; }
.pr-name { font-weight: 600; word-break: break-all; }
.pr-status { color: var(--muted); white-space: nowrap; }
.bar { height: 6px; background: #eef1f7; border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .2s; }
.progress-row.ok .bar i { background: var(--ok); }
.progress-row.fail { border-color: #fecaca; background: #fff7f7; }
.progress-row.fail .pr-status { color: var(--danger); }

.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 200px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.hint {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------------- perms ---------------- */
.form-card { padding: 24px; }
.perms-form { display: flex; flex-direction: column; gap: 16px; max-width: 640px; }
.radio-row {
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.radio-row:hover { border-color: #c3cee6; background: #fafcff; }
.radio-row input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--primary); flex: none; }
.radio-row span { display: flex; flex-direction: column; gap: 3px; }
.radio-row small { font-weight: 400; color: var(--muted); font-size: 12.5px; }

/* ---------------- password ---------------- */
.password-card { margin-top: 18px; padding: 0 20px 20px; }
.password-card summary {
  padding: 16px 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
}
.password-card[open] summary { color: var(--ink); }
.password-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.password-form label { flex: 1; min-width: 160px; }
.password-form .btn { margin-bottom: 1px; }

/* ---------------- error ---------------- */
.error-card { padding: 44px 30px; }
.error-code { font-size: 52px; font-weight: 800; color: #c7d2fe; letter-spacing: -2px; }
.error-card h1 { font-size: 20px; margin: 2px 0 8px; }
.error-card .btn { margin-top: 16px; }

/* ---------------- responsive ---------------- */
.inline { display: inline; }

@media (max-width: 720px) {
  .time-col { display: none; }
  .file-table th, .file-table td { padding: 11px 10px; }
  .name-cell { min-width: 150px; }
  .perm-col { display: none; }
  .action-col.wide { width: auto; }
  .page-head h1 { font-size: 22px; }
  .auth-card { padding: 28px 22px; }
  .upload-panel { padding: 16px; }
}
