:root {
  --bg-1: #0b1026;
  --bg-2: #1b1f4b;
  --bg-3: #3a1c5c;
  --text: #f4f5fb;
  --muted: rgba(244, 245, 251, 0.62);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-strong: rgba(18, 21, 48, 0.82);
  --border: rgba(255, 255, 255, 0.14);
  --accent: #7c8cff;
  --accent-2: #a855f7;
  --danger: #ff5d6c;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 15% 10%, rgba(124, 140, 255, 0.35), transparent 60%),
    radial-gradient(900px 600px at 90% 85%, rgba(168, 85, 247, 0.35), transparent 60%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ───────── Formulaires (connexion, mot de passe, fenêtres) ───────── */

.center {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.card {
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  background: var(--glass-strong);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(22px);
}

.brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; text-align: center; }
.brand img { width: 64px; height: 64px; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: 0.2px; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.field input[type="email"],
.field input[type="password"],
.field input[type="text"],
.field input[type="url"] {
  width: 100%;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.25); }
.hint { margin: -6px 0 14px; font-size: 12px; color: var(--muted); }

.btn {
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.ghost { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--border); }

.error {
  margin: 0 0 14px;
  padding: 10px 12px;
  font-size: 13.5px;
  color: #ffd9dd;
  background: rgba(255, 93, 108, 0.14);
  border: 1px solid rgba(255, 93, 108, 0.4);
  border-radius: 10px;
}
.notice {
  margin: 0 0 18px;
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.45;
  background: rgba(124, 140, 255, 0.14);
  border: 1px solid rgba(124, 140, 255, 0.4);
  border-radius: 10px;
}
.link { display: block; margin-top: 14px; text-align: center; font-size: 13.5px; color: var(--muted); }

/* ───────────────────────── Barre du haut ───────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 14px;
  background: rgba(10, 12, 30, 0.55);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}
.topbar .logo { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 15px; white-space: nowrap; }
.topbar .logo img { width: 22px; height: 22px; }
.topbar .spacer { flex: 1; }
.topbar .clock { font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; margin-right: 4px; }

.tabs { display: flex; gap: 4px; margin-left: 12px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  height: 32px;
  padding: 0 14px;
  font-size: 13.5px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
}
.tab:hover { color: var(--text); background: var(--glass); }
.tab.active { color: var(--text); background: rgba(255, 255, 255, 0.14); border-color: var(--border); font-weight: 600; }
.tab.drop, .item.folder.drop .icon { outline: 2px solid var(--accent); outline-offset: 2px; }
.tab.drop { color: var(--text); background: rgba(124, 140, 255, 0.3); }

.tb-btn {
  flex: none;
  height: 32px;
  padding: 0 12px;
  font-size: 13.5px;
  white-space: nowrap;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
}
.tb-btn:hover, .tb-btn[aria-expanded="true"], .tb-btn.active { background: var(--glass); border-color: var(--border); }
.tb-btn.active { color: #ffd166; }
.tb-btn.danger-text { color: #ff9aa4; }
.tb-btn:disabled { opacity: 0.5; }

.menu-wrap { position: relative; flex: none; }
.menu {
  position: absolute;
  right: 0;
  top: 40px;
  min-width: 230px;
  padding: 6px;
  background: var(--glass-strong);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(22px);
}
.menu .who { padding: 8px 10px 10px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 6px; overflow-wrap: anywhere; }
.menu hr { margin: 6px 4px; border: 0; border-top: 1px solid var(--border); }
.menu a, .menu button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  text-align: left;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: 9px;
}
.menu a:hover, .menu button:hover { background: var(--glass); }

/* ───────────────────────── Bureau ───────────────────────── */

.desktop-wrap { overflow-x: auto; }
.desktop { position: relative; min-height: calc(100vh - 47px); }
.desktop .item { position: absolute; }

/* Petit écran ou page vide : les éléments s'enchaînent dans une grille. */
.desktop.flow, .folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 14px 6px;
  align-content: start;
  justify-items: center;
}
.desktop.flow { padding: 24px 14px 60px; }
.desktop.flow .item, .folder-grid .item { position: relative; }
.desktop.flow .widget { grid-column: 1 / -1; justify-self: stretch; width: auto; height: auto; }
.empty { grid-column: 1 / -1; justify-self: start; margin: 8px 10px; font-size: 14px; color: var(--muted); }

.item { user-select: none; -webkit-user-select: none; }
.item.app, .item.folder {
  width: 104px;
  height: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 4px 0;
  color: var(--text);
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: 16px;
  transition: background 0.15s;
}
.item.app:hover, .item.folder:hover, .item.app:focus-visible, .item.folder:focus-visible { background: var(--glass); outline: none; }
.item .icon {
  flex: none;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s;
}
.item:hover .icon { transform: translateY(-2px) scale(1.03); }
.item .icon img { width: 100%; height: 100%; object-fit: cover; }
.item .icon img.small { width: 60%; height: 60%; object-fit: contain; }
.item .label {
  max-width: 100%;
  font-size: 13px;
  line-height: 1.25;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.item .folder-icon {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 5px;
  padding: 9px;
  place-items: stretch;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(10px);
}
.item .folder-icon img { border-radius: 6px; background: rgba(255, 255, 255, 0.92); min-width: 0; min-height: 0; }

.item.add .icon {
  background: rgba(255, 255, 255, 0.06);
  border: 2px dashed rgba(255, 255, 255, 0.4);
  box-shadow: none;
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
  color: rgba(255, 255, 255, 0.85);
}
.item.add:hover .icon { border-color: #fff; color: #fff; }
.item.add .label { color: var(--muted); }

.item.widget {
  display: flex;
  margin: 0;
  overflow: hidden;
  background: rgba(18, 21, 48, 0.6);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(16px);
}
.widget-body { flex: 1; min-width: 0; padding: 16px 18px; overflow: auto; }
.item.widget h3 { margin: 0 0 8px; font-size: 15px; }
.item.widget p { margin: 0; font-size: 14px; line-height: 1.5; color: rgba(244, 245, 251, 0.86); white-space: pre-wrap; overflow-wrap: anywhere; }
.item.widget .resize {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  border-right: 2px solid rgba(255, 255, 255, 0.5);
  border-bottom: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 0 0 9px 0;
  opacity: 0;
  touch-action: none;
}
.item.widget:hover .resize, .editing .item.widget .resize { opacity: 1; }

.item.dragging { z-index: 4; opacity: 0.85; cursor: grabbing; transition: none; }
.item.dragging .icon { transform: scale(1.08); }
.editing .item { touch-action: none; }
.editing .item:not(.add) { cursor: pointer; }
.editing .item:not(.add):not(.dragging) .icon { animation: wiggle 0.35s ease-in-out infinite alternate; }
.editing .item.widget { outline: 1px dashed rgba(255, 255, 255, 0.5); outline-offset: 2px; }
@keyframes wiggle { from { transform: rotate(-1.5deg); } to { transform: rotate(1.5deg); } }
@media (prefers-reduced-motion: reduce) { .editing .item .icon { animation: none !important; } }

/* ───────────────────────── Fenêtres ───────────────────────── */

dialog {
  width: calc(100% - 32px);
  max-width: 420px;
  max-height: calc(100% - 32px);
  padding: 26px 24px;
  color: var(--text);
  background: var(--glass-strong);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(22px);
}
dialog.wide { max-width: 560px; }
dialog::backdrop { background: rgba(5, 6, 18, 0.55); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 6px; font-size: 19px; }
dialog p.sub { margin: 0 0 18px; font-size: 13.5px; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
dialog h2 + div { margin-top: 14px; }
.actions { display: flex; gap: 10px; margin-top: 10px; }
.btn.danger { flex: 0 0 auto; width: auto; color: #ffd9dd; background: rgba(255, 93, 108, 0.16); border: 1px solid rgba(255, 93, 108, 0.45); }

.field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: inherit;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}
.field textarea { resize: vertical; min-height: 110px; line-height: 1.45; }
.field select option { color: #111; }
.field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.25); }
.field input.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.5px; }

.group-title { margin: 18px 0 10px; font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; padding: 7px 2px; font-size: 14px; overflow-wrap: anywhere; }
.check input { flex: none; width: 17px; height: 17px; accent-color: var(--accent); }
.checks { margin-bottom: 14px; }
.checks.off { opacity: 0.45; }
.hint { margin: 6px 0 6px; }

.picker { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.picker .preview {
  flex: none;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-size: 26px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: var(--radius);
}
.picker .preview.filled { background: rgba(255, 255, 255, 0.92); border: 0; }
.picker .preview img { width: 100%; height: 100%; object-fit: cover; }
.picker-buttons { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.picker-buttons .btn { padding: 9px 12px; font-size: 14px; }

.user-list { margin-bottom: 6px; }
.user-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.user-info { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; }
.user-info strong { font-size: 14px; font-weight: 600; }
.user-info span { font-size: 12.5px; color: var(--muted); }
.user-actions { display: flex; flex-wrap: wrap; gap: 2px; }
.user-actions .tb-btn { padding: 0 9px; font-size: 13px; }

dialog.folder-window { max-width: 520px; }
.folder-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.folder-head h2 { margin: 0; overflow-wrap: anywhere; }
.folder-grid { min-height: 120px; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 6px 10px; }
  .topbar .logo span, .topbar .clock { display: none; }
  .tabs { order: 10; flex: 0 0 100%; margin: 0; padding-bottom: 2px; }
  .tabs:empty { display: none; }
  .desktop { min-height: 0; }
  .actions { flex-wrap: wrap; }
}
