:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #eef1f8;
  --line: #e0e5ef;
  --text: #121826;
  --muted: #5f6b80;
  --blue: #2f6bff;
  --blue-soft: #e5edff;
  --green: #0fa57f;
  --green-soft: #def7ef;
  --amber: #c27a00;
  --amber-soft: #fff3d9;
  --red: #d63a4a;
  --red-soft: #ffe5e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420; --panel: #171e2d; --panel-2: #1e2738; --line: #2a3448;
    --text: #eef2fa; --muted: #9aa6bd; --blue: #5b8cff; --blue-soft: #1c2a4d;
    --green: #2fd3a6; --green-soft: #12322b; --amber: #f2b441; --amber-soft: #3a2e12;
    --red: #ff6b7a; --red-soft: #3d1c22; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1420; --panel: #171e2d; --panel-2: #1e2738; --line: #2a3448;
  --text: #eef2fa; --muted: #9aa6bd; --blue: #5b8cff; --blue-soft: #1c2a4d;
  --green: #2fd3a6; --green-soft: #12322b; --amber: #f2b441; --amber-soft: #3a2e12;
  --red: #ff6b7a; --red-soft: #3d1c22; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: "Space Grotesk", Inter, sans-serif; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 236px; flex: none; padding: 20px 14px; border-right: 1px solid var(--line);
  background: var(--panel); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-family: "Space Grotesk"; font-weight: 700; font-size: 18px; }
.brand img { width: 32px; height: 32px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--muted);
  font-weight: 500; border: 0; background: none; cursor: pointer; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--blue-soft); color: var(--blue); }
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item .count { margin-left: auto; background: var(--blue); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.side .me { margin-top: auto; }

main { flex: 1; min-width: 0; padding: 28px 32px 120px; max-width: 1180px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

.tabbar { display: none; }

@media (max-width: 820px) {
  .side { display: none; }
  main { padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 96px); }
  h1 { font-size: 24px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
  }
  .tabbar button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 6px 0; position: relative; cursor: pointer; }
  .tabbar button.active { color: var(--blue); }
  .tabbar svg { width: 24px; height: 24px; }
  .tabbar .dot { position: absolute; top: 2px; left: calc(50% + 8px); background: var(--red); color: #fff; font-size: 10px; border-radius: 99px; padding: 0 5px; font-weight: 700; }
}

/* Components */
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.card-head a, .link-btn { font-size: 13px; font-weight: 600; color: var(--blue); background: none; border: 0; cursor: pointer; padding: 0; }
.empty { color: var(--muted); padding: 10px 0; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; cursor: pointer; white-space: nowrap; color: var(--text);
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn svg { width: 18px; height: 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-family: "Space Grotesk"; font-size: 28px; line-height: 1.1; }

.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; padding-top: 2px; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 13px; }
.when { flex: none; width: 58px; text-align: center; border-radius: 12px; background: var(--blue-soft); color: var(--blue); padding: 6px 0; line-height: 1.2; }
.when b { display: block; font-family: "Space Grotesk"; font-size: 15px; }
.when span { font-size: 11px; font-weight: 600; text-transform: uppercase; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }

.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; flex: none; }
.avatars { display: inline-flex; }
.avatars .avatar { width: 24px; height: 24px; font-size: 10px; border: 2px solid var(--panel); margin-left: -6px; }
.avatars .avatar:first-child { margin-left: 0; }

.check { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); background: none; flex: none; cursor: pointer; display: grid; place-items: center; margin-top: 1px; padding: 0; }
.check.done { background: var(--green); border-color: var(--green); color: #fff; }
.check svg { width: 14px; height: 14px; }
.done-text { text-decoration: line-through; color: var(--muted); }

.seg { display: inline-flex; background: var(--panel-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* Pipeline */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; }
.col { background: var(--panel-2); border-radius: var(--radius); padding: 12px; scroll-snap-align: start; min-height: 120px; }
.col-head { display: flex; justify-content: space-between; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 10px; }
.deal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; cursor: pointer; }
.deal:hover { border-color: var(--blue); }
.deal .title { font-weight: 600; }
.deal .money { font-family: "Space Grotesk"; font-weight: 700; }

/* Chat */
.chat { display: grid; grid-template-columns: 240px 1fr; height: calc(100vh - 150px); min-height: 420px; padding: 0; overflow: hidden; }
.chat-list { border-right: 1px solid var(--line); padding: 10px; overflow-y: auto; }
.chan { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 10px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.chan:hover { background: var(--panel-2); }
.chan.active { background: var(--blue-soft); color: var(--blue); }
.chan .hash { width: 32px; height: 32px; border-radius: 10px; background: var(--panel-2); display: grid; place-items: center; font-weight: 700; color: var(--muted); flex: none; }
.chan .unread { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; border-radius: 99px; padding: 0 7px; font-weight: 700; }
.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-top { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 10px; max-width: 80%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble { background: var(--panel-2); padding: 9px 13px; border-radius: 16px 16px 16px 4px; overflow-wrap: anywhere; }
.msg.mine .bubble { background: var(--blue); color: #fff; border-radius: 16px 16px 4px 16px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg.mine .meta { text-align: right; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer input { flex: 1; }
.back-btn { display: none; }
@media (max-width: 820px) {
  .chat { grid-template-columns: 1fr; height: calc(100dvh - 190px); }
  .chat.open .chat-list { display: none; }
  .chat:not(.open) .chat-main { display: none; }
  .back-btn { display: inline-flex; }
  .msg { max-width: 88%; }
}

/* Forms + sheet */
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); min-height: 42px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: transparent; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form { display: grid; gap: 14px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toggle { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-weight: 500; font-size: 14px; }
.toggle input { width: 20px; min-height: 20px; height: 20px; }

.overlay { position: fixed; inset: 0; background: rgba(6, 10, 20, .5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
.sheet { background: var(--panel); border-radius: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.x { border: 0; background: var(--panel-2); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 18px; color: var(--muted); }
@media (max-width: 820px) {
  .overlay { align-items: flex-end; padding: 0; }
  .sheet { border-radius: 20px 20px 0 0; padding-bottom: calc(env(safe-area-inset-bottom) + 22px); max-height: 92vh; }
}
@keyframes fade { from { opacity: 0; } }

.banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 14px; background: var(--amber-soft); color: var(--amber); font-size: 13px; font-weight: 500; margin-bottom: 18px; }
.banner b { color: inherit; }

.tile { display: flex; gap: 14px; align-items: center; padding: 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); color: var(--text); cursor: pointer; text-align: left; width: 100%; }
.tile:hover { border-color: var(--blue); }
.tile .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.tile .ico svg { width: 22px; height: 22px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { max-width: 400px; width: 100%; padding: 28px; text-align: center; }
.login img { width: 72px; height: 72px; margin-bottom: 12px; }
.who { display: grid; gap: 10px; margin-top: 20px; }
.who button { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); background: var(--panel); border-radius: 14px; cursor: pointer; text-align: left; }
.who button:hover { border-color: var(--blue); }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; z-index: 60; animation: fade .2s; }

.day-head { font-weight: 700; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 8px; }
.day-head:first-child { margin-top: 0; }
.day-head.today { color: var(--blue); }

@media print {
  body > *:not(.print-invoice) { display: none !important; }
  .print-invoice { position: static; background: none; padding: 0; display: block; }
  .print-invoice .sheet { box-shadow: none; max-height: none; max-width: none; border-radius: 0; padding: 0; }
  .no-print { display: none !important; }
}

.seg.scroll { display: flex; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.seg.scroll button { white-space: nowrap; }
@media (max-width: 820px) {
  .grid.stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .grid.stats .card { padding: 12px; }
  .grid.stats b { font-size: 22px; }
  .grid.stats .small { font-size: 11px; line-height: 1.3; }
}
[hidden] { display: none !important; }
