* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --ink: #0f172a; --muted: #64748b; --line: #e8ebf3; --bg: #f5f6fb; --surface: #fff;
  --accent: #4f46e5; --accent-2: #7c3aed; --accent-soft: #eef0ff; --danger: #dc2626;
  --night: #0f1226; --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
  --shadow: 0 1px 2px rgb(15 23 42 / .04), 0 8px 24px rgb(15 23 42 / .06);
}
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1 { font-size: 20px; letter-spacing: -.02em; }
h2 { font-size: 15px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.error { color: var(--danger); }
.status { color: #15803d; font-weight: 500; }
.status:empty, .error:empty { display: none; }
svg { width: 20px; height: 20px; flex: none; }

button, input, select, textarea { font: inherit; color: inherit; }
button, select { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 500; transition: background .15s, border-color .15s, transform .05s, box-shadow .15s; }
button:hover, select:hover { border-color: #cbd0e0; background: #fafbff; }
button:active { transform: translateY(1px); }
input, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; width: 100%; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 4px rgb(79 70 229 / .13); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
textarea { resize: vertical; }
input[type=color] { height: 42px; width: 90px; padding: 4px; cursor: pointer; }
.primary { background: var(--grad); border: 0; color: #fff; font-weight: 600; box-shadow: 0 6px 16px rgb(79 70 229 / .25); }
.primary:hover { background: var(--grad); filter: brightness(1.07); }
.icon { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; }
a { color: var(--accent); font-weight: 500; text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--accent-soft); border-radius: 5px; padding: 1px 5px; font-size: 12px; }

.logo { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--grad); color: #fff; flex: none; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; flex: none; font-weight: 700; font-size: 13px; background: var(--accent-soft); color: var(--accent); }
.a1 { background: #ecfdf5; color: #047857; } .a2 { background: #fff7ed; color: #c2410c; }
.a3 { background: #fdf2f8; color: #be185d; } .a4 { background: #ecfeff; color: #0e7490; }

/* sign in */
#login { min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
.hero { background: radial-gradient(1200px 600px at -10% -10%, #4f46e5 0, transparent 55%), radial-gradient(900px 600px at 110% 110%, #7c3aed 0, transparent 55%), var(--night); color: #fff; display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 8vw; }
.hero .logo { width: 56px; height: 56px; border-radius: 16px; background: rgb(255 255 255 / .12); }
.hero .logo svg { width: 28px; height: 28px; }
.hero h2 { font-size: clamp(26px, 3vw, 40px); line-height: 1.15; letter-spacing: -.03em; }
.hero p { color: #c7cbe8; font-size: 16px; }
.signin { display: grid; place-items: center; padding: 32px 20px; }
.signin .box { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
.signin h1 { font-size: 28px; }
.signin button { padding: 12px; margin-top: 4px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; }
label input, label textarea { font-weight: 400; font-size: 14px; }

/* shell */
#app { height: 100dvh; display: flex; }
nav { width: 224px; flex: none; display: flex; flex-direction: column; gap: 4px; padding: 18px 12px; background: var(--night); color: #c3c7e0; }
nav .brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 18px; color: #fff; font-size: 16px; letter-spacing: -.01em; }
nav button { display: flex; align-items: center; gap: 10px; background: transparent; border: 0; color: inherit; text-align: left; padding: 10px 12px; }
nav button:hover { background: rgb(255 255 255 / .07); color: #fff; }
nav button.active { background: rgb(129 120 255 / .22); color: #fff; box-shadow: inset 3px 0 0 #8b83ff; }
nav .user { display: flex; align-items: center; gap: 10px; padding: 12px 6px 6px; border-top: 1px solid rgb(255 255 255 / .09); margin-top: 8px; font-size: 12px; }
nav .user .avatar { width: 32px; height: 32px; font-size: 12px; }
#me { overflow: hidden; text-overflow: ellipsis; }
.pill { align-self: flex-start; font-size: 11px; font-weight: 600; border-radius: 99px; padding: 4px 10px; background: rgb(255 255 255 / .08); margin-left: 6px; }
main { flex: 1; min-width: 0; min-height: 0; }

/* inbox */
#inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 288px; grid-template-rows: minmax(0, 1fr); }
#inbox:has(#details[hidden]) { grid-template-columns: 320px minmax(0, 1fr); }
aside { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
aside h1 { padding: 18px 18px 4px; }
.filters { display: flex; gap: 8px; padding: 10px 14px 12px; border-bottom: 1px solid var(--line); }
.filters input { background: var(--bg); border-color: transparent; }
#list { list-style: none; overflow-y: auto; padding: 8px; }
#listEmpty { padding: 28px; text-align: center; }
#list button { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; border: 0; border-radius: 12px; padding: 11px 10px; margin-bottom: 2px; font-weight: 400; background: transparent; }
#list button:hover { background: var(--bg); }
#list button.active { background: var(--accent-soft); }
#list .text { flex: 1; min-width: 0; }
#list .top, #list .bottom { display: flex; gap: 8px; align-items: center; }
#list b, #list .last { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .last { color: var(--muted); font-size: 13px; flex: 1; }
.badge { background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; min-width: 18px; text-align: center; padding: 0 6px; }
time { font-size: 11px; color: #94a3b8; flex: none; }

#thread { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#empty { margin: auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px; }
#empty .logo { width: 60px; height: 60px; border-radius: 18px; margin-bottom: 8px; }
#empty .logo svg { width: 30px; height: 30px; }
#empty b { font-size: 16px; }
#chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#chat header { display: flex; gap: 12px; align-items: center; padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
#chat header b, #chat header small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat header small { color: var(--muted); }
#back, #showInfo, #infoBack { display: none; }
#messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.msg { flex: none; max-width: min(70%, 560px); padding: 10px 14px; border-radius: 18px 18px 18px 6px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface); box-shadow: var(--shadow); align-self: flex-start; }
.msg small { display: block; font-size: 10.5px; opacity: .65; margin-top: 3px; text-align: right; }
.day { align-self: center; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 3px 12px; flex: none; }
.msg.agent, .msg.ai { align-self: flex-end; background: var(--grad); color: #fff; border-radius: 18px 18px 6px 18px; }
#typing { padding: 0 22px 8px; color: var(--muted); font-size: 12px; font-style: italic; }
#quick { display: flex; gap: 8px; overflow-x: auto; padding: 0 18px 10px; scrollbar-width: none; }
#quick button { flex: none; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; border-radius: 99px; padding: 6px 14px; }
#quick button:hover { border-color: var(--accent); color: var(--accent); }
#composer { display: flex; gap: 10px; align-items: flex-end; margin: 0 14px 14px; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
#composer:focus-within { border-color: var(--accent); }
#composer textarea { border: 0; box-shadow: none; resize: none; padding: 8px; }
#composer button { width: 42px; height: 42px; display: grid; place-items: center; padding: 0; flex: none; }

#details { background: var(--surface); border-left: 1px solid var(--line); padding: 20px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
#details h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 6px; }
#details > * { flex: none; }
#info { background: var(--bg); border-radius: 14px; padding: 6px 14px; }
dt { font-size: 11px; color: var(--muted); padding-top: 8px; }
dd { overflow-wrap: anywhere; font-weight: 500; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
dd:last-child { border-bottom: 0; }

.switch { display: flex; flex-direction: row; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.switch input { position: absolute; opacity: 0; width: 1px; }
.switch span { width: 36px; height: 21px; border-radius: 99px; background: #d5d9e6; position: relative; flex: none; }
.switch span::after { content: ""; position: absolute; width: 17px; height: 17px; top: 2px; left: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .2); transition: left .15s; }
.switch input:checked + span { background: #16a34a; }
.switch input:checked + span::after { left: 17px; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch.disabled { opacity: .5; cursor: not-allowed; }

/* settings + clients */
.page { overflow-y: auto; padding: 32px 20px 60px; display: flex; flex-direction: column; gap: 18px; align-items: center; }
.page > * { width: min(680px, 100%); flex: none; }
.title h1 { font-size: 26px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 16px; }
.card > button, .card form > button { align-self: flex-start; padding: 10px 20px; }
pre { background: var(--night); color: #d8dbff; padding: 14px 16px; border-radius: 12px; overflow-x: auto; font-size: 12px; user-select: all; }
#userForm { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 16px; }
#users, #clientList { list-style: none; }
#users li, #clientList li { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
#users li:last-child, #clientList li:last-child { border-bottom: 0; }
#planForm, #payForm { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; align-items: end; }
#planForm button, #payForm button { padding: 10px 20px; justify-self: start; }
#billing select { padding: 10px 12px; font-size: 14px; }
#billing h3 { font-size: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
#clientList .who { flex: 1 1 260px; } /* the buttons wrap below instead of squeezing the name */
#payList { list-style: none; }
#payList li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; }
#planBanner { margin: 8px 14px 0; padding: 10px 12px; border-radius: 10px; background: #fef3c7; color: #92400e; font-size: 13px; font-weight: 600; }

.profile { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.profile .avatar { width: 64px; height: 64px; font-size: 20px; }
.profile b { font-size: 16px; overflow-wrap: anywhere; }
#actions { display: flex; gap: 8px; width: 100%; margin-top: 4px; }
#actions a { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; font-size: 12px; font-weight: 600; }
#actions a:hover { background: var(--accent-soft); border-color: transparent; text-decoration: none; }
.chip { font-size: 11px; font-weight: 700; border-radius: 99px; padding: 3px 10px; background: var(--bg); color: var(--muted); flex: none; }
.chip.good { background: #dcfce7; color: #15803d; }
.chip.bad { background: #fee2e2; color: #b91c1c; }
.chip.warn { background: #fef3c7; color: #92400e; }
.who { display: flex; flex-direction: column; }
.who small { color: var(--muted); overflow-wrap: anywhere; }

.off { display: none !important; }
#pushBar { margin: 8px 14px 0; background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.danger:hover { background: #fef2f2; border-color: #fecaca; }
nav a { color: inherit; padding: 10px 12px; font-weight: 500; }
nav a:hover { color: #fff; }
#setup { text-align: left; width: min(420px, 100%); margin-top: 16px; gap: 6px; }
#setup ul { list-style: none; }
#setup button { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 8px; }
#setup button:hover { background: var(--bg); }
#setup button.done { color: var(--muted); text-decoration: line-through; }
#empty { overflow-y: auto; }
#settings > * { width: min(940px, 100%); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: transparent; border-radius: 0; padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button:hover { background: transparent; color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.studio { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
#preview { position: sticky; top: 0; display: flex; flex-direction: column; gap: 8px; --pc: #1d4ed8; --po: #fff; }
.mock { border-radius: 20px; overflow: hidden; background: #f6f7fb; box-shadow: 0 18px 50px rgb(15 23 42 / .16); }
.mhead { display: flex; gap: 10px; align-items: center; padding: 16px; color: var(--po); background: var(--pc) linear-gradient(135deg, rgb(255 255 255 / .16), rgb(0 0 0 / .28)); }
.mhead b { display: block; overflow-wrap: anywhere; }
.mhead small { opacity: .85; font-size: 11px; }
.mmark { width: 38px; height: 38px; border-radius: 13px; background: rgb(255 255 255 / .2); display: grid; place-items: center; font-weight: 700; flex: none; }
.mbody { margin: 14px; padding: 14px; border-radius: 16px; background: #fff; display: flex; flex-direction: column; gap: 8px; font-size: 12px; overflow-wrap: anywhere; }
.mbody p { color: #475569; }
.mbody i { font-style: normal; color: #94a3b8; border: 1px solid #e2e8f0; background: #f8fafc; border-radius: 10px; padding: 8px 10px; }
.mbody span { color: #94a3b8; font-size: 11px; }
.mbody em { font-style: normal; font-weight: 600; text-align: center; border-radius: 10px; padding: 9px; color: var(--po); background: var(--pc); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow); }
.stats b { display: block; font-size: 28px; letter-spacing: -.03em; }
.stats span { color: var(--muted); font-size: 12px; }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); width: max-content; max-width: min(440px, calc(100vw - 32px)); padding: 12px 18px; border-radius: 12px; background: var(--night); color: #fff; font-weight: 500; box-shadow: 0 12px 32px rgb(15 23 42 / .28); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #b91c1c; }

@media (max-width: 1100px) {
  .studio { grid-template-columns: minmax(0, 1fr); }
  #preview { position: static; }
  #inbox, #inbox:has(#details[hidden]) { grid-template-columns: 290px minmax(0, 1fr); }
  #showInfo { display: grid; }
  #infoBack { display: block; }
  #details { display: none; }
  #inbox.info #thread { display: none; }
  #inbox.info #details { display: flex; grid-column: 2; }
}
@media (max-width: 720px) {
  #login { grid-template-columns: 1fr; }
  .hero { display: none; }
  #app { flex-direction: column; }
  nav { width: 100%; flex-direction: row; align-items: center; padding: 8px; order: 2; justify-content: space-around; }
  nav .brand, nav .user, nav .pill, nav .grow, nav a { display: none; }
  nav button { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 10px; }
  nav button.active { box-shadow: none; }
  #inbox, #inbox:has(#details[hidden]) { grid-template-columns: minmax(0, 1fr); }
  #inbox #thread, #inbox.viewing aside, #inbox.info #thread { display: none; }
  #setup { display: none; }
  #inbox.viewing #thread { display: flex; }
  #inbox.viewing.info #thread { display: none; }
  #inbox.info #details { grid-column: 1; }
  aside { border-right: 0; }
  #back { display: grid; }
  #chat header { gap: 8px; padding: 10px; }
  #chat header .avatar, #aiLabel { display: none; }
  .msg { max-width: 85%; }
  .page { padding: 20px 12px 40px; }
  .stats { gap: 8px; }
  .stats div { padding: 12px; }
  #toast { bottom: 80px; }
  .card { padding: 18px; }
}
.help { max-width: 720px; margin: 0 auto; padding: 36px 16px 60px; display: flex; flex-direction: column; gap: 16px; }
.help ol, .help ul { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
