:root {
  --bg: #0d1014;
  --surface: #161a20;
  --surface-2: #1d222a;
  --surface-3: #262c35;
  --line: rgba(255, 255, 255, .07);
  --line-2: rgba(255, 255, 255, .12);
  --text: #eceae6;
  --text-2: #a2a7ae;
  --text-3: #6b717a;
  --accent: #f2c230;
  --accent-soft: rgba(242, 194, 48, .14);
  --green: #3fca7c;
  --red: #e5735f;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100dvh; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; text-decoration: none; }

.wrap { max-width: 1120px; margin: 0 auto; padding: calc(var(--safe-t) + 18px) 16px calc(40px + var(--safe-b)); }
@media (min-width: 760px) { .wrap { padding: 28px 28px 56px; } }

/* En-tête */
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 40px; height: 40px; border-radius: 11px; background: var(--accent); color: #1a1405; display: grid; place-items: center; flex: none; box-shadow: 0 6px 18px rgba(242, 194, 48, .18); }
.logo svg { width: 20px; height: 20px; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { display: block; font-size: 11px; letter-spacing: .14em; color: var(--text-3); font-weight: 600; text-transform: uppercase; margin-top: 1px; }
.head-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--text-2); }
.pill svg { width: 16px; height: 16px; }
.pill.on { color: var(--accent); border-color: rgba(242, 194, 48, .35); background: var(--accent-soft); }
.pill.icon { width: 34px; padding: 0; justify-content: center; }
.online { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); margin-right: 4px; }
.online i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
@media (max-width: 520px) { .online { display: none; } }

.search { margin: 16px 0 4px; position: relative; }
.search input { width: 100%; height: 42px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); padding: 0 14px 0 40px; font-size: 15px; outline: none; }
.search input:focus { border-color: rgba(242, 194, 48, .5); }
.search svg { position: absolute; left: 13px; top: 12px; width: 18px; height: 18px; color: var(--text-3); }

/* Sections */
.section { margin-top: 26px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 11.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text-2); white-space: nowrap; }
.section-head::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }
.section-head .sec-edit { order: 3; color: var(--text-3); font-size: 12.5px; font-weight: 600; display: inline-flex; gap: 5px; align-items: center; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line-2); }
.section-head .sec-edit svg { width: 13px; height: 13px; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 12px; } }

.tile { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 108px; padding: 16px 8px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-align: center; transition: transform .12s, border-color .15s, background .15s; }
.tile:hover { border-color: rgba(242, 194, 48, .35); background: var(--surface-2); }
.tile:active { transform: scale(.97); }
@media (min-width: 860px) { .tile { min-height: 118px; } }
.tile .ic { width: 46px; height: 46px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 700; font-size: 16px; color: #fff; overflow: hidden; flex: none; }
.tile .ic.emoji { font-size: 24px; }
.tile .ic img { width: 100%; height: 100%; object-fit: contain; }
.tile .ic.img { background: transparent; border-radius: 10px; }
.tile .nm { font-size: 13px; font-weight: 650; line-height: 1.25; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .st { position: absolute; top: 9px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); opacity: .7; }
.tile .st.ok { background: var(--green); opacity: 1; box-shadow: 0 0 0 3px rgba(63, 202, 124, .14); }
.tile .st.ko { background: var(--red); opacity: 1; box-shadow: 0 0 0 3px rgba(229, 115, 95, .14); }
.tile .lk { position: absolute; top: 7px; left: 8px; color: var(--accent); opacity: .85; }
.tile .lk svg { width: 12px; height: 12px; }
.tile.add { border-style: dashed; color: var(--text-3); background: transparent; }
.tile.add svg { width: 24px; height: 24px; }
.editing .tile:not(.add)::after { content: ""; position: absolute; inset: -1px; border-radius: 12px; border: 1px dashed rgba(242, 194, 48, .45); pointer-events: none; }

.edit-bar { position: sticky; top: 0; z-index: 10; margin: 14px -16px 0; padding: 10px 16px; display: flex; gap: 8px; align-items: center; justify-content: space-between; background: rgba(42, 34, 10, .92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid rgba(242, 194, 48, .25); color: var(--accent); font-size: 13.5px; font-weight: 600; }
.edit-bar .btns { display: flex; gap: 8px; }
@media (min-width: 760px) { .edit-bar { margin: 14px 0 0; border-radius: 12px; border: 1px solid rgba(242, 194, 48, .25); } }

.empty { text-align: center; color: var(--text-2); padding: 60px 20px; font-size: 14.5px; }
.foot { margin-top: 40px; text-align: center; font-size: 12px; color: var(--text-3); }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px; border-radius: 12px; font-weight: 650; font-size: 15px; background: var(--surface-3); }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--accent); color: #1a1405; }
.btn.danger { background: rgba(229, 115, 95, .14); color: var(--red); }
.btn.small { height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; }

/* Feuilles */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s; }
.sheet { width: 100%; max-width: 480px; max-height: 92dvh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line-2); border-bottom: 0; border-radius: 20px 20px 0 0; animation: up .24s cubic-bezier(.2, .9, .3, 1); }
@media (min-width: 760px) { .overlay { align-items: center; } .sheet { border-radius: 20px; border-bottom: 1px solid var(--line-2); } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-body { padding: 16px 18px calc(18px + var(--safe-b)); overflow-y: auto; }
.x { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); }
.x svg { width: 17px; height: 17px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* Code PIN */
.pin { text-align: center; padding: 6px 0 4px; }
.pin p { margin: 0 0 18px; color: var(--text-2); font-size: 14px; }
.dots { display: flex; justify-content: center; gap: 16px; margin-bottom: 10px; }
.dots i { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--text-3); transition: .12s; }
.dots i.on { background: var(--accent); border-color: var(--accent); }
.dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
.pin .err { min-height: 20px; color: var(--red); font-size: 13.5px; margin-bottom: 8px; }
.pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; justify-content: center; }
.pad button { height: 64px; border-radius: 50%; width: 76px; font-size: 26px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--line); }
.pad button:active { background: var(--surface-3); }
.pad .ghost { background: none; border: 0; font-size: 14px; color: var(--text-2); }
.pad .ghost svg { width: 24px; height: 24px; }

/* Formulaires */
.fields { display: flex; flex-direction: column; gap: 13px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.field .help { font-size: 12px; color: var(--text-3); margin-top: 5px; line-height: 1.4; }
.field input, .field select { width: 100%; height: 44px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line-2); padding: 0 12px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { flex: 1; height: 36px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.seg button.on { background: var(--surface-3); color: var(--text); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 12px; }
.switch b { font-size: 14.5px; font-weight: 600; }
.switch small { display: block; color: var(--text-3); font-size: 12px; margin-top: 2px; }
.toggle { width: 50px; height: 30px; border-radius: 99px; background: var(--surface-3); position: relative; flex: none; transition: .15s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .15s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 23px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.colors button.on { border-color: #fff; }
.preview-tile { display: flex; justify-content: center; margin-bottom: 4px; }
.preview-tile .tile { width: 150px; pointer-events: none; }
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .btn { flex: 1; }
.move { display: flex; gap: 8px; }
.move .btn { flex: 1; }

#toast { position: fixed; left: 50%; top: calc(var(--safe-t) + 14px); transform: translateX(-50%) translateY(-16px); opacity: 0; z-index: 60; background: var(--surface-3); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; transition: .25s; pointer-events: none; white-space: nowrap; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
