:root {
  --bg: #0b0d12;
  --bg-2: #10131a;
  --panel: #151926;
  --panel-2: #1c2233;
  --border: #262d40;
  --border-hi: #36405c;
  --text: #e8eaf0;
  --muted: #8a93a6;
  --accent: #7c8cff;
  --accent-2: #a06bff;
  --accent-soft: rgba(124, 140, 255, .14);
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(124, 140, 255, .10), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(160, 107, 255, .10), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* ============ Login ============ */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.2rem; }
.login-card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.2rem 2rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: .55rem;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: .3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-card p { margin: 0 0 1rem; }
.login-card label { font-size: .82rem; color: var(--muted); margin-top: .4rem; }
.login-card input[type=password] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .8rem .9rem;
  color: var(--text);
  font-size: 1rem;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button {
  margin-top: 1.1rem;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #0b0d12;
  border: none;
  border-radius: 10px;
  padding: .8rem;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
.login-card button:hover { filter: brightness(1.08); }
.login-card button:active { transform: translateY(1px); }
.alert {
  background: rgba(255, 107, 107, .12);
  border: 1px solid var(--danger);
  color: #ffb4b4;
  padding: .6rem .8rem;
  border-radius: 10px;
  font-size: .9rem;
}

/* ============ Topbar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(13, 16, 24, .82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.bar-main {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .65rem .9rem;
  max-width: 1280px;
  margin: 0 auto;
}
.brand { font-weight: 800; font-size: 1.1rem; color: var(--text); white-space: nowrap; }
.brand span { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.search { flex: 1; display: flex; min-width: 0; }
.search input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 11px 0 0 11px;
  padding: .6rem .9rem;
  color: var(--text);
  font-size: .95rem;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 11px 11px 0;
  padding: 0 .9rem;
  cursor: pointer;
  font-size: 1rem;
}
.search button:hover { background: var(--border); }

.logout button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: .55rem .8rem;
  cursor: pointer;
  font-size: .85rem;
  white-space: nowrap;
}
.logout button:hover { color: var(--text); border-color: var(--border-hi); }

.cats {
  display: flex;
  gap: .35rem;
  padding: .15rem .9rem .6rem;
  max-width: 1280px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: thin;
}
.cats::-webkit-scrollbar { height: 5px; }
.cats::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }
.cats a {
  padding: .35rem .8rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: .85rem;
  white-space: nowrap;
  border: 1px solid transparent;
}
.cats a:hover { background: var(--panel); text-decoration: none; color: var(--text); }
.cats a.active { background: var(--accent-soft); color: var(--text); border-color: var(--border-hi); }

/* ============ Content ============ */
.content { padding: 1.1rem 1rem 3rem; max-width: 1280px; margin: 0 auto; }

.breadcrumb { margin-bottom: 1.1rem; font-size: .95rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; }
.breadcrumb .sep { margin: 0 .35rem; opacity: .5; }
.breadcrumb .current { color: var(--text); font-weight: 600; }
.breadcrumb .count { margin-left: auto; font-size: .82rem; opacity: .8; }

.page-head { display: flex; align-items: baseline; gap: .7rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 1.3rem; }
.count {
  font-size: .78rem; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border);
  padding: .1rem .5rem; border-radius: 999px;
}
.empty { padding: 2.5rem 0; text-align: center; }
.section {
  margin: 1.4rem 0 .7rem;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 700;
}
.section:first-of-type { margin-top: .4rem; }

/* ============ Barre d'actions (upload / mkdir) ============ */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: center;
  margin-bottom: 1.1rem;
  padding: .7rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.upload-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; flex: 1; min-width: 0; }
.upload-form input[type=file] {
  flex: 1;
  min-width: 140px;
  font-size: .82rem;
  color: var(--muted);
  background: var(--bg-2);
  border: 1px dashed var(--border-hi);
  border-radius: 9px;
  padding: .45rem .5rem;
}
.upload-form input[type=file]::file-selector-button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: .3rem .6rem; margin-right: .6rem; cursor: pointer;
}
.mkdir { position: relative; }
.mkdir[open] > summary { border-color: var(--accent); }
.mkdir > form {
  position: absolute;
  z-index: 6;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  gap: .4rem;
  background: var(--panel-2);
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  padding: .5rem;
  box-shadow: var(--shadow);
  width: max(240px, 100%);
}
.mkdir input[type=text] {
  flex: 1; min-width: 0;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .55rem; color: var(--text); font-size: .88rem;
}
.mkdir input:focus { outline: none; border-color: var(--accent); }
.mkdir form button {
  background: var(--accent); color: #0b0d12; border: none;
  border-radius: 8px; padding: 0 .8rem; font-weight: 700; cursor: pointer;
}

/* Suppression */
.act.danger { color: #ff8f8f; }
.act.danger:hover { border-color: var(--danger); color: #ffb4b4; }
.del[open] > summary { border-color: var(--danger); color: var(--danger); }
.del .ren-form { width: max(200px, 100%); align-items: center; }
.del .confirm { font-size: .8rem; color: var(--muted); flex: 1; }
.danger-btn {
  background: var(--danger) !important; color: #1a0606 !important;
  border: none; border-radius: 7px; padding: .25rem .7rem;
  font-weight: 700; cursor: pointer; white-space: nowrap;
}

/* ============ Grid de cartes ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: .6rem;
}
.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s, transform .08s, background .15s;
  display: flex;
  flex-direction: column;
}
.card:hover { border-color: var(--border-hi); background: var(--panel-2); }
.card-open {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .75rem .8rem;
  color: var(--text);
  min-width: 0;
}
.card-open:hover { text-decoration: none; }
.ic { font-size: 1.35rem; line-height: 1; flex-shrink: 0; }
.cat-folder .ic { filter: drop-shadow(0 2px 6px rgba(124, 140, 255, .4)); }
.nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.mt { font-size: .74rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }

.card-actions {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: 0 .55rem .55rem;
  margin-top: auto;
}
.act {
  font-size: .76rem;
  color: var(--muted);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .25rem .5rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.act:hover { color: var(--text); border-color: var(--border-hi); text-decoration: none; }
summary.act::-webkit-details-marker { display: none; }

/* Renommage (popover via <details>) */
.ren { position: relative; }
.ren[open] > summary { color: var(--accent); border-color: var(--accent); }
.ren-form {
  position: absolute;
  z-index: 5;
  bottom: calc(100% + 6px);
  right: 0;
  display: flex;
  gap: .3rem;
  background: var(--panel-2);
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  padding: .4rem;
  box-shadow: var(--shadow);
  width: max(220px, 100%);
}
.ren-form input[type=text] {
  flex: 1; min-width: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .4rem .5rem;
  color: var(--text);
  font-size: .85rem;
}
.ren-form input:focus { outline: none; border-color: var(--accent); }
.ren-form button {
  background: var(--accent); color: #0b0d12; border: none;
  border-radius: 7px; padding: 0 .7rem; font-weight: 700; cursor: pointer;
}

/* ============ Viewer ============ */
.viewer .view-actions { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: flex-start; }
.btn {
  display: inline-block;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #0b0d12;
  padding: .55rem .9rem;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost { background: var(--panel); color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.btn.ghost:hover { border-color: var(--border-hi); filter: none; }
.ren.inline { position: relative; }
.ren.inline .ren-form { left: 0; right: auto; }

.media { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.media img, .media video { max-width: 100%; max-height: 78vh; display: block; margin: 0 auto; border-radius: 10px; }
.media audio { width: 100%; }
.media .pdf { width: 100%; height: 80vh; border: none; border-radius: 10px; background: #fff; }
.media .text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .86rem;
  color: #d4d9e3;
  max-height: 78vh;
  overflow: auto;
}

/* ============ Mobile ============ */
@media (max-width: 680px) {
  .brand span { display: none; }
  .bar-main { gap: .5rem; padding: .55rem .7rem; }
  .logout button { padding: .5rem .6rem; }
  .content { padding: 1rem .8rem 3rem; }
  .grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 440px) {
  .grid { grid-template-columns: 1fr; }
  .nm { white-space: normal; }
}
