:root {
  --bg: #0f1115; --bg2: #161922; --bg3: #1e2230; --border: #2a2f3d;
  --text: #e6e8ee; --muted: #8b92a5; --accent: #d97757; --accent2: #e8916f;
  --danger: #e5484d; --ok: #3dd68c; --warn: #f5a524;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f7f7f8; --bg2: #ffffff; --bg3: #eef0f3; --border: #dcdfe6; --text: #1b1d23; --muted: #677085; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.error { color: var(--danger); min-height: 1.5em; }

.btn { background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
.input { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font: inherit; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 14px; }
.icon-btn:hover { background: var(--bg3); color: var(--text); }
.icon-btn.del:hover { color: var(--danger); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 40px 32px; text-align: center; width: 100%; max-width: 360px; }
.login-card h1 { margin: 8px 0 0; font-size: 22px; }
.login-card .logo { font-size: 36px; color: var(--accent); }
.login-card .btn { margin-top: 20px; width: 100%; justify-content: center; }

/* Layout */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
header { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--bg2); flex-wrap: wrap; }
.brand { font-weight: 600; color: var(--accent); }
nav { display: flex; gap: 4px; flex: 1; }
.tab { background: none; border: none; color: var(--muted); padding: 6px 12px; border-radius: 8px; cursor: pointer; font: inherit; }
.tab.active, .tab:hover { color: var(--text); background: var(--bg3); }
.user { display: flex; align-items: center; gap: 10px; }
.panel { flex: 1; overflow: auto; padding: 16px; min-height: 0; }

/* Fichiers */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; font-family: var(--mono); font-size: 13px; }
.breadcrumb a { color: var(--text); text-decoration: none; padding: 2px 6px; border-radius: 6px; cursor: pointer; }
.breadcrumb a:hover { background: var(--bg3); }
.breadcrumb span { color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.checkbox { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; }
.dropzone { position: relative; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.dropzone.drag { outline: 2px dashed var(--accent); }
.drop-hint { display: none; position: absolute; inset: 0; background: color-mix(in srgb, var(--bg) 85%, transparent); place-items: center; font-size: 18px; color: var(--accent); }
.dropzone.drag .drop-hint { display: grid; }
table.files { width: 100%; border-collapse: collapse; }
.files th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.files td { padding: 6px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.files tr:last-child td { border-bottom: none; }
.files tbody tr:hover { background: var(--bg3); }
.files td.name { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.files td.name .ico { display: inline-block; width: 22px; }
.files .num { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.files td.date { color: var(--muted); }
.files td.row-actions { text-align: right; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--bg3); color: var(--muted); border: none; padding: 4px 10px; cursor: pointer; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: #fff; }
.select { background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; font: inherit; font-size: 13px; }
.input.filter { width: 140px; padding: 4px 10px; font-size: 13px; }
.files th.sortable { cursor: pointer; user-select: none; }
.files th.sortable:hover { color: var(--text); }
.empty-dir { padding: 24px; text-align: center; color: var(--muted); }

/* Grille / galerie */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; padding: 12px; }
.grid.gallery { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.tile { position: relative; border: 1px solid transparent; border-radius: 10px; padding: 10px 6px 6px; text-align: center; cursor: pointer; min-width: 0; }
.tile:hover { background: var(--bg3); border-color: var(--border); }
.tile .t-ico { font-size: 40px; line-height: 1.2; }
.tile .t-thumb { width: 100%; aspect-ratio: 4 / 3; border-radius: 6px; background: var(--bg3); display: grid; place-items: center; overflow: hidden; font-size: 44px; }
.tile .t-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tile .t-name { font-size: 12.5px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.tile .t-meta { font-size: 11px; color: var(--muted); }
.tile .t-actions { position: absolute; top: 4px; right: 4px; display: none; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; }
.tile:hover .t-actions { display: flex; }
@media (hover: none) { .tile .t-actions { display: flex; position: static; justify-content: center; background: none; border: none; } }
.tile.up .t-ico { color: var(--muted); }

.viewer-box { width: 100%; max-width: 1200px; max-height: 92vh; }
.viewer-body { flex: 1; overflow: auto; display: grid; place-items: center; padding: 12px; min-height: 0; }
.viewer-body img { max-width: 100%; max-height: 80vh; object-fit: contain; }

.progress { height: 4px; background: var(--bg3); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* Modal / éditeur */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; }
.editor-box { width: 100%; max-width: 1200px; height: 90vh; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.modal-head > div { display: flex; gap: 8px; align-items: center; }
#editor-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#editor-text { flex: 1; background: var(--bg); color: var(--text); border: none; padding: 14px; font: 13px/1.5 var(--mono); resize: none; outline: none; tab-size: 2; white-space: pre; border-radius: 0 0 12px 12px; }

/* Chat */
#tab-claude { padding: 0; overflow: hidden; }
.chat-layout { display: flex; height: 100%; }
.sessions { width: 300px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--bg2); padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
#session-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
#session-list li { padding: 8px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 2px; }
#session-list li:hover { background: var(--bg3); }
#session-list li.active { background: var(--bg3); border-left: 3px solid var(--accent); }
#session-list .s-title { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
#session-list .s-meta { font-size: 11px; color: var(--muted); }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
#chat-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
#chat-cwd { font-size: 12px; }
.messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 860px; width: 100%; margin: 0 auto; }
.msg.user .bubble { background: var(--bg3); border-radius: 12px; padding: 10px 14px; white-space: pre-wrap; word-wrap: break-word; margin-left: auto; width: fit-content; max-width: 85%; }
.msg.assistant .md { word-wrap: break-word; }
.md pre { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow: auto; font-size: 12.5px; }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--bg3); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow: auto; }
.md td, .md th { border: 1px solid var(--border); padding: 4px 8px; }
.md p:first-child { margin-top: 0; } .md p:last-child { margin-bottom: 0; }
.tool { font-family: var(--mono); font-size: 12px; color: var(--muted); border-left: 2px solid var(--border); padding: 2px 10px; margin: 6px 0; }
.tool summary { cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool summary b { color: var(--accent); font-weight: 600; }
.tool pre { white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow: auto; margin: 6px 0; }
.tool.err { border-left-color: var(--danger); }
.typing::after { content: '▍'; animation: blink 1s infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.chat-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); align-items: flex-end; }
#chat-input { flex: 1; background: var(--bg2); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font: inherit; resize: none; max-height: 200px; }
.empty { color: var(--muted); text-align: center; margin: auto; }
.show-sm { display: none; }

/* Système */
.sys-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.sys-head h2 { margin: 0 0 12px; font-size: 18px; }
.gauges { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.card-title { color: var(--muted); font-size: 13px; }
.big { font-size: 32px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.bar div { height: 100%; width: 0; background: var(--ok); transition: width .5s, background .5s; }
canvas { width: 100%; margin-top: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: calc(100% - 32px); }
.toast.err { border-color: var(--danger); color: var(--danger); }

@media (max-width: 760px) {
  .hide-sm { display: none; }
  .show-sm { display: inline-flex; }
  .sessions { position: absolute; z-index: 5; height: calc(100% - 52px); width: 85%; transform: translateX(-100%); transition: transform .2s; }
  .sessions.open { transform: none; }
  #tab-claude { position: relative; }
  header { gap: 8px; }
  #user-email { display: none; }
}
