:root {
  --bg: #faf7f3;
  --panel: #ffffff;
  --ink: #2b2118;
  --muted: #7a6a5c;
  --line: #ece4da;
  --brand: #5a3a22;
  --brand-2: #8a5a36;
  --accent: #c8a27a;
  --hover: #f4ede5;
  --danger: #b4382c;
  --ok: #2f7d4f;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(43, 33, 24, .12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-2); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; text-decoration: none; color: var(--ink);
  white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=password], input[type=search], select {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; background: #fff; width: 100%;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-size: 13px; color: var(--muted); }

/* Simple pages (login, share) */
body.simple { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.card-page {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 32px; width: 100%; max-width: 460px;
}
.card-page h1 { font-size: 22px; margin: 18px 0 8px; }
.card-page h1.filename { font-size: 18px; margin: 0 0 2px; word-break: break-word; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--brand); font-size: 17px; }
.logo-dot {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 35% 35%, var(--accent), var(--brand)); display: inline-block;
}
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.link { color: var(--brand-2); }
.alert { background: #fbeceb; color: var(--danger); border-radius: 8px; padding: 10px 12px; margin-top: 12px; }
.share-file { display: flex; gap: 14px; align-items: center; margin: 22px 0 16px; }
.file-badge {
  min-width: 52px; height: 60px; border-radius: 8px; background: var(--hover); color: var(--brand);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; padding: 0 6px;
}
.share-preview { width: 100%; max-height: 420px; object-fit: contain; border-radius: 8px; background: #f3efe9; margin-bottom: 14px; }
.share-audio { width: 100%; margin-bottom: 14px; }
.share-frame { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 14px; }
body.simple:has(.share-frame) .card-page, body.simple:has(.share-preview) .card-page { max-width: 760px; }

/* App layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 0 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.sidebar nav a:hover { background: var(--hover); }
.sidebar nav a.active { background: var(--hover); color: var(--brand); font-weight: 600; }
.usage { font-size: 13px; color: var(--muted); padding: 0 10px; line-height: 1.6; }
.logout { margin-top: auto; padding: 0 8px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.who { font-size: 13px; color: var(--muted); word-break: break-all; }
.main { flex: 1; min-width: 0; padding: 0 24px 80px; position: relative; }
.topbar {
  display: flex; gap: 10px; align-items: center; padding: 16px 0; position: sticky; top: 0;
  background: var(--bg); z-index: 5; flex-wrap: wrap;
}
.topbar input[type=search] { max-width: 420px; flex: 1; min-width: 160px; }
.topbar .actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.menu-btn { display: none; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 6px 0 14px; font-size: 18px; }
.crumbs a { color: var(--ink); text-decoration: none; padding: 4px 8px; border-radius: 6px; }
.crumbs a:hover { background: var(--hover); }
.crumbs .sep { color: var(--muted); }
.crumbs .current { font-weight: 600; padding: 4px 8px; }
h2.view-title { font-size: 20px; margin: 6px 0 14px; }

/* File table */
.table { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) 100px 150px 120px; align-items: center;
  gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); min-height: 48px;
}
.row:first-child { border-top: 0; }
.row.head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; min-height: 38px; }
.row:not(.head):hover { background: #fcfaf7; }
.row.selected { background: #f7efe6 !important; }
.row .name { display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.row .name span.label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .name small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 13px; }
.row .row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.row .row-actions .btn { padding: 5px 8px; font-size: 13px; }
.icon { width: 28px; height: 28px; flex-shrink: 0; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff; }
.icon.folder { background: #d9b48a; }
.icon.image { background: #4f8a6e; }
.icon.pdf { background: #c0473a; }
.icon.video { background: #7056a8; }
.icon.audio { background: #b06a2c; }
.icon.doc { background: #3d6db3; }
.icon.sheet { background: #2f8a4f; }
.icon.slide { background: #d08a1e; }
.icon.zip { background: #6b5b4e; }
.icon.file { background: #9b8b7c; }
.badge { display: inline-block; font-size: 11px; background: #eaf3ed; color: var(--ok); border-radius: 20px; padding: 2px 8px; margin-left: 6px; flex-shrink: 0; }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }

.bulkbar {
  display: flex; align-items: center; gap: 8px; background: var(--brand); color: #fff; border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 10px;
}
.bulkbar .btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }
.bulkbar .btn:hover { background: rgba(255,255,255,.22); }
.bulkbar .count { margin-right: auto; font-weight: 600; }

/* Drop zone */
.drop-hint {
  display: none; position: fixed; inset: 16px; border: 3px dashed var(--accent); border-radius: 16px;
  background: rgba(250, 247, 243, .92); z-index: 40; align-items: center; justify-content: center;
  font-size: 22px; color: var(--brand); font-weight: 600; pointer-events: none;
}
body.dragging .drop-hint { display: flex; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(30, 22, 15, .45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { max-width: 980px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.modal header .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal .body { padding: 18px 20px; overflow: auto; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.preview-body { display: flex; align-items: center; justify-content: center; background: #f3efe9; min-height: 300px; padding: 0 !important; }
.preview-body img, .preview-body video { max-width: 100%; max-height: 75vh; display: block; }
.preview-body iframe { width: 100%; height: 75vh; border: 0; background: #fff; }
.preview-body audio { width: 90%; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.share-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.share-item .url { display: flex; gap: 6px; }
.share-item .url input { font-size: 13px; }
.share-item .info { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.share-item .info .btn { margin-left: auto; }
.picker-list { border: 1px solid var(--line); border-radius: 8px; max-height: 320px; overflow: auto; }
.picker-list div { padding: 9px 12px; border-top: 1px solid var(--line); cursor: pointer; display: flex; gap: 8px; align-items: center; }
.picker-list div:first-child { border-top: 0; }
.picker-list div:hover { background: var(--hover); }

/* Row menu */
.menu { position: fixed; z-index: 55; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 180px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }

/* Upload panel */
.uploads {
  position: fixed; right: 18px; bottom: 18px; width: 360px; max-width: calc(100vw - 36px); background: var(--panel);
  border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); z-index: 45; overflow: hidden;
}
.uploads header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--brand); color: #fff; font-weight: 600; font-size: 14px; }
.uploads header span { flex: 1; }
.uploads header .btn { color: #fff; padding: 2px 8px; }
.uploads .list { max-height: 260px; overflow: auto; }
.up-item { padding: 8px 14px; border-top: 1px solid var(--line); font-size: 13px; }
.up-item .n { display: flex; justify-content: space-between; gap: 8px; }
.up-item .n span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item.err .n span:last-child { color: var(--danger); }
.up-item.done .n span:last-child { color: var(--ok); }
.bar { height: 5px; background: var(--hover); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--brand-2); transition: width .2s; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; font-size: 14px; }
.toast.err { background: var(--danger); }

/* Import page */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 10px; font-size: 16px; }
.panel ol { margin: 0; padding-left: 20px; line-height: 1.7; }
.import-row { display: grid; grid-template-columns: minmax(0, 1fr) 220px auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.import-row:first-of-type { border-top: 0; }
.import-row .zipname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.import-row .btns { display: flex; gap: 6px; }

@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.menu-open .sidebar { transform: none; }
  .menu-btn { display: inline-flex; }
  .main { padding: 0 12px 80px; }
  .row { grid-template-columns: 30px minmax(0, 1fr) auto; }
  .row .meta { display: none; }
  .topbar .actions { margin-left: 0; width: 100%; }
  .import-row { grid-template-columns: 1fr; }
}

/* Version and admin */
.version { font-size: 12px; color: var(--muted); opacity: .8; }
.card-page .version { text-align: center; margin-top: 22px; }
.sidebar nav a.nav-admin { margin-top: 10px; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; padding-top: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; color: var(--ink); }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 10px; align-items: baseline; padding: 7px 0; border-top: 1px solid var(--line); }
.checks li:first-child { border-top: 0; }
.checks .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--ok); }
.checks li.bad .dot { background: var(--danger); }
.checks .info { margin-left: auto; color: var(--muted); font-size: 13px; text-align: right; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.grid-table { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.grid-table table { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid-table th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 500; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid-table td { padding: 9px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.grid-table tr:first-child td { border-top: 0; }
.grid-table td.actions { text-align: right; white-space: nowrap; }
.grid-table td.wrap { max-width: 360px; word-break: break-word; }
.grid-table td.muted { font-size: 13px; }
.pill { display: inline-block; font-size: 11px; border-radius: 20px; padding: 2px 9px; background: var(--hover); color: var(--brand); white-space: nowrap; }
.pill.superadmin { background: var(--brand); color: #fff; }
.pill.admin { background: #f2e2cf; color: var(--brand); }
.pill.ok, .pill.active { background: #eaf3ed; color: var(--ok); }
.pill.bad, .pill.off, .pill.blocked { background: #fbeceb; color: var(--danger); }
.pill.expired { background: #efebe6; color: var(--muted); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.inline-form input[type=email], .inline-form input[type=text] { max-width: 280px; }
.inline-form select { width: auto; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar .spacer { flex: 1; }
.grid-table select { width: auto; padding: 5px 8px; }

/* Staging */
.sidebar nav a .count { float: right; background: var(--brand); color: #fff; font-size: 11px; font-weight: 600; border-radius: 20px; padding: 1px 8px; margin-top: 1px; }
.staging-intro { background: #fbf3e8; border: 1px solid #f0dfc8; color: var(--ink); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; font-size: 14px; }
.empty .btn { margin-top: 8px; }
.brand img.logo { width: 24px; height: 24px; border-radius: 6px; display: block; }

/* Music player */
.player {
  position: fixed; left: 240px; right: 0; bottom: 0; z-index: 35; background: #2b2118; color: #f6efe6;
  display: grid; grid-template-columns: minmax(140px, 1fr) auto minmax(220px, 2fr) auto; gap: 18px; align-items: center;
  padding: 10px 20px; box-shadow: 0 -6px 24px rgba(43, 33, 24, .25);
}
.pl-info { min-width: 0; }
.pl-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-sub { font-size: 12px; color: #c9b8a6; margin-top: 2px; }
.pl-controls, .pl-extra { display: flex; align-items: center; gap: 6px; }
.pl-btn { background: none; border: 0; color: inherit; width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; text-decoration: none; font-size: 15px; }
.pl-btn:hover { background: rgba(255, 255, 255, .1); }
.pl-btn:disabled { opacity: .35; cursor: default; background: none; }
.pl-main { width: 46px; height: 46px; background: var(--accent); color: #2b2118; }
.pl-main:hover { background: #d8b892; }
.player .i-pause, .player.is-playing .i-play { display: none; }
.player.is-playing .i-pause { display: block; }
.pl-seek { display: flex; align-items: center; gap: 10px; font-size: 12px; color: #c9b8a6; font-variant-numeric: tabular-nums; }
.player input[type=range] { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .2); flex: 1; cursor: pointer; }
#plSeek { background: linear-gradient(to right, var(--accent) var(--pct, 0%), rgba(255, 255, 255, .2) var(--pct, 0%)); }
.player input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; }
.player input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; }
#plVol { width: 90px; flex: none; }
.pl-vol-icon { color: #c9b8a6; }
body.has-player .main { padding-bottom: 120px; }
body.has-player .uploads { bottom: 96px; }
body.has-player .toast { bottom: 100px; }
.row.playing { background: #fbf3e8 !important; }
.row.playing .name .label { color: var(--brand); font-weight: 600; }
.icon.play-icon { cursor: pointer; }
.toast.link { cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.menu-btn { position: relative; }
.menu-btn[data-count]::after { content: attr(data-count); position: absolute; top: -2px; right: -4px; background: var(--brand); color: #fff; font-size: 10px; font-weight: 700; border-radius: 10px; padding: 1px 5px; line-height: 1.3; }

@media (max-width: 820px) {
  .player { left: 0; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "info controls" "seek seek"; gap: 6px 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .pl-info { grid-area: info; }
  .pl-controls { grid-area: controls; }
  .pl-seek { grid-area: seek; }
  .pl-extra { display: none; }
  .player .pl-btn#plClose { display: none; }
  body.has-player .main { padding-bottom: 150px; }
  body.has-player .uploads { bottom: 120px; }
  body.has-player .toast { bottom: 124px; }
}

.pl-close-m { display: none; }
@media (max-width: 820px) { .pl-close-m { display: inline-flex; width: 32px; } }
