:root {
  --bg: #0f1218;
  --bg-alt: #161a22;
  --surface: #1c212c;
  --surface-2: #232936;
  --border: #2a3142;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --muted: #6a7285;
  --primary: #7c3aed;
  --primary-hover: #8b5cf6;
  --accent: #22d3ee;
  --success: #10b981;
  --warn: #f59e0b;
  --error: #ef4444;
  --danger: #dc2626;
  --ok: #34d399;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --transition: 140ms ease;
  --sidebar-width: 240px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
body { display: flex; flex-direction: column; min-height: 100vh; font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 1rem; margin: 0 0 10px; }

/* brand */
.brand-link { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 1.1rem; text-decoration: none; }
.brand-link:hover { text-decoration: none; }
.brand-link i { color: var(--primary); font-size: 1.4rem; }

/* layout with sidebar */
body.has-sidebar { display: block; }
body.has-sidebar .app-shell {
  display: flex; flex-direction: column;
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition);
}
body.no-sidebar .app-shell { display: flex; flex-direction: column; min-height: 100vh; }

/* sidebar */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform var(--transition);
}
.sidebar-brand {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .brand-link { font-size: 1.15rem; }
.sidebar-close { display: none; }

.sidebar-nav {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 10px; flex: 1;
  overflow-y: auto;
}
.sidebar-footer {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px; border-top: 1px solid var(--border);
}

.side-link {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--text-dim); text-decoration: none;
  font-size: 0.95em; font-weight: 500;
  transition: var(--transition);
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
}
.side-link i { width: 20px; text-align: center; font-size: 1em; }
.side-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.side-link.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.side-link.active i { color: var(--primary); }
.side-link-button { background: none; }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 35;
}

/* topbar */
.app-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.sidebar-toggle { display: none; }
.topbar-brand { display: none; font-size: 1.05rem; }

.search-form {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 10px;
  flex: 1; max-width: 520px;
}
.search-form i { color: var(--muted); }
.search-form input { border: 0; background: transparent; color: var(--text); outline: none; flex: 1; font-size: 0.95em; }
.search-form.big { padding: 10px 14px; max-width: 600px; margin-bottom: 20px; flex: none; width: 100%; }

/* main */
.app-main { flex: 1; padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
.app-footer { padding: 16px; border-top: 1px solid var(--border); color: var(--muted); text-align: center; font-size: 0.85em; }

.page { display: flex; flex-direction: column; gap: 20px; }

/* flashes */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  animation: slide-in 180ms ease;
}
.flash span { flex: 1; }
.flash-close { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px; }
.flash-success { border-color: #114a33; color: #b7f4d5; background: #0f2a20; }
.flash-error { border-color: #5a1b1b; color: #fecaca; background: #2a1212; }
.flash-info { border-color: #174e75; color: #c6e2f7; background: #0f2230; }

@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer; text-decoration: none;
  font-size: 0.92em; font-weight: 500;
  transition: var(--transition);
}
.btn:hover { background: var(--surface); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-block { width: 100%; justify-content: center; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-icon { padding: 6px 8px; }
.btn-danger { color: #fecaca; }
.btn-danger:hover { background: #451a1a; border-color: #7a2626; }
.btn-large { padding: 12px 22px; font-size: 1em; }
.inline { display: inline; }

/* forms */
.stacked-form { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid > label { flex-direction: column; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.stacked-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9em; color: var(--text-dim); }
.stacked-form label.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.stacked-form input, .stacked-form select, .stacked-form textarea {
  padding: 9px 12px; border-radius: var(--radius);
  background: var(--bg-alt); border: 1px solid var(--border);
  color: var(--text); outline: none; font-size: 0.95em;
  transition: var(--transition);
}
.stacked-form input:focus, .stacked-form select:focus, .stacked-form textarea:focus { border-color: var(--primary); }

/* auth */
.auth-wrapper { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 140px); padding: 20px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow);
}
.auth-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--muted); font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.1em; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.sso-stack { display: flex; flex-direction: column; gap: 8px; }
.btn-sso { justify-content: center; background: var(--surface-2); border-color: var(--border); }
.btn-sso:hover { background: var(--surface); border-color: var(--primary); }
.btn-sso i { color: var(--accent); }

.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand i { font-size: 2.2rem; color: var(--primary); }
.auth-brand h1 { font-size: 1.5rem; margin: 12px 0 6px; }
.auth-brand p { color: var(--text-dim); margin: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }

/* card */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
}
.card.highlight { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card h2 { margin-bottom: 16px; }
.card.center-col { text-align: center; }

/* browser */
.browser-page .browser-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap;
}
.breadcrumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.breadcrumbs .crumb {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: var(--radius);
  color: var(--text-dim);
}
.breadcrumbs .crumb:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.breadcrumbs .crumb.current { color: var(--text); font-weight: 500; cursor: default; }
.breadcrumbs .sep { color: var(--muted); font-size: 0.8em; }
.browser-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.folder-meta { display: flex; gap: 18px; flex-wrap: wrap; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.folder-meta-item { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 0.92em; }
.folder-meta-item .meter { width: 120px; }

/* listing */
.files-table { width: 100%; border-collapse: collapse; }
.files-table th, .files-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.95em; vertical-align: middle; }
.files-table th { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 500; }
.files-table tbody tr { transition: var(--transition); }
.files-table tbody tr:hover { background: var(--surface-2); }
.files-table tr.expired { opacity: 0.55; }

.col-size, .col-updated, .col-expires { white-space: nowrap; color: var(--text-dim); }
.col-actions { width: 1%; white-space: nowrap; }
.col-name { min-width: 180px; }

.item-link {
  display: inline-flex; align-items: center; gap: 10px; color: var(--text);
  max-width: 100%;
}
.item-link:hover { text-decoration: none; color: var(--accent); }
.item-icon { width: 22px; text-align: center; font-size: 1.05em; }
.item-icon.folder { color: #fbbf24; }
.item-icon.link { color: var(--accent); }
.item-icon.file { color: #94a3b8; }
.item-icon.large { font-size: 2.2rem; }
.item-name { word-break: break-word; }

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

.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-dim);
  border: 1px dashed var(--border); border-radius: var(--radius-lg);
  background: var(--surface);
}
.empty-state i { font-size: 2.2rem; color: var(--muted); margin-bottom: 8px; }

/* meter */
.meter { background: var(--border); height: 5px; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.meter-bar { background: linear-gradient(90deg, var(--primary), var(--accent)); height: 100%; transition: width var(--transition); }

/* dashboard stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.stat-card { display: flex; gap: 14px; align-items: flex-start; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.stat-icon { width: 40px; height: 40px; background: var(--surface-2); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; color: var(--primary); font-size: 1.3em; flex-shrink: 0; }
.stat-card.admin .stat-icon { color: var(--accent); }
.stat-label { color: var(--text-dim); font-size: 0.85em; }
.stat-value { font-size: 1.7rem; font-weight: 600; line-height: 1.2; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.badge.green { background: #103a28; color: #4ade80; }
.badge.red { background: #3a1212; color: #fca5a5; }
.badge.orange { background: #3a2812; color: #fdba74; }
.badge.purple { background: #2a1a4a; color: #c4b5fd; }
.ok { color: var(--ok); }

/* modal */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); align-items: center; justify-content: center; z-index: 100; padding: 20px; animation: fade-in 120ms ease; }
.modal.open { display: flex; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-card.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-card > form { padding: 18px 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* dropzone */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; cursor: pointer; transition: var(--transition); position: relative; }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone-inner i { font-size: 2rem; color: var(--primary); margin-bottom: 8px; display: block; }
.dropzone.drag { background: var(--surface-2); border-color: var(--primary); }

/* share table */
.compact-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.compact-table th, .compact-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.9em; }
.compact-table th { color: var(--muted); text-transform: uppercase; font-size: 0.75em; }
.share-form { display: grid; grid-template-columns: 2fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.share-form .checkbox-row { display: flex; gap: 12px; align-items: center; grid-column: 1 / -1; color: var(--text); }
.share-form.inline { display: grid; }
.copy-row { display: flex; gap: 6px; align-items: center; }
.copy-row input { flex: 1; padding: 6px 10px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-family: ui-monospace, monospace; font-size: 0.85em; }
.copy-row input.copied, .code-block.copied { background: #1f3a2b; border-color: var(--ok); }

.ci-cmd-row { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 10px; }
.ci-cmd {
  flex: 1;
  margin: 0;
  padding: 10px 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82em;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
}
.ci-cmd.copied { background: #1f3a2b; border-color: var(--ok); }
.ci-subcaption { margin: 4px 0 4px; font-size: 0.82em; }

#listing-wrap { transition: opacity 0.15s ease; }
#listing-wrap.listing-loading { opacity: 0.4; pointer-events: none; }

.code-example { margin-top: 12px; }
.code-example-label { font-size: 0.8em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.code-block {
  flex: 1;
  margin: 0;
  padding: 10px 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82em;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  transition: background var(--transition), border-color var(--transition);
}

/* kv */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 20px; }
.kv > div { display: flex; flex-direction: column; }
.kv .k { font-size: 0.75em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kv .v { font-size: 0.95em; color: var(--text); }

/* preview */
.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.preview-title { display: flex; align-items: center; gap: 14px; }
.preview-title h1 { margin: 0 0 4px; }
.preview-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* magic hero */
.magic-hero { display: flex; align-items: center; gap: 16px; padding: 18px 20px; background: linear-gradient(135deg, rgba(124,58,237,0.15), rgba(34,211,238,0.1)); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.magic-hero > i { font-size: 2.5rem; color: var(--primary); }
.magic-hero h1 { margin: 0; font-size: 1.5rem; }

/* mobile */
@media (max-width: 900px) {
  body.has-sidebar .app-shell { margin-left: 0; }
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  body.sidebar-open .sidebar { transform: translateX(0); box-shadow: var(--shadow); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar-close { display: inline-flex; }
  .sidebar-toggle { display: inline-flex; }
  .topbar-brand { display: flex; }
  .app-topbar { padding: 8px 12px; gap: 8px; }
  .app-main { padding: 14px; }
  .files-table th.col-updated, .files-table td.col-updated, .files-table th.col-expires, .files-table td.col-expires { display: none; }
  .share-form { grid-template-columns: 1fr; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 1.35rem; }
  .browser-actions .btn span { display: none; }
  .browser-actions .btn { padding: 8px 10px; }
  .preview-title h1 { font-size: 1.2rem; }
}

@media (max-width: 480px) {
  .files-table th.col-size, .files-table td.col-size { display: none; }
  .topbar-brand span { display: none; }
}
