/* Panneau bots - identité visuelle propre, sans rapport avec le MDT.
   Parti pris : application pleine fenêtre, barre latérale fixe, zone de contenu qui défile seule.
   Palette ardoise très sombre + un accent indigo unique, décliné en opacités. */

@layer reset, base, layout, components;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { height: 100%; }
  body, h1, h2, h3, p, figure { margin: 0; }
  button, input, textarea { font: inherit; color: inherit; }
  /* Indispensable : toute règle de classe posant un `display` (ici .overlay) l'emporterait sur le
     display:none par défaut de [hidden], et l'élément resterait visible malgré l'attribut. */
  [hidden] { display: none !important; }
}

@layer base {
  :root {
    --bg:          #08090b;
    --surface:     #0f1114;
    --surface-2:   #15181c;
    --surface-3:   #1c2026;
    --border:      #1e2228;
    --border-2:    #2b3038;

    --text:        #f2f4f7;
    --text-2:      #99a1ad;
    --text-3:      #626b77;

    --accent-rgb:  109 122 255;
    --accent:      rgb(var(--accent-rgb));
    --ok-rgb:      62 207 142;
    --warn-rgb:    245 166 35;
    --danger-rgb:  255 92 92;

    --r-1: 6px;
    --r-2: 10px;
    --r-3: 14px;

    --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-2: 0 12px 40px -12px rgb(0 0 0 / .7);

    --sidebar: 244px;
    color-scheme: dark;
  }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  ::selection { background: rgb(var(--accent-rgb) / .3); }

  /* Les chiffres qui changent toutes les 5 secondes ne doivent pas faire sautiller la mise en page. */
  .num { font-variant-numeric: tabular-nums; }

  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; border: 3px solid var(--bg); }
  ::-webkit-scrollbar-thumb:hover { background: #3a414b; }
}

@layer layout {
  .shell {
    height: 100%;
    display: grid;
    grid-template-columns: var(--sidebar) 1fr;
  }

  /* ── barre latérale ─────────────────────────────────────────────── */
  .side {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  /* Pas de logo : uniquement le nom, posé comme un titre. Les pastilles décoratives successives
     (carré dégradé, puis aplat bordé) faisaient toutes ornement sans rien apporter. */
  .brand {
    display: flex; align-items: center;
    height: 62px; padding: 0 18px;
    border-bottom: 1px solid var(--border);
  }
  .brand b { font-size: 15px; font-weight: 600; letter-spacing: -.02em; }

  .side nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; }
  .navitem {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 11px; border-radius: var(--r-1);
    color: var(--text-2); font-size: 13.5px; font-weight: 500;
    background: none; border: 0; width: 100%; text-align: left; cursor: pointer;
    transition: background .12s, color .12s;
  }
  .navitem:hover { background: var(--surface-2); color: var(--text); }
  .navitem[aria-current="true"] { background: rgb(var(--accent-rgb) / .12); color: var(--text); }
  .navitem[aria-current="true"] svg { color: var(--accent); }
  .navitem svg { width: 17px; height: 17px; flex: none; }
  .navitem .count {
    margin-left: auto; font-size: 11.5px; color: var(--text-3);
    background: var(--surface-3); border-radius: 99px; padding: 1px 7px;
  }

  .side footer { padding: 14px 12px; border-top: 1px solid var(--border); }
  .hostcard {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 11px; border-radius: var(--r-2);
    background: var(--surface-2); margin-bottom: 8px;
  }
  .hostcard .dot { width: 7px; height: 7px; border-radius: 99px; background: rgb(var(--ok-rgb)); box-shadow: 0 0 0 3px rgb(var(--ok-rgb) / .16); flex: none; }
  .hostcard b { font-size: 12.5px; font-weight: 600; display: block; }
  .hostcard span { font-size: 11px; color: var(--text-3); display: block; }

  /* ── zone principale ────────────────────────────────────────────── */
  .main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

  .topbar {
    height: 62px; flex: none;
    display: flex; align-items: center; gap: 16px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: rgb(8 9 11 / .8);
    backdrop-filter: blur(8px);
  }
  .topbar h1 { font-size: 16px; font-weight: 600; letter-spacing: -.015em; }
  .topbar .spacer { flex: 1; }
  .live { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-3); }
  .live i {
    width: 6px; height: 6px; border-radius: 99px; background: rgb(var(--ok-rgb));
    animation: pulse 2.4s ease-in-out infinite;
  }
  @keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

  .scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 28px 32px 48px; }
  /* Pas de largeur maximale : un tableau de bord doit occuper l'écran. Un contenu centré à 1180 px
     laissait de larges bandes vides de chaque côté sur un écran large, ce qui donnait une page à
     moitié utilisée. */
  /* Sélecteur volontairement non direct : les sections sont imbriquées dans #view-dashboard, donc un
     `.page > section + section` ne matchait jamais et le titre « Bots » se collait aux cartes. */
  .page section + section { margin-top: 38px; }

  /* Navigation de repli, affichée uniquement quand la barre latérale disparaît. Sans elle, les
     écrans étroits n'avaient plus AUCUN moyen d'atteindre « Ajouter un bot ». */
  .topnav { display: none; gap: 6px; }
  .topnav .navitem { width: auto; padding: 7px 12px; font-size: 13px; }

  h2.title { font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: .02em; margin-bottom: 13px; }
}

@layer components {
  /* ── boutons ────────────────────────────────────────────────────── */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 34px; padding: 0 14px;
    border-radius: var(--r-1); border: 1px solid var(--border-2);
    background: var(--surface-2); color: var(--text);
    font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
    transition: background .12s, border-color .12s, transform .06s;
  }
  .btn:hover:not(:disabled) { background: var(--surface-3); border-color: #363d47; }
  .btn:active:not(:disabled) { transform: translateY(1px); }
  .btn:disabled { opacity: .45; cursor: not-allowed; }
  .btn svg { width: 15px; height: 15px; }
  .btn.sm { height: 29px; padding: 0 10px; font-size: 12.5px; }
  /* Teinte et bordure plutôt qu'aplat plein : sur des surfaces sombres bordées de cheveux, un bloc
     de couleur saturée devient l'élément le plus criard de l'écran et jure avec tout le reste. */
  .btn.primary {
    background: rgb(var(--accent-rgb) / .12);
    border-color: rgb(var(--accent-rgb) / .45);
    color: var(--accent);
  }
  .btn.primary:hover:not(:disabled) {
    background: rgb(var(--accent-rgb) / .2);
    border-color: rgb(var(--accent-rgb) / .7);
  }
  .btn.danger { color: rgb(var(--danger-rgb)); }
  .btn.danger:hover:not(:disabled) { background: rgb(var(--danger-rgb) / .12); border-color: rgb(var(--danger-rgb) / .5); }
  .btn.ghost { background: none; border-color: transparent; color: var(--text-2); }
  .btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

  /* ── cartes de statistiques ─────────────────────────────────────── */
  .metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 14px; }
  .metric {
    position: relative; overflow: hidden;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-3); padding: 17px 18px 18px;
  }
  .metric::after {
    content: ""; position: absolute; inset: 0 0 auto 0; height: 1px;
    background: linear-gradient(90deg, transparent, rgb(var(--accent-rgb) / .45), transparent);
    opacity: 0; transition: opacity .3s;
  }
  .metric:hover::after { opacity: 1; }
  .metric .head { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12px; font-weight: 500; }
  .metric .head svg { width: 15px; height: 15px; }
  .metric .value { font-size: 27px; font-weight: 600; letter-spacing: -.03em; margin-top: 9px; line-height: 1.1; }
  .metric .value small { font-size: 15px; font-weight: 500; color: var(--text-3); margin-left: 2px; }
  .metric .foot { font-size: 12px; color: var(--text-3); margin-top: 3px; }
  .gauge { height: 3px; border-radius: 99px; background: var(--surface-3); margin-top: 13px; overflow: hidden; }
  .gauge > i { display: block; height: 100%; border-radius: 99px; background: rgb(var(--accent-rgb)); transition: width .5s cubic-bezier(.4,0,.2,1); }
  .gauge.warn > i { background: rgb(var(--warn-rgb)); }
  .gauge.hot > i  { background: rgb(var(--danger-rgb)); }

  /* ── liste des bots ─────────────────────────────────────────────── */
  .list { border: 1px solid var(--border); border-radius: var(--r-3); overflow: hidden; background: var(--surface); }
  .row {
    display: flex; align-items: center; gap: 14px; padding: 14px 18px;
    border-bottom: 1px solid var(--border); transition: background .12s;
  }
  .row:last-child { border-bottom: 0; }
  .row:hover { background: var(--surface-2); }
  .avatar {
    width: 36px; height: 36px; flex: none; border-radius: var(--r-2);
    display: grid; place-items: center; font-size: 14px; font-weight: 600;
    background: var(--surface-3); color: var(--text-2); text-transform: uppercase;
  }
  .row .id { min-width: 0; flex: 1; }
  .row .id b { display: block; font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
  .row .id .meta { display: flex; align-items: center; gap: 8px; margin-top: 3px; font-size: 12px; color: var(--text-3); flex-wrap: wrap; }
  .row .id .meta span { display: inline-flex; align-items: center; gap: 5px; }
  /* Barre d'outils groupée plutôt que boutons isolés : trois boutons bordés côte à côte au bout
     d'une ligne ressemblaient à un formulaire posé là, sans lien avec la ligne. Regroupés dans un
     même cadre, ils se lisent comme les actions de CETTE ligne. */
  .row .tools {
    display: flex; align-items: center; gap: 2px; flex: none;
    padding: 3px; border-radius: 8px;
    background: var(--bg); border: 1px solid var(--border);
  }
  .row .tools .btn {
    height: 28px; border: 0; background: none; color: var(--text-2);
    box-shadow: none; font-weight: 500;
  }
  .row .tools .btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
  /* Pas d'aplat plein ici : un bloc indigo saturé au milieu d'une barre en aplats discrets se lit
     comme un élément venu d'ailleurs. La couleur seule suffit à désigner l'action principale. */
  .row .tools .btn.primary { background: none; color: var(--accent); box-shadow: none; }
  .row .tools .btn.primary:hover:not(:disabled) { background: rgb(var(--accent-rgb) / .14); color: var(--accent); }
  .row .tools .btn.danger { color: var(--text-3); padding: 0 8px; }
  .row .tools .btn.danger:hover:not(:disabled) { background: rgb(var(--danger-rgb) / .14); color: rgb(var(--danger-rgb)); }
  .row .tools .sep { width: 1px; align-self: stretch; margin: 2px 3px; background: var(--border); }

  .badge {
    display: inline-flex; align-items: center; gap: 6px;
    height: 22px; padding: 0 9px; border-radius: 99px;
    font-size: 11.5px; font-weight: 500;
    background: var(--surface-3); color: var(--text-2);
  }
  .badge i { width: 6px; height: 6px; border-radius: 99px; background: currentColor; }
  .badge.online  { background: rgb(var(--ok-rgb) / .13);     color: rgb(var(--ok-rgb)); }
  .badge.stopped { background: var(--surface-3);              color: var(--text-3); }
  .badge.errored { background: rgb(var(--danger-rgb) / .13); color: rgb(var(--danger-rgb)); }
  .badge.online i { box-shadow: 0 0 0 3px rgb(var(--ok-rgb) / .18); }

  /* ── zone de dépôt ──────────────────────────────────────────────── */
  .dropzone {
    border: 1.5px dashed var(--border-2); border-radius: var(--r-3);
    background: var(--surface); padding: 42px 24px; text-align: center;
    cursor: pointer; transition: border-color .15s, background .15s;
  }
  .dropzone:hover { border-color: #3a414b; background: var(--surface-2); }
  .dropzone.over { border-color: rgb(var(--accent-rgb)); background: rgb(var(--accent-rgb) / .07); }
  .dropzone .icon {
    width: 46px; height: 46px; margin: 0 auto 14px; border-radius: var(--r-2);
    display: grid; place-items: center; background: var(--surface-3); color: var(--text-2);
  }
  .dropzone .icon svg { width: 22px; height: 22px; }
  .dropzone b { display: block; font-size: 14.5px; font-weight: 600; margin-bottom: 4px; }
  .dropzone p { font-size: 12.5px; color: var(--text-3); }

  .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-3); padding: 20px; }
  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .grid3 { display: grid; grid-template-columns: 1fr 1fr minmax(180px, .8fr); gap: 14px; }

  /* Mention « facultatif » ou « (toi) » accolée à un libellé : même taille, poids normal, couleur
     effacée, pour qu'elle se lise comme une précision et non comme une seconde information. */
  .opt { color: var(--text-3); font-weight: 400; }

  .rolehelp { margin-top: 14px; font-size: 12px; color: var(--text-3); line-height: 1.7; }
  .rolehelp b { color: var(--text-2); font-weight: 600; }

  /* Journal d'audit : dense par nature, on le lit en balayant une colonne à la fois. D'où une
     hauteur de ligne serrée et des colonnes techniques (heure, adresse) en chasse fixe. */
  table.audit { width: 100%; border-collapse: collapse; font-size: 12.5px; }
  table.audit th {
    text-align: left; font-weight: 500; font-size: 11.5px; color: var(--text-3);
    padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
  }
  table.audit td { padding: 9px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
  table.audit tbody tr:last-child td { border-bottom: 0; }
  table.audit tbody tr:hover { background: var(--surface-2); }
  table.audit td:first-child, table.audit td:last-child { white-space: nowrap; color: var(--text-2); }
  table.audit td.ko { color: rgb(var(--danger-rgb)); }
  table.audit td.warn { color: rgb(var(--warn-rgb)); }
  table.audit td.ok { color: rgb(var(--ok-rgb)); }

  select.input {
    appearance: none;
    padding-right: 30px;
    /* Chevron dessiné en SVG inline plutôt que via une police d'icônes : la flèche native des
       navigateurs ignore la couleur du thème et ressort en clair sur fond sombre. */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2399a1ad' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 15px;
  }
  select.input option { background: var(--surface-2); color: var(--text); }

  /* Sélecteur de rôle logé dans la barre d'outils d'une ligne : il doit passer pour un contrôle de
     la ligne, pas pour un champ de formulaire posé au milieu. */
  .row .tools select.rolepick {
    height: 28px; font-size: 12.5px; padding: 0 26px 0 9px;
    background-color: transparent; border: 0; color: var(--text-2);
    border-radius: var(--r-1); cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23626b77' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 7px center; background-size: 14px;
  }
  .row .tools select.rolepick:hover:not(:disabled) { background-color: var(--surface-3); color: var(--text); }
  .row .tools select.rolepick:disabled { opacity: .5; cursor: not-allowed; }

  .field { display: flex; flex-direction: column; gap: 6px; }
  .field label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
  .field .hint { font-size: 11.5px; color: var(--text-3); }
  .input {
    height: 36px; padding: 0 12px;
    background: var(--bg); border: 1px solid var(--border-2); border-radius: var(--r-1);
    transition: border-color .12s, box-shadow .12s;
  }
  textarea.input { height: auto; padding: 10px 12px; resize: vertical; font-family: inherit; }
  .input::placeholder { color: var(--text-3); }
  .input:focus { outline: none; border-color: rgb(var(--accent-rgb) / .75); box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / .13); }

  .actions { display: flex; gap: 8px; align-items: center; }

  /* ── état vide ──────────────────────────────────────────────────── */
  .empty { text-align: center; padding: 54px 24px; }
  .empty .icon { width: 44px; height: 44px; margin: 0 auto 14px; border-radius: var(--r-2); display: grid; place-items: center; background: var(--surface-2); color: var(--text-3); }
  .empty b { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
  .empty p { font-size: 12.5px; color: var(--text-3); }

  /* ── fenêtre modale ─────────────────────────────────────────────── */
  .overlay {
    position: fixed; inset: 0; z-index: 60;
    background: rgb(4 5 7 / .74); backdrop-filter: blur(3px);
    display: grid; place-items: center; padding: 26px;
    animation: fade .16s ease-out;
  }
  @keyframes fade { from { opacity: 0 } }
  .dialog {
    width: min(940px, 100%); max-height: 84vh;
    display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border-2);
    border-radius: var(--r-3); box-shadow: var(--shadow-2);
    animation: rise .2s cubic-bezier(.2,.8,.3,1);
  }
  @keyframes rise { from { transform: translateY(10px); opacity: .4 } }
  .dialog > header { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
  .dialog > header h3 { font-size: 14px; font-weight: 600; }
  .dialog > header .spacer { flex: 1; }
  .dialog > .body { padding: 16px 18px; overflow: auto; min-height: 0; }

  .console {
    margin: 0; padding: 14px 15px; border-radius: var(--r-2);
    background: #050608; border: 1px solid var(--border);
    font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
    font-size: 12px; line-height: 1.65;
    white-space: pre-wrap; word-break: break-word;
    max-height: 62vh; overflow: auto; color: #c8cfd8;
  }
  .console .err { color: rgb(var(--danger-rgb)); }

  .note { border-radius: var(--r-1); padding: 9px 12px; font-size: 12.5px; }
  .note.error { background: rgb(var(--danger-rgb) / .1); border: 1px solid rgb(var(--danger-rgb) / .35); color: rgb(var(--danger-rgb)); }
  .note.ok    { background: rgb(var(--ok-rgb) / .1);     border: 1px solid rgb(var(--ok-rgb) / .35);     color: rgb(var(--ok-rgb)); }

  /* ── pages d'authentification ───────────────────────────────────── */
  .auth {
    min-height: 100%; display: grid; place-items: center; padding: 24px;
    background:
      radial-gradient(680px 420px at 50% -8%, rgb(var(--accent-rgb) / .13), transparent 70%),
      var(--bg);
  }
  .authcard {
    width: min(392px, 100%); background: var(--surface);
    border: 1px solid var(--border-2); border-radius: var(--r-3);
    padding: 30px; box-shadow: var(--shadow-2);
  }
  .authcard h1 { font-size: 19px; font-weight: 600; letter-spacing: -.02em; }
  .authcard > p { font-size: 13px; color: var(--text-3); margin: 5px 0 22px; }
  .authcard .field + .field { margin-top: 13px; }
  .authcard .btn { width: 100%; height: 38px; margin-top: 18px; }
  .authcard .note { margin-top: 14px; }

  /* Seuil bas volontairement : la barre latérale ne fait que 244 px, la garder le plus longtemps
     possible évite de basculer sur la navigation de repli pour rien. */
  @media (max-width: 720px) {
    :root { --sidebar: 0px; }
    .side { display: none; }
    .topnav { display: flex; }
    .topbar h1 { display: none; }
    .topbar { padding: 0 16px; }
    .scroll { padding: 18px 16px 40px; }
    .grid2 { grid-template-columns: 1fr; }
    .row { flex-wrap: wrap; }
    .row .tools { width: 100%; justify-content: flex-end; }
    .metrics { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
    .metric { padding: 14px; }
    .metric .value { font-size: 22px; }
    .live { display: none; }
    .grid3 { grid-template-columns: 1fr; }
  }
}
