:root {
  --ink: #0D1B2A;
  --ink-2: #16293D;
  --ink-3: #24405C;
  --blue: #2563EB;
  --sky: #3B82F6;
  --green: #047857;
  --green-soft: #D1FAE5;
  --red: #B91C1C;
  --red-soft: #FEE2E2;
  --amber: #92400E;
  --amber-soft: #FEF3C7;
  --slate: #475569;
  --line: #DCE3EB;
  --mist: #F1F5F9;
  --white: #FFFFFF;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Poppins', -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.55; color: var(--ink); background: var(--mist);
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 28px 0 10px; }
h3 { font-size: 14px; font-weight: 600; margin: 16px 0 6px; }
p { margin: 0 0 10px; }
code { font-size: 12.5px; background: var(--mist); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
.muted { color: var(--slate); }
.small { font-size: 12.5px; }

/* Shell */
.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.shell > div { min-width: 0; }
.rail { background: var(--ink); color: #C9D6E3; padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: var(--white); font-weight: 700; font-size: 17px; padding: 2px 10px 16px; }
.rail a { display: flex; justify-content: space-between; align-items: center; color: inherit; padding: 8px 10px; border-radius: 8px; }
.rail a:hover { background: var(--ink-2); text-decoration: none; color: var(--white); }
.rail a.on { background: var(--blue); color: var(--white); }
.rail .group { margin-top: 14px; padding: 0 10px 4px; color: #8FA3B8; font-size: 12px; }
.rail .who { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--ink-3); font-size: 12.5px; }
.rail .who a { padding: 4px 0; display: inline; color: #8FB4F5; }
.badge { background: var(--white); color: var(--ink); font-size: 11.5px; font-weight: 600; border-radius: 10px; padding: 0 7px; min-width: 20px; text-align: center; }
.content { padding: 28px 32px 60px; min-width: 0; max-width: 1180px; width: 100%; }
.btn.menu-toggle { display: none; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }

/* Controls */
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--white); color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; display: inline-block; }
.btn:hover { border-color: var(--sky); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--white); }
.btn.primary:hover { background: #1D4ED8; }
.btn.good { background: var(--green); border-color: var(--green); color: var(--white); }
.btn.danger { color: var(--red); border-color: #F3B4B4; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; color: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
input[type=checkbox] { width: auto; }
textarea { min-height: 96px; resize: vertical; }
label { display: block; font-weight: 500; font-size: 13px; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.notice { padding: 9px 12px; border-radius: 8px; background: var(--green-soft); color: #065F46; margin-bottom: 14px; }
.notice.bad { background: var(--red-soft); color: var(--red); }
.notice.warn { background: var(--amber-soft); color: var(--amber); }
.tag { display: inline-block; font-size: 12px; padding: 0 8px; border-radius: 10px; background: var(--mist); color: var(--slate); white-space: nowrap; }
.tag.good { background: var(--green-soft); color: #065F46; }
.tag.bad { background: var(--red-soft); color: var(--red); }
.tag.warn { background: var(--amber-soft); color: var(--amber); }
.scroll { overflow-x: auto; background: var(--white); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--slate); }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--slate); }
.stats { display: flex; gap: 32px; flex-wrap: wrap; margin-bottom: 20px; }
.stat strong { display: block; font-size: 22px; font-weight: 600; }

/* Auth */
.auth-page { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 16px; }
.auth-card { background: var(--white); border-radius: 12px; padding: 28px; width: 100%; max-width: 380px; }
.auth-card.wide { max-width: 480px; margin: 24px 0; }

/* Team switchboard */
.desk { display: grid; grid-template-columns: 252px minmax(0, 1fr); height: 100vh; }
.board { background: var(--white); border-right: 1px solid var(--line); overflow-y: auto; padding: 16px 10px; }
.board h2 { margin: 2px 8px 10px; font-size: 13px; color: var(--slate); font-weight: 500; }
.team-link { display: grid; grid-template-columns: 42px 1fr; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 10px; color: var(--ink); }
.team-link:hover { background: var(--mist); text-decoration: none; }
.team-link .code { width: 42px; height: 42px; border-radius: 11px; background: var(--ink); color: var(--white); display: grid; place-items: center; font-weight: 600; font-size: 12.5px; letter-spacing: .3px; }
.team-link.on { background: #E8F0FE; }
.team-link.on .code { background: var(--blue); }
.team-link span { font-weight: 500; line-height: 1.25; }
.recent { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.recent a { display: block; padding: 5px 8px; border-radius: 6px; color: var(--slate); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent a.on, .recent a:hover { background: var(--mist); color: var(--ink); text-decoration: none; }
.chat { display: flex; flex-direction: column; min-width: 0; height: 100vh; background: var(--mist); }
.chat-head { background: var(--white); border-bottom: 1px solid var(--line); padding: 12px 22px; display: flex; justify-content: space-between; gap: 14px; align-items: center; flex-wrap: wrap; }
.chat-head h1 { font-size: 17px; margin: 0; }
.chat-head select { width: auto; min-width: 160px; }
.log { flex: 1; overflow-y: auto; padding: 22px; }
.log-inner { max-width: 820px; margin: 0 auto; display: grid; gap: 14px; }
.msg { max-width: 100%; }
.msg.user { justify-self: end; background: var(--ink); color: var(--white); padding: 9px 14px; border-radius: 14px 14px 3px 14px; max-width: 78%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { background: var(--white); border: 1px solid var(--line); padding: 12px 16px; border-radius: 3px 14px 14px 14px; overflow-wrap: anywhere; }
.msg.note { color: var(--slate); font-size: 13px; }
.msg table { font-size: 13px; margin: 8px 0; display: block; overflow-x: auto; }
.msg h3, .msg h4 { margin: 10px 0 4px; font-size: 14px; }
.msg ul, .msg ol { margin: 6px 0; padding-left: 20px; }
.msg p:last-child { margin-bottom: 0; }
.msg pre { background: var(--mist); padding: 10px; border-radius: 8px; overflow-x: auto; }
.draft { border: 1px solid #BBD0F8; background: #F5F8FF; border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.draft-text { white-space: pre-wrap; }
.draft-title { font-size: 12.5px; color: var(--blue); font-weight: 500; margin-bottom: 4px; }
.draft .row { margin-top: 8px; }
.cards { display: grid; gap: 6px; margin-top: 8px; }
.card-link { display: block; font-size: 13px; padding: 6px 10px; border-radius: 8px; background: var(--mist); color: var(--ink); }
.rate { display: flex; gap: 6px; margin-top: 8px; font-size: 12.5px; }
.rate button { font: inherit; background: none; border: 0; color: var(--slate); cursor: pointer; padding: 0 2px; }
.rate button:hover { color: var(--blue); }
.starters { display: flex; gap: 8px; flex-wrap: wrap; }
.starters button { font: inherit; font-size: 13px; background: var(--white); border: 1px solid var(--line); border-radius: 16px; padding: 5px 12px; cursor: pointer; }
.starters button:hover { border-color: var(--sky); }
.status-line { color: var(--slate); font-size: 13px; }
.composer { background: var(--white); border-top: 1px solid var(--line); padding: 12px 22px; }
.composer form { max-width: 820px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 160px; resize: none; }

/* Calculator */
.calc { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.modes button { font: inherit; font-weight: 500; padding: 9px; border: 1px solid var(--line); background: var(--white); border-radius: 8px; cursor: pointer; }
.modes button.on { background: var(--ink); color: var(--white); border-color: var(--ink); }
.result { position: sticky; top: 20px; }
.result .big { font-size: 32px; font-weight: 600; line-height: 1.2; }
.result .big.profit { color: var(--green); }
.result .big.loss { color: var(--red); }
.lines { width: 100%; margin: 12px 0; }
.lines td { padding: 4px 0; border: 0; }
.lines td:last-child { text-align: right; }
.lines tr.total td { border-top: 1px solid var(--line); font-weight: 600; padding-top: 7px; }

/* Case clock */
.clock { font-weight: 600; white-space: nowrap; }
.clock.late { color: var(--red); }
.clock.soon { color: var(--amber); }
.quote { background: var(--mist); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--blue); }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; z-index: 20; inset: 0 auto 0 0; width: 232px; transform: translateX(-100%); transition: transform .18s; }
  .rail.open { transform: none; }
  .btn.menu-toggle { display: inline-block; position: fixed; z-index: 30; right: 12px; bottom: 84px; }
  .content { padding: 18px 16px 60px; }
  .desk { grid-template-columns: 1fr; height: auto; }
  .board { border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; gap: 6px; overflow-x: auto; }
  .board h2, .recent { display: none; }
  .team-link { display: block; padding: 2px; }
  .team-link span { display: none; }
  .chat { height: calc(100vh - 68px); }
  .chat-head, .composer { padding-left: 16px; padding-right: 16px; }
  .log { padding: 16px; }
  .calc, .grid2, .grid3 { grid-template-columns: 1fr; }
  .result { position: static; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
