:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --border: #e4e4df;
  --text: #1c1c1a;
  --muted: #74746e;
  --accent: #e8743b;
  --accent-soft: #fbe9df;
  --folder: #f2b84b;
  --folder-dark: #d99a26;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  --shadow-hover: 0 2px 4px rgb(0 0 0 / 0.06), 0 12px 32px rgb(0 0 0 / 0.08);
  --radius: 14px;
  --k-image: #3b82f6;
  --k-video: #a855f7;
  --k-audio: #10b981;
  --k-pdf: #ef4444;
  --k-text: #64748b;
  --k-file: #8b8b84;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2c2c2a;
    --text: #ededea;
    --muted: #8f8f88;
    --accent-soft: #3a2418;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-hover: 0 8px 28px rgb(0 0 0 / 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.no-scroll { overflow: hidden; }

* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

button { font: inherit; color: inherit; }

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- marca ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #f5a05f, var(--accent));
  color: #fff;
  box-shadow: 0 4px 12px rgb(232 116 59 / 0.35);
}

.brand-mark svg { width: 17px; height: 17px; fill: currentColor; stroke: none; }
.brand--lg { font-size: 22px; justify-content: center; }
.brand--lg .brand-mark { width: 42px; height: 42px; border-radius: 12px; }
.brand--lg .brand-mark svg { width: 22px; height: 22px; }

/* ---------- botões e campos ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgb(232 116 59 / 0.3);
}

.btn--primary:hover { background: #dc6529; }
.btn--primary:active { transform: translateY(1px); }
.btn--block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  color: inherit;
  transition: background 0.15s;
}

.icon-btn:hover { background: var(--surface-2); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 500; color: var(--muted); }

.field input,
.search input,
.select {
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.search input:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- login ---------- */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(circle at 20% 10%, rgb(232 116 59 / 0.12), transparent 40%),
    radial-gradient(circle at 80% 90%, rgb(242 184 75 / 0.12), transparent 40%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 36px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-hover);
}

.login-sub { text-align: center; color: var(--muted); margin: 10px 0 28px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form .btn { margin-top: 6px; }

/* ---------- layout ---------- */

.main { max-width: 1440px; margin: 0 auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-row { display: flex; align-items: center; gap: 16px; flex: 1; min-width: 0; }
.topbar .brand { color: var(--text); text-decoration: none; flex-shrink: 0; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.crumb {
  display: inline-block;
  flex-shrink: 0;
  max-width: 320px;
  padding: 6px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button.crumb:hover { background: var(--surface-2); color: var(--text); }
.crumb.is-current { color: var(--text); font-weight: 600; cursor: default; }
.crumb-sep { width: 14px; height: 14px; color: var(--muted); opacity: 0.5; }

.toolbar { display: flex; gap: 10px; flex-shrink: 0; }

.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search input { width: 240px; padding-left: 36px; height: 38px; }
.select { height: 38px; padding-right: 10px; cursor: pointer; }
.select[hidden] { display: none; }

.content { padding: 24px 28px 8px; }
.sentinel { height: 40px; }

/* ---------- seções e grade ---------- */

.section + .section { margin-top: 32px; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.count {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--surface-2);
  font-weight: 500;
}

.grid { display: grid; gap: 14px; }
.grid--folders { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.grid--files { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }

.folder {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  min-width: 0;
}

.folder:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: var(--folder); }

.folder-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--folder) 18%, transparent);
  color: var(--folder-dark);
  flex-shrink: 0;
}

.folder-icon svg { width: 22px; height: 22px; fill: var(--folder); stroke: var(--folder-dark); stroke-width: 1.4; }
.folder-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--border);
  flex-shrink: 0;
}

.status-dot.is-online { background: var(--k-audio); box-shadow: 0 0 0 3px color-mix(in srgb, var(--k-audio) 20%, transparent); }
.folder-name { font-weight: 600; }
.folder-sub { font-size: 12px; color: var(--muted); }

.file {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  min-width: 0;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}

.file:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.file:hover .thumb img { transform: scale(1.04); }

.thumb {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  margin-bottom: 8px;
  border-radius: 9px;
  background: var(--surface-2);
  overflow: hidden;
}

.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s, transform 0.4s;
}

.thumb.is-loaded img { opacity: 1; }
.thumb--image:not(.is-loaded):not(.is-broken) { animation: shimmer 1.4s ease-in-out infinite; }
.thumb-fallback { display: none; color: var(--k-image); }
.thumb.is-broken img { display: none; }
.thumb.is-broken .thumb-fallback { display: block; }
.thumb-fallback svg { width: 30px; height: 30px; }

.thumb-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
}

.thumb-icon svg { width: 28px; height: 28px; }

.thumb-icon--video { color: var(--k-video); background: color-mix(in srgb, var(--k-video) 14%, transparent); }
.thumb-icon--audio { color: var(--k-audio); background: color-mix(in srgb, var(--k-audio) 14%, transparent); }
.thumb-icon--pdf { color: var(--k-pdf); background: color-mix(in srgb, var(--k-pdf) 14%, transparent); }
.thumb-icon--text { color: var(--k-text); background: color-mix(in srgb, var(--k-text) 14%, transparent); }
.thumb-icon--file { color: var(--k-file); background: color-mix(in srgb, var(--k-file) 14%, transparent); }

.thumb-ext {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.thumb-play {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 99px;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.15s, transform 0.15s;
}

.thumb-play svg { width: 11px; height: 11px; fill: currentColor; stroke: none; margin-left: 2px; }
.file:hover .thumb-play { opacity: 1; transform: scale(1); }

.file-date { font-weight: 600; font-size: 13px; padding: 0 2px; font-variant-numeric: tabular-nums; }
.file-meta { font-size: 11px; color: var(--muted); padding: 0 2px; }

/* ---------- estados ---------- */

.skeleton { pointer-events: none; }
.skeleton .thumb, .skeleton-line { animation: shimmer 1.4s ease-in-out infinite; background: var(--surface-2); }
.skeleton-line { display: block; height: 12px; border-radius: 6px; margin: 8px; }

@keyframes shimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px 16px;
  color: var(--muted);
  text-align: center;
}

.empty svg { width: 44px; height: 44px; stroke-width: 1.3; }
.empty--error { color: var(--k-pdf); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 100;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-hover);
  max-width: calc(100% - 32px);
}

/* ---------- visualizador ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: rgb(10 10 10 / 0.94);
  backdrop-filter: blur(8px);
  color: #f2f2f0;
  animation: fade 0.18s ease-out;
}

.viewer[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
}

.viewer-info { flex: 1; min-width: 0; }
.viewer-name { margin: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-meta { margin: 2px 0 0; font-size: 12px; color: #a0a09a; }
.viewer-actions { display: flex; gap: 4px; }
.viewer .icon-btn:hover { background: rgb(255 255 255 / 0.1); }

.viewer-stage {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0 72px 28px;
}

.viewer-media {
  max-width: 100%;
  max-height: calc(100vh - 110px);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.5);
  background: #000;
}

.viewer-doc {
  width: min(1000px, 100%);
  height: calc(100vh - 110px);
  border: 0;
  border-radius: 10px;
  background: #fff;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 99px;
  background: rgb(255 255 255 / 0.08);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.viewer-nav:hover { background: rgb(255 255 255 / 0.18); }
.viewer-nav:disabled { opacity: 0.2; cursor: default; }
.viewer-nav--prev { left: 14px; }
.viewer-nav--next { right: 14px; }

.audio-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: min(420px, 100%);
  padding: 36px 28px;
  border-radius: 20px;
  background: rgb(255 255 255 / 0.06);
  text-align: center;
}

.audio-art {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 24px;
  background: linear-gradient(135deg, #34d399, #059669);
  color: #fff;
  box-shadow: 0 12px 32px rgb(16 185 129 / 0.35);
}

.audio-art svg { width: 42px; height: 42px; }
.audio-art--file { background: linear-gradient(135deg, #a3a39c, #6b6b65); box-shadow: none; }
.audio-name { margin: 0; font-weight: 600; word-break: break-all; }
.audio-card audio { width: 100%; }

/* ---------- mobile ---------- */

@media (max-width: 860px) {
  .topbar { flex-direction: column; align-items: stretch; padding: 10px 16px; gap: 10px; }
  .topbar .brand > span:last-child { display: none; }
  .toolbar { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .content { padding: 16px 16px 8px; }
  .grid--files { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .grid--folders { grid-template-columns: 1fr; }
  .viewer-stage { padding: 0 8px 16px; }
  .viewer-nav { top: auto; bottom: 18px; transform: none; }
}
