/* =============================================================================
   Portail SPYGEN — styles
============================================================================= */
:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: light;
  --accent: #0d7d7a;
  --accent-2: #12a39d;
  --accent-ink: #0a5f5d;
  --ink: #132422;
  --ink-2: #4a5a5b;
  --ink-3: #7d8c8d;
  --surface: #ffffff;
  --surface-2: #f0f4f4;
  --surface-3: #f7fafa;
  --line: #e2e9e8;
  --line-2: #cdd8d7;
  --radius: 16px;

  --d-labo: #059669;
  --d-client: #ea6a0c;
  --d-finance: #7c3aed;
  --d-transverse: #0d7d7a;

  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15,30,29,.06), 0 6px 18px -10px rgba(15,30,29,.18);
  --shadow: 0 10px 40px -12px rgba(15,30,29,.35);
  --shadow-lg: 0 24px 70px -18px rgba(4,16,18,.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: #05161a;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- Boutons ---------- */
.btn {
  font: inherit; font-size: .9rem; font-weight: 600;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  padding: 8px 15px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); border-color: transparent; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }

/* =============================================================================
   ÉCRAN DE CONNEXION (Azure AD simulé)
============================================================================= */
#loginView {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 28px;
  background:
    radial-gradient(1100px 760px at 15% 10%, #0d4a47 0%, transparent 60%),
    radial-gradient(900px 680px at 88% 92%, #0a3346 0%, transparent 55%),
    linear-gradient(160deg, #072423 0%, #04161b 100%);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  padding: 34px 32px 26px;
}
.brand {
  display: inline-flex; align-items: center; gap: 11px;
  font-weight: 800; letter-spacing: -.02em; font-size: 1.15rem; color: var(--ink);
}
.brand .mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  color: #fff; display: grid; place-items: center; font-size: 1.1rem;
  box-shadow: 0 4px 14px -4px var(--accent);
}
.login-card h1 { font-size: 1.5rem; letter-spacing: -.02em; margin: 22px 0 6px; }
.login-card .sub { color: var(--ink-2); font-size: .92rem; margin: 0 0 22px; }
.sim-badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .72rem; font-weight: 600; color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  padding: 3px 10px; border-radius: 999px; margin-bottom: 20px;
}
.ms-btn {
  width: 100%; justify-content: center;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  padding: 11px; border-radius: 10px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 10px; font-size: .95rem;
}
.ms-btn:hover { background: var(--surface-2); }
.ms-logo { width: 18px; height: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 1.5px; }
.ms-logo i { display: block; }
.ms-logo i:nth-child(1) { background: #f25022; }
.ms-logo i:nth-child(2) { background: #7fba00; }
.ms-logo i:nth-child(3) { background: #00a4ef; }
.ms-logo i:nth-child(4) { background: #ffb900; }

.accounts { margin-top: 18px; display: flex; flex-direction: column; gap: 4px; }
.accounts .accounts-h {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3); padding: 6px 4px;
}
.account {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 10px; border-radius: 11px; border: 1px solid transparent;
  background: none; cursor: pointer; text-align: left;
}
.account:hover { background: var(--surface-2); border-color: var(--line); }
.account:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .85rem;
}
.account .who { min-width: 0; }
.account .who .n { font-weight: 600; font-size: .92rem; }
.account .who .t { font-size: .78rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account .adm { margin-left: auto; font-size: .64rem; font-weight: 700; letter-spacing: .06em; color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 2px 7px; border-radius: 6px; }

/* =============================================================================
   BUREAU (desktop + wallpaper)
============================================================================= */
#desktopView { min-height: 100%; display: flex; flex-direction: column; position: relative; }
.desk-bg {
  position: fixed; inset: 0; z-index: 0;
  background-size: cover; background-position: center;
}
.desk { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100vh; }
.desk[data-theme="dark"] {
  --desk-fg: #eaf5f4; --desk-fg-2: rgba(234,245,244,.72);
  --tile-bg: rgba(255,255,255,.10); --tile-bg-hover: rgba(255,255,255,.18);
  --tile-border: rgba(255,255,255,.20); --tile-fg: #ffffff; --tile-sub: rgba(255,255,255,.66);
  --bar-bg: rgba(9,20,20,.46); --bar-border: rgba(255,255,255,.12); --bar-fg: #eef7f6;
  --pop-bg: rgba(16,28,28,.92); --pop-border: rgba(255,255,255,.14); --pop-fg: #eef7f6;
}
.desk[data-theme="light"] {
  --desk-fg: #10302e; --desk-fg-2: rgba(16,48,46,.66);
  --tile-bg: rgba(255,255,255,.74); --tile-bg-hover: rgba(255,255,255,.94);
  --tile-border: rgba(9,30,29,.08); --tile-fg: #12302e; --tile-sub: #566a69;
  --bar-bg: rgba(255,255,255,.62); --bar-border: rgba(9,30,29,.08); --bar-fg: #12302e;
  --pop-bg: rgba(255,255,255,.96); --pop-border: rgba(9,30,29,.10); --pop-fg: #12302e;
}

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 9px 20px;
  background: var(--bar-bg); color: var(--bar-fg);
  border-bottom: 1px solid var(--bar-border);
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
}
.topbar .brand { color: var(--bar-fg); font-size: .98rem; }
.topbar .spacer { flex: 1; }
.greet-inline { color: var(--bar-fg); font-size: .86rem; opacity: .9; margin-right: 4px; white-space: nowrap; }
.greet-inline b { font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) { .greet-inline { display: none; } }
.iconbtn {
  border: 1px solid var(--bar-border); background: transparent; color: var(--bar-fg);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s;
}
.iconbtn:hover { background: color-mix(in srgb, var(--bar-fg) 12%, transparent); }
.iconbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 5px 6px 5px 5px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--bar-border); background: transparent; color: var(--bar-fg);
}
.user-chip:hover { background: color-mix(in srgb, var(--bar-fg) 10%, transparent); }
.user-chip .avatar { width: 30px; height: 30px; font-size: .74rem; }
.user-chip .u-name { font-weight: 600; font-size: .86rem; padding-right: 4px; }
@media (max-width: 620px) { .user-chip .u-name { display: none; } }

/* desktop content : centré, tient sur une page */
.desk-main {
  flex: 1; min-height: 0;
  display: flex; overflow: auto;
  padding: 10px 24px; width: 100%; max-width: 1800px; margin: 0 auto;
}

.group-block { margin-bottom: 30px; }
.group-head {
  display: flex; align-items: center; gap: 10px; margin: 0 2px 14px;
  color: var(--desk-fg);
}
.group-head h3 { font-size: 1.02rem; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.group-head .gcount {
  font-family: var(--font-mono); font-size: .72rem; color: var(--desk-fg-2);
  border: 1px solid var(--tile-border); border-radius: 999px; padding: 1px 8px;
}
.group-head .gline { flex: 1; height: 1px; background: var(--tile-border); }

.desk-inner { margin: auto; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 15px; }
.launch {
  display: flex; flex-wrap: wrap;
  justify-content: center; align-items: flex-start;
  gap: 13px 22px; width: 100%;
}
.tile.tile-propose {
  width: auto; min-width: 180px; flex-direction: row; gap: 10px; justify-content: center;
  border: 2px dashed var(--tile-border); background: var(--tile-bg);
}
.tile.tile-propose:hover { border-color: var(--accent-2); background: var(--tile-bg-hover); }
.tile.tile-propose .ic-propose { background: var(--accent); color: #fff; }
.tile.tile-propose .t-name { font-size: .92rem; }
.tile.tile-propose > div:not(.ic) { align-items: flex-start; text-align: left; }
.dom-block {
  display: flex; flex-direction: column; gap: 6px;
  width: fit-content; max-width: 100%; flex: 0 0 auto;
}
.dom-title {
  text-align: center; font-size: .72rem; font-weight: 700;
  letter-spacing: .11em; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  opacity: .95;
}
.dom-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.tiles {
  display: flex; flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.tile {
  position: relative;
  width: 100px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 5px;
  padding: 10px 8px 9px;
  background: var(--tile-bg); color: var(--tile-fg);
  border: 1px solid var(--tile-border); border-radius: var(--radius);
  cursor: pointer; text-decoration: none;
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  transition: transform .14s ease, background .15s ease, box-shadow .15s ease;
}
.tile:hover { transform: translateY(-3px); background: var(--tile-bg-hover); box-shadow: 0 16px 40px -16px rgba(0,0,0,.5); }
.tile:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.tile .ic {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: .88rem; letter-spacing: -.02em;
  box-shadow: 0 8px 20px -8px rgba(0,0,0,.5);
}
.tile .ic.emoji { font-size: 1.15rem; }
.tile .ic.ic-logo { background: transparent; padding: 0; overflow: hidden; }
.tile .ic.ic-logo svg { width: 100%; height: 100%; display: block; }
.tile .t-name { font-weight: 600; font-size: .78rem; line-height: 1.18; }
.tile .t-tech {
  font-family: var(--font-mono); font-size: .6rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--tile-sub);
}
.tile .t-missing {
  position: absolute; top: 9px; right: 9px;
  width: 9px; height: 9px; border-radius: 50%;
  background: #f59e0b; box-shadow: 0 0 0 3px color-mix(in srgb, #f59e0b 30%, transparent);
}
.tile.no-url { cursor: default; }
.tile.no-url:hover { transform: none; }

.empty-desk { color: var(--desk-fg-2); padding: 40px 4px; }

/* wallpaper popover + user menu */
/* Les popovers sont rendus dans <body> (hors .desk) : style clair fixe, toujours lisible. */
.pop {
  position: absolute; z-index: 30;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
}
.pop h4 { margin: 2px 4px 10px; font-size: .7rem; font-family: var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.wp-grid { display: grid; grid-template-columns: repeat(3, 84px); gap: 9px; }
.wp-thumb {
  height: 56px; border-radius: 10px; cursor: pointer; position: relative;
  border: 2px solid transparent; overflow: hidden; padding: 0;
  background-size: cover; background-position: center;
}
.wp-thumb span {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: .62rem; font-weight: 600;
  color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.55)); padding: 8px 5px 3px; text-align: center;
}
.wp-thumb[aria-pressed="true"] { border-color: var(--accent-2); box-shadow: 0 0 0 2px var(--accent-2); }

.menu { min-width: 210px; padding: 8px; }
.menu .m-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu .m-head .n { font-weight: 700; }
.menu .m-head .e { font-size: .78rem; color: var(--ink-3); }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: none; color: var(--ink); font: inherit; font-size: .88rem;
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }

/* =============================================================================
   BACK-OFFICE (admin)
============================================================================= */
#adminView { min-height: 100%; background: var(--surface-3); }
.admin-top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.admin-top .brand { font-size: 1rem; }
.admin-top .title { font-weight: 700; letter-spacing: -.01em; }
.admin-top .spacer { flex: 1; }
.admin-wrap { max-width: 1080px; margin: 0 auto; padding: 22px 24px 80px; }
.tabs { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.tab {
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  padding: 8px 15px; border-radius: 999px;
}
.tab[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.panel-intro { color: var(--ink-2); font-size: .9rem; margin: 0 0 18px; max-width: 80ch; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-sm); padding: 16px; margin-bottom: 12px;
}
.card.row-app { display: grid; grid-template-columns: 44px 1.4fr 1fr 1.2fr 1.1fr auto; gap: 10px; align-items: center; }
@media (max-width: 860px) { .card.row-app { grid-template-columns: 44px 1fr 1fr; } }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: .72rem; color: var(--ink-3); }
label.field span { font-family: var(--font-mono); letter-spacing: .06em; text-transform: uppercase; }
input.inp, select.inp {
  font: inherit; font-size: .88rem; color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 9px; background: var(--surface); width: 100%;
}
input.inp:focus, select.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.inp.url-empty { border-color: color-mix(in srgb, #f59e0b 55%, transparent); background: color-mix(in srgb, #f59e0b 8%, transparent); }

.chk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 14px; margin-top: 6px; }
label.chk { display: flex; align-items: center; gap: 8px; font-size: .86rem; color: var(--ink); cursor: pointer; padding: 3px 0; }
label.chk input { accent-color: var(--accent); width: 16px; height: 16px; }
.card h3 { margin: 0 0 4px; font-size: 1.02rem; letter-spacing: -.01em; }
.card .muted { color: var(--ink-3); font-size: .8rem; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head .spacer { flex: 1; }

.ic-mini { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .95rem; }
.ic-mini.emoji { font-size: 1.3rem; }

.section-actions { display: flex; gap: 10px; margin: 6px 0 24px; }

.pill-dom { font-size: .7rem; font-weight: 600; padding: 2px 9px; border-radius: 6px; display: inline-flex; align-items: center; gap: 5px; }

.dom-admin-row { display: flex; align-items: center; gap: 12px; }
.dom-color { width: 42px; height: 42px; flex: none; border: 1px solid var(--line-2); border-radius: 9px; padding: 2px; background: var(--surface); cursor: pointer; }
.dom-color::-webkit-color-swatch { border: none; border-radius: 6px; }
.dom-color::-moz-color-swatch { border: none; border-radius: 6px; }
.dom-actions { display: flex; gap: 6px; margin-left: auto; }
.dom-actions .btn-sm { padding: 6px 9px; }

/* Modal (proposer une application) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px;
  background: rgba(8,16,15,.5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h3 { margin: 0; font-size: 1.2rem; letter-spacing: -.01em; }
.modal-sub { margin: 0 0 6px; color: var(--ink-2); font-size: .9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.modal-card.modal-wide { max-width: 780px; }
.sg-modal { display: flex; gap: 24px; }
.sg-form { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.sg-form h3 { margin: 0; font-size: 1.2rem; letter-spacing: -.01em; }
.sg-list-pane { width: 290px; flex: none; border-left: 1px solid var(--line); padding-left: 22px; display: flex; flex-direction: column; }
.sg-list-pane h4 { margin: 2px 0 12px; font-family: var(--font-mono); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.sg-existing { overflow-y: auto; max-height: 48vh; display: flex; flex-direction: column; gap: 10px; }
.sg-item { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.sg-item-name { font-weight: 600; font-size: .9rem; }
.sg-item-url { display: block; font-size: .78rem; color: var(--accent-ink); word-break: break-all; text-decoration: none; }
.sg-item-url:hover { text-decoration: underline; }
.sg-item-by { font-size: .74rem; color: var(--ink-3); margin-top: 2px; }
@media (max-width: 640px) {
  .sg-modal { flex-direction: column; gap: 16px; }
  .sg-list-pane { width: auto; border-left: none; border-top: 1px solid var(--line); padding-left: 0; padding-top: 16px; }
  .sg-existing { max-height: 30vh; }
}

/* Badge de l'onglet Suggestions */
.tab-badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700;
  font-family: var(--font-mono); margin-left: 4px; vertical-align: middle;
}
.tab[aria-pressed="true"] .tab-badge { background: #fff; color: var(--ink); }

/* Lignes de suggestions */
.sg-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.sg-info { flex: 1; min-width: 220px; }
.sg-info h3 { margin: 0 0 2px; font-size: 1rem; }
.sg-actions { display: flex; gap: 8px; margin-left: auto; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 11px;
  font-size: .88rem; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
