:root {
  color-scheme: dark light;
  --bg: #0a0b0f;
  --bg-elevated: #101218;
  --bg-card: #14161d;
  --bg-hover: #1b1e27;
  --bg-inset: #0d0e13;
  --border: #232631;
  --border-soft: #1b1e27;
  --text: #eef0f5;
  --text-muted: #9298a8;
  --text-faint: #5c6272;
  --accent: #7c6cff;
  --accent-strong: #9285ff;
  --accent-2: #23d3c4;
  --accent-grad: linear-gradient(135deg, #7c6cff 0%, #2fb8d8 100%);
  --accent-grad-soft: linear-gradient(135deg, rgba(124, 108, 255, 0.16), rgba(47, 184, 216, 0.12));
  --danger: #ff5d72;
  --danger-bg: rgba(255, 93, 114, 0.12);
  --warning: #ffb020;
  --warning-bg: rgba(255, 176, 32, 0.12);
  --success: #2ecf8e;
  --success-bg: rgba(46, 207, 142, 0.12);
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f8;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #eef0f6;
    --bg-inset: #eceef4;
    --border: #e3e5ee;
    --border-soft: #ececf1;
    --text: #171923;
    --text-muted: #5c6172;
    --text-faint: #8a90a3;
    --accent-grad-soft: linear-gradient(135deg, rgba(124, 108, 255, 0.09), rgba(47, 184, 216, 0.07));
    --danger-bg: rgba(255, 93, 114, 0.09);
    --warning-bg: rgba(255, 176, 32, 0.1);
    --success-bg: rgba(46, 207, 142, 0.1);
    --shadow-sm: 0 1px 2px rgba(20, 20, 45, 0.05);
    --shadow: 0 8px 24px rgba(20, 20, 45, 0.08);
    --shadow-lg: 0 24px 60px rgba(20, 20, 45, 0.12);
  }
}

* { box-sizing: border-box; }
::selection { background: rgba(124, 108, 255, 0.35); }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.icon { width: 1.1em; height: 1.1em; flex: none; display: inline-block; vertical-align: -0.15em; }

.page { min-height: 100vh; display: flex; flex-direction: column; }
.container { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 24px; }

/* ---------------------------------------------------------------- Topbar */
.topbar {
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner { max-width: 1160px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-grad); color: white; box-shadow: 0 4px 14px rgba(124, 108, 255, 0.35);
}
.brand-mark .icon { width: 18px; height: 18px; }
.topnav { display: flex; align-items: center; gap: 6px; }
.topnav-link { text-decoration: none; color: var(--text-muted); font-weight: 600; font-size: 0.9rem; padding: 8px 14px; border-radius: 20px; transition: background 0.15s ease, color 0.15s ease; }
.topnav-link:hover { color: var(--text); background: var(--bg-hover); }
.topnav-link.is-active { color: var(--text); background: var(--bg-hover); }
.topnav-divider { width: 1px; height: 22px; background: var(--border); margin: 0 8px; }
.topnav-user { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 0.85rem; padding: 0 4px; }
.topnav-user-badge {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent-grad-soft); color: var(--accent-strong);
  display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
}

.main { flex: 1; padding: 48px 0 90px; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 10px 18px; font-size: 0.9rem; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform 0.06s ease, opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  font-family: inherit; line-height: 1.2;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent-grad); color: white; box-shadow: 0 6px 16px rgba(124, 108, 255, 0.3); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: rgba(255, 93, 114, 0.2); }
.btn-icon { padding: 8px; width: 34px; height: 34px; border-radius: var(--radius-sm); }
.btn-sm { padding: 7px 13px; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.inline-form { display: inline; }
.action-group { display: inline-flex; align-items: center; gap: 2px; background: var(--bg-inset); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 3px; }
.action-group .btn-icon:hover { background: var(--bg-hover); }

.quota-form { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.quota-input-group { display: flex; align-items: center; background: var(--bg-inset); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); transition: border-color 0.15s ease; }
.quota-input-group:focus-within { border-color: var(--accent); }
.quota-input-group input[type="number"] {
  width: 50px; border: none; background: transparent; color: var(--text); font-size: 0.85rem;
  padding: 8px 2px 8px 10px; -moz-appearance: textfield; font-family: inherit;
}
.quota-input-group input[type="number"]::-webkit-outer-spin-button,
.quota-input-group input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.quota-input-group input[type="number"]:focus { outline: none; }
.quota-input-group input[type="number"]:disabled { opacity: 0.35; }
.quota-unit { font-size: 0.76rem; color: var(--text-faint); padding: 7px 10px 7px 4px; }
.quota-unlimited { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; cursor: pointer; }
.quota-unlimited input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; flex: none; }

/* ---------------------------------------------------------------- Auth */
.auth-shell { flex: 1; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-aside {
  position: relative; display: flex; flex-direction: column; justify-content: center; gap: 28px;
  padding: 64px; background: var(--bg-inset); overflow: hidden;
}
.auth-aside::before {
  content: ""; position: absolute; inset: -20%; background: var(--accent-grad); opacity: 0.16; filter: blur(80px);
}
.auth-aside-content { position: relative; max-width: 420px; }
.auth-aside .brand { font-size: 1.4rem; margin-bottom: 28px; }
.auth-aside .brand-mark { width: 40px; height: 40px; border-radius: 11px; }
.auth-aside .brand-mark .icon { width: 22px; height: 22px; }
.auth-aside h2 { font-size: 1.7rem; line-height: 1.3; margin-bottom: 14px; }
.auth-aside p { color: var(--text-muted); font-size: 0.98rem; margin: 0 0 28px; }
.auth-feature-list { display: flex; flex-direction: column; gap: 16px; position: relative; }
.auth-feature { display: flex; align-items: flex-start; gap: 12px; font-size: 0.92rem; color: var(--text-muted); }
.auth-feature .icon { color: var(--accent-strong); margin-top: 2px; }
.auth-feature strong { color: var(--text); font-weight: 600; }

.auth-form-side { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.auth-sub { color: var(--text-muted); margin: 0 0 28px; font-size: 0.92rem; }
.auth-foot { margin-top: 24px; text-align: center; color: var(--text-muted); font-size: 0.86rem; }
.auth-foot a { color: var(--accent-strong); font-weight: 600; text-decoration: none; }

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}

/* ---------------------------------------------------------------- Forms */
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 0.84rem; font-weight: 600; margin-bottom: 7px; color: var(--text-muted); }
.field input[type="text"], .field input[type="email"], .field input[type="password"], .field input[type="number"], .field select {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 0.95rem; font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-grad-soft); }
.field-hint { font-size: 0.78rem; color: var(--text-faint); margin-top: 6px; }
.checkbox-field { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.checkbox-field input { width: 16px; height: 16px; flex: none; }
.checkbox-field label { font-size: 0.88rem; color: var(--text); }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

.alert { display: flex; align-items: flex-start; gap: 10px; border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 18px; font-size: 0.86rem; }
.alert .icon { margin-top: 1px; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(255, 93, 114, 0.28); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(46, 207, 142, 0.28); }
.alert-info { background: var(--accent-grad-soft); color: var(--accent-strong); border: 1px solid rgba(124, 108, 255, 0.28); }

/* ---------------------------------------------------------------- Headers & stats */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 32px; flex-wrap: wrap; }
.page-header .eyebrow { display: block; color: var(--accent-strong); font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.page-header h1 { font-size: 1.9rem; margin-bottom: 6px; }
.page-header p { margin: 0; color: var(--text-muted); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 36px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); padding: 22px; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow-sm); }
.stat-chip { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: var(--accent-grad-soft); color: var(--accent-strong); flex: none; }
.stat-chip .icon { width: 20px; height: 20px; }
.stat-card .stat-label { color: var(--text-faint); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.01em; }
.stat-value-quota { font-size: 0.95rem; font-weight: 600; color: var(--text-faint); }
.quota-bar-track { height: 5px; border-radius: 4px; background: var(--bg-inset); overflow: hidden; margin-top: 8px; }
.quota-bar-fill { height: 100%; background: var(--accent-grad); border-radius: 4px; }

/* ---------------------------------------------------------------- Upload */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius-lg); background: var(--bg-card);
  padding: 44px 24px; text-align: center; cursor: pointer; margin-bottom: 20px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.is-dragover { border-color: var(--accent); background: var(--accent-grad-soft); }
.dropzone-icon {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-grad-soft); color: var(--accent-strong);
}
.dropzone-icon .icon { width: 26px; height: 26px; }
.dropzone h3 { margin: 0 0 6px; font-size: 1.05rem; }
.dropzone p { margin: 0; color: var(--text-muted); font-size: 0.88rem; }
.dropzone input[type="file"] { display: none; }

.upload-options { background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 20px; display: none; box-shadow: var(--shadow-sm); }
.upload-options.is-visible { display: block; }
.upload-options .file-preview { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--border-soft); }
.upload-options .file-preview-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--bg-inset); color: var(--text-muted); display: flex; align-items: center; justify-content: center; flex: none; }
.upload-options .file-preview .fname { font-weight: 700; word-break: break-all; }
.upload-options .file-preview .fsize { color: var(--text-faint); font-size: 0.85rem; }

.progress-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.progress-item { background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.progress-item-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 10px; font-size: 0.87rem; }
.progress-item-head .pname { font-weight: 700; word-break: break-all; }
.progress-item-head .pstatus { color: var(--text-faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.progress-bar-track { height: 7px; border-radius: 5px; background: var(--bg-inset); overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--accent-grad); width: 0%; transition: width 0.2s ease; border-radius: 5px; }
.progress-item.is-error .progress-bar-fill { background: var(--danger); }
.progress-item.is-done .progress-bar-fill { background: var(--success); }

/* ---------------------------------------------------------------- Cards / tables */
.card { background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.card-pad { padding: 28px; margin-bottom: 32px; }
.card-pad:last-child { margin-bottom: 0; }
.container-narrow { max-width: 760px; }
.field-role { max-width: 170px; }
.field-quota { max-width: 160px; }
.field-port { max-width: 140px; }
.field-grow-2 { flex: 2; }
.field-flush { margin-bottom: 0; }
.checkbox-field-aligned { margin-top: 30px; }
.field-row-align-end { align-items: flex-end; }
.section-flush { margin-bottom: 0; }
.admin-quick-actions { display: flex; gap: 14px; flex-wrap: wrap; }
.legal-text { color: var(--text-muted); line-height: 1.8; }
.is-hidden { display: none; }
.upload-options .modal-actions { justify-content: flex-start; }
.download-card .field-hint, .auth-card .field-hint { margin-top: 16px; margin-bottom: 28px; text-align: center; }
table.files-table { width: 100%; border-collapse: collapse; }
table.files-table th, table.files-table td { padding: 16px 20px; text-align: left; border-bottom: 1px solid var(--border-soft); font-size: 0.9rem; vertical-align: middle; }
table.files-table th { color: var(--text-faint); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; background: var(--bg-inset); }
table.files-table tbody tr { transition: background 0.12s ease; }
table.files-table tbody tr:hover { background: var(--bg-hover); }
table.files-table tr:last-child td { border-bottom: none; }
table.files-table td.actions { white-space: nowrap; text-align: right; }
.fname-cell { display: flex; align-items: center; gap: 12px; }
.fname-icon { width: 36px; height: 36px; border-radius: 9px; background: var(--bg-inset); color: var(--text-muted); display: flex; align-items: center; justify-content: center; flex: none; }
.fname-icon .icon { width: 17px; height: 17px; }
.fname-text { min-width: 0; }
.fname-main { font-weight: 700; word-break: break-word; }
.fname-label { display: flex; align-items: center; gap: 5px; color: var(--accent-strong); font-size: 0.78rem; font-weight: 600; margin-top: 3px; }
.fname-label .icon { width: 12px; height: 12px; }
.fname-sub { color: var(--text-faint); font-size: 0.78rem; margin-top: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.link-copy { display: inline-flex; align-items: center; gap: 8px; background: var(--bg-inset); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 7px 10px; font-size: 0.8rem; color: var(--text-muted); max-width: 230px; }
.link-copy code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.link-copy button { border: none; background: none; color: var(--text-muted); cursor: pointer; display: flex; padding: 2px; flex: none; }
.link-copy button:hover { color: var(--accent-strong); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.badge .icon { width: 11px; height: 11px; }
.badge-permanent { background: var(--success-bg); color: var(--success); }
.badge-locked { background: var(--warning-bg); color: var(--warning); }
.badge-role-admin { background: var(--accent-grad-soft); color: var(--accent-strong); }
.badge-role-user { background: var(--bg-hover); color: var(--text-muted); }
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: var(--danger-bg); color: var(--danger); }

.ip-partial { font-variant-numeric: tabular-nums; }
.ip-hidden { filter: blur(3.5px); user-select: none; opacity: 0.85; }

.empty-state { padding: 70px 20px; text-align: center; color: var(--text-muted); }
.empty-state .e-icon { width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 16px; background: var(--bg-inset); color: var(--text-faint); display: flex; align-items: center; justify-content: center; }
.empty-state .e-icon .icon { width: 24px; height: 24px; }
.empty-state p { margin: 0; font-size: 0.92rem; }

.section { margin-bottom: 40px; }
.section-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 16px; display: flex; align-items: center; gap: 8px; }

/* ---------------------------------------------------------------- Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(5, 6, 10, 0.62); backdrop-filter: blur(2px); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-overlay.is-open { display: flex; }
.modal { width: 100%; max-width: 440px; background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); padding: 28px; box-shadow: var(--shadow-lg); }
.modal h2 { margin: 0 0 18px; font-size: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.modal-actions-split { justify-content: space-between; align-items: center; }
.modal-actions-split-group { display: flex; gap: 10px; }
.modal-list { max-height: 320px; overflow-y: auto; font-size: 0.85rem; }
.modal-list-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border-soft); color: var(--text-muted); }
.modal-list-row:last-child { border-bottom: none; }

/* ---------------------------------------------------------------- Toasts */
.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; box-shadow: var(--shadow-lg); font-size: 0.85rem; max-width: 320px; animation: toast-in 0.2s ease; }
.toast.toast-error { border-color: rgba(255, 93, 114, 0.4); }
.toast.toast-success { border-color: rgba(46, 207, 142, 0.4); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------------------------------------------------------------- Public download */
.download-shell { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 20px; position: relative; overflow: hidden; }
.download-shell::before {
  content: ""; position: absolute; top: -30%; left: 50%; width: 900px; height: 900px; transform: translateX(-50%);
  background: var(--accent-grad); opacity: 0.1; filter: blur(120px); pointer-events: none;
}
.download-card { position: relative; width: 100%; max-width: 460px; background: var(--bg-card); border: 1px solid var(--border-soft); border-radius: var(--radius-lg); padding: 44px 40px; text-align: center; box-shadow: var(--shadow-lg); }
.download-icon { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 20px; display: flex; align-items: center; justify-content: center; background: var(--accent-grad-soft); color: var(--accent-strong); }
.download-icon .icon { width: 30px; height: 30px; }
.download-card h1 { font-size: 1.2rem; margin: 0 0 10px; word-break: break-word; }
.download-meta { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; color: var(--text-muted); font-size: 0.86rem; margin-bottom: 28px; }
.download-meta .dot { color: var(--text-faint); }
.lock-form { text-align: left; margin-top: 6px; }

.footer-note { text-align: center; color: var(--text-faint); font-size: 0.78rem; padding: 24px; line-height: 1.7; }
.footer-note a { color: var(--text-muted); text-decoration: underline; text-underline-offset: 2px; }
.footer-note a:hover { color: var(--accent-strong); }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; }
  .field-row { flex-direction: column; gap: 0; }
  table.files-table { display: block; overflow-x: auto; }
  .download-card { padding: 32px 24px; }
}
