.app-body { min-height: 100vh; background: radial-gradient(60% 50% at 80% -10%, rgba(92, 225, 255, .06), transparent 60%) no-repeat, var(--bg); }
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 18px 14px; border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #060a11, #04070c); display: flex; flex-direction: column; gap: 22px; z-index: 30;
}
.side .brand { padding: 4px 8px; }
.side-nav { display: grid; gap: 3px; }
.side-nav button {
  all: unset; cursor: pointer; display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-size: 14px; font-weight: 500; transition: background .2s, color .2s;
}
.side-nav button svg { width: 17px; height: 17px; fill: currentColor; opacity: .8; }
.side-nav button:hover { color: var(--text); background: rgba(255, 255, 255, .03); }
.side-nav button.on { color: var(--text); background: linear-gradient(90deg, rgba(92, 225, 255, .12), rgba(92, 225, 255, .02)); box-shadow: inset 2px 0 0 var(--accent); }
.side-nav button .badge { margin-left: auto; height: 20px; font-size: 10px; }
.side-nav .count { margin-left: auto; min-width: 20px; height: 20px; border-radius: 10px; background: var(--warn); color: #1a1200; font: 600 11px/20px var(--mono); text-align: center; padding: 0 6px; }
.side-foot { margin-top: auto; display: flex; gap: 16px; padding: 0 10px; font-size: 13px; }

.main { min-width: 0; padding: 0 clamp(14px, 2.6vw, 34px) 60px; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 70px; display: flex; align-items: center; gap: 14px;
  background: linear-gradient(180deg, rgba(3, 5, 10, .95), rgba(3, 5, 10, .75)); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); margin: 0 calc(-1 * clamp(14px, 2.6vw, 34px)) 24px; padding: 0 clamp(14px, 2.6vw, 34px);
}
.topbar h1 { font: 700 22px/1 var(--display); letter-spacing: .06em; margin: 0; text-transform: uppercase; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-btn { display: none; }

.agent-switch { display: flex; align-items: center; gap: 9px; height: 38px; padding: 0 10px 0 12px; border-radius: 10px; border: 1px solid var(--line2); background: rgba(10, 15, 24, .8); }
.agent-switch .mono { font-size: 11px; letter-spacing: .18em; color: var(--muted); }
.switch { all: unset; cursor: pointer; width: 40px; height: 22px; border-radius: 12px; background: #1b2433; position: relative; transition: background .25s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #8b97a9; transition: transform .25s, background .25s; }
.switch[aria-checked="true"] { background: rgba(92, 225, 255, .35); }
.switch[aria-checked="true"] i { transform: translateX(18px); background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.switch.busy { opacity: .5; pointer-events: none; }

.acct { position: relative; }
.acct-btn { all: unset; cursor: pointer; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel2); font-size: 13px; }
.net-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.acct-menu { position: absolute; right: 0; top: 46px; min-width: 190px; padding: 6px; border-radius: 12px; border: 1px solid var(--line2); background: #0b111b; box-shadow: 0 20px 50px -20px #000; display: grid; }
.acct-menu a, .acct-menu button { all: unset; cursor: pointer; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.acct-menu a:hover, .acct-menu button:hover { background: rgba(255, 255, 255, .05); }

.banner { margin: 0 0 18px; padding: 12px 16px; border-radius: 12px; border: 1px solid rgba(255, 200, 92, .35); background: rgba(255, 200, 92, .06); font-size: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.dash-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.dash-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { display: grid; gap: 8px; align-content: start; }
.stat .panel-title { margin: 0; }
.stat .badge { justify-self: start; }
.big { font-size: 28px; font-weight: 500; line-height: 1.1; }
.bar { height: 5px; border-radius: 4px; background: #182131; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--chrome); transition: width .6s; }
.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head .panel-title { margin: 0; }
.stack { display: grid; gap: 10px; }
.empty { padding: 18px; border: 1px dashed var(--line2); border-radius: 12px; color: var(--muted); font-size: 14px; text-align: center; }
.small { font-size: 12.5px; }

.mini { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .02); }
.mini b { font-weight: 600; font-size: 14px; }
.mini .grow { flex: 1; min-width: 0; }
.mini .grow span { display: block; color: var(--dim); font: 12px var(--mono); }

/* Chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 130px); min-height: 480px; padding: 0; overflow: hidden; }
.chat-off { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); background: rgba(255, 200, 92, .05); font-size: 14px; }
.chat-log { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: min(640px, 92%); }
.msg.user { align-self: flex-end; }
.msg .bub { padding: 11px 15px; border-radius: 14px; font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.msg.user .bub { background: var(--panel2); border: 1px solid var(--line2); border-bottom-right-radius: 4px; }
.msg.agent .bub { background: rgba(92, 225, 255, .06); border: 1px solid rgba(92, 225, 255, .2); border-bottom-left-radius: 4px; }
.msg .who { font: 500 10.5px var(--mono); letter-spacing: .16em; color: var(--dim); margin: 0 4px 5px; text-transform: uppercase; }
.msg.user .who { text-align: right; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 20px 12px; }
.chips button { all: unset; cursor: pointer; padding: 7px 11px; border-radius: 9px; border: 1px solid var(--line2); color: var(--muted); font: 12.5px var(--mono); }
.chips button:hover { color: var(--text); border-color: var(--accent); }
.chat-input { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: rgba(3, 5, 10, .5); }
.chat-input input { flex: 1; min-width: 0; height: 46px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line2); background: #070b12; color: var(--text); font: 15px var(--sans); outline: none; }
.chat-input input:focus { border-color: var(--accent); }
.chat-input .btn { height: 46px; }
.thinking { display: inline-flex; gap: 4px; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: think 1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; } .thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes think { 0%, 100% { opacity: .2; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

/* Trade form */
.trade-grid { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 18px; align-items: start; }
.trade-form { display: grid; gap: 16px; }
.trade-form label { display: grid; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 500; }
.trade-form input, .trade-form select {
  height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line2); background: #070b12; color: var(--text); font: 15px var(--sans); outline: none; width: 100%; min-width: 0;
}
.trade-form input:focus, .trade-form select:focus { border-color: var(--accent); }
.tok-row { display: flex; gap: 8px; }
.tok-row select { flex: 0 0 150px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 12px; background: #070b12; border: 1px solid var(--line2); }
.seg button { all: unset; cursor: pointer; text-align: center; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on[data-v="buy"] { background: rgba(62, 240, 161, .12); color: var(--ok); }
.seg button.on[data-v="sell"] { background: rgba(255, 92, 122, .12); color: var(--bad); }

.soon-panel { max-width: 640px; padding: 34px; }
.soon-panel h2 { font: 700 34px/1 var(--display); letter-spacing: .06em; margin: 14px 0 10px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font: 500 11px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--dim); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:hover td { background: rgba(255, 255, 255, .015); }
.tbl .num { font-family: var(--mono); }
.tbl a { color: var(--accent); }
.side-buy { color: var(--ok); font-weight: 600; }
.side-sell { color: var(--bad); font-weight: 600; }

@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: 1fr 1fr; }
  .dash-cols, .trade-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .25s; box-shadow: 20px 0 60px -20px #000; }
  .side.open { transform: none; }
  .menu-btn { display: inline-grid; }
  .topbar h1 { font-size: 17px; }
  .agent-switch .mono { display: none; }
  .top-right .ca-chip { display: none; }
  .dash-grid.three { grid-template-columns: 1fr; }
  .chat { height: calc(100vh - 110px); }
}
@media (max-width: 520px) {
  .dash-grid { grid-template-columns: 1fr; }
  .acct-btn #acctAddr { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
  .tok-row select { flex-basis: 120px; }
}

/* Visiteur sans wallet : l'app est consultable, les actions demandent de connecter un wallet */
body.guest [data-user-only] { display: none !important; }
body:not(.guest) [data-guest-only] { display: none !important; }
.guest-banner { justify-content: space-between; border-color: rgba(92, 225, 255, .3); background: rgba(92, 225, 255, .06); }
.connect-btn { height: 38px; border-radius: 10px; }
@media (max-width: 860px) { body.guest .agent-switch { display: none; } }
