:root {
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  color: #111b21;
  background: #d9dbd5;
  --green: #00a884;
  --green-dark: #008069;
  --line: #e9edef;
  --muted: #667781;
  --danger: #b42318;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; overflow: hidden; background: #f0f2f5; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--danger); min-height: 1.25rem; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(#00a884 0 222px, #f0f2f5 222px);
}
.card { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 22px; box-shadow: 0 1px 3px rgba(11,20,26,.08); }
.login-card { width: min(420px, 100%); box-shadow: 0 17px 50px rgba(11,20,26,.18); }
.brand-mark { width: 48px; height: 48px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; }
.login-card h1 { margin: 18px 0 4px; font-size: 1.7rem; }
label { display: grid; gap: 7px; margin: 15px 0; font-size: .9rem; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid #cdd9d5; border-radius: 8px; padding: 11px 12px; background: #fff; color: #17232d; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(0,168,132,.12); }
button[type="submit"], form > button, .primary { border: 0; border-radius: 8px; padding: 11px 16px; background: var(--green); color: #fff; font-weight: 700; }
button:hover { filter: brightness(.97); }

.app {
  min-height: 100vh;
  height: 100vh;
  margin: 0;
  width: 100%;
  max-width: none;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  background: #fff;
  box-shadow: none;
  overflow: hidden;
}
.sidebar { background: #f0f2f5; color: #54656f; padding: 10px 8px; display: flex; flex-direction: column; gap: 22px; border-right: 1px solid #d8dcdf; align-items: center; }
.sidebar-brand { width: 40px; height: 40px; display: grid; place-items: center; background: var(--green); border-radius: 50%; color: #fff; font-weight: 800; font-size: .78rem; }
.sidebar nav { display: grid; gap: 9px; width: 100%; }
.nav { position: relative; width: 48px; height: 44px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: #54656f; }
.nav.active { background: #d9e1df; color: #111b21; }
.nav-icon { font-size: 1.45rem; line-height: 1; }
.nav-label, .profile-detail { display: none; }
.badge { min-width: 22px; padding: 2px 7px; border-radius: 20px; background: #25d366; color: #fff; text-align: center; font-size: .72rem; font-weight: 800; }
.nav .badge { position: absolute; right: -1px; top: 0; min-width: 18px; padding: 1px 5px; font-size: .65rem; }
.profile { margin-top: auto; width: 100%; display: grid; place-items: center; gap: 10px; }
.theme-toggle { margin-top: auto; }
.theme-toggle + .profile { margin-top: 0; }
.profile-avatar { width: 36px; height: 36px; border: 0; border-radius: 50%; background: #cfd7da; color: #54656f; font-weight: 800; }
.link-button { border: 0; background: transparent; color: #54656f; font-size: 1.25rem; }

.workspace { min-width: 0; padding: 0; background: #fff; display: grid; grid-template-rows: 64px minmax(0, 1fr); height: 100%; overflow: hidden; }
.workspace > header { height: 64px; padding: 0 18px; margin: 0; display: flex; justify-content: space-between; align-items: center; background: #f0f2f5; border-bottom: 1px solid #d8dcdf; }
.workspace h2 { margin: 0 0 3px; font-size: 1rem; font-weight: 600; }
.workspace header p { margin: 0; font-size: .76rem; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.header-icon { border: 0; background: transparent; color: #54656f; font-size: 1.55rem; }
.live { color: var(--green-dark); font-size: .75rem; font-weight: 700; }
.notice { position: absolute; z-index: 8; right: 25px; top: 78px; max-width: 420px; padding: 12px 15px; border-radius: 8px; background: #fff4d6; border: 1px solid #eed28a; box-shadow: 0 4px 18px rgba(0,0,0,.14); }

.view { min-height: 0; }
#queue-view { overflow: auto; background: #fff; }
.list { display: grid; gap: 0; }
.list-item { min-width: 0; overflow: hidden; background: #fff; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 12px 15px; display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.list-item:hover { background: #f5f6f6; }
.contact { display: flex; flex: 1 1 auto; width: 0; gap: 12px; align-items: center; min-width: 0; overflow: hidden; }
.avatar { position: relative; overflow: hidden; width: 49px; height: 49px; flex: 0 0 49px; border-radius: 50%; display: grid; place-items: center; background: #dfe5e7; color: #54656f; font-weight: 800; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.contact-text { flex: 1 1 auto; width: 0; min-width: 0; overflow: hidden; }
.contact-text strong, .contact-text span { display: block; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#queue-list, .chat-list { min-width: 0; overflow-x: hidden; }
.meta { font-size: .78rem; color: var(--muted); }
.elapsed { font-weight: 650; color: #008069; }
.elapsed.waiting { color: #b26a00; }
.elapsed.late { color: #c43d36; }
.secondary, .claim { border: 1px solid #bdd1cc; background: #fff; color: var(--green-dark); border-radius: 8px; padding: 8px 11px; font-weight: 700; }
.claim { background: var(--green); border-color: var(--green); color: #fff; }
.empty-state { padding: 50px; margin: 28px; text-align: center; color: var(--muted); background: #fff; border: 1px dashed #d8dcdf; border-radius: 4px; }

.chat-layout { display: grid; grid-template-columns: 390px minmax(0, 1fr); height: 100%; min-height: 0; gap: 0; }
.chat-sidebar { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); border-right: 1px solid #d8dcdf; background: #fff; }
.chat-tools { padding: 14px 12px 10px; border-bottom: 1px solid var(--line); background: #fff; }
.chat-title-row { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 12px; font-size: 1.25rem; }
.chat-menu { color: #54656f; font-size: 1.35rem; }
.search-box { height: 40px; margin: 0; padding: 0 14px; display: flex; align-items: center; gap: 10px; border-radius: 9px; background: #f0f2f5; color: #54656f; font-weight: 400; }
.search-box input { border: 0; padding: 0; background: transparent; box-shadow: none; font-size: .88rem; }
.chat-filters { display: flex; gap: 8px; margin-top: 10px; }
.filter { border: 1px solid #d6dadd; border-radius: 18px; padding: 6px 13px; background: #fff; color: #54656f; }
.filter.active { border-color: #a7d7aa; background: #e7fce3; color: #008069; }
.chat-list { overflow: auto; align-content: start; background: #fff; }
.chat-list .list-item { cursor: pointer; }
.chat-list .list-item.active { background: #f0f2f5; }
.chat-panel { background: #fff; min-width: 0; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.chat-panel.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); background: #f7f5f3; border-bottom: 6px solid #25d366; }
.empty-chat-mark { width: 84px; height: 84px; display: grid; place-items: center; border-radius: 50%; background: #d9fdd3; color: #008069; font-size: 1.5rem; font-weight: 800; }
.chat-header { min-height: 60px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #f0f2f5; }
.messages { padding: 22px 7%; overflow: auto; display: flex; flex-direction: column; gap: 5px; background-color: #efeae2; background-image: linear-gradient(rgba(239,234,226,.18),rgba(239,234,226,.18)),url('/chat-pattern.svg'); background-size: auto,320px 190px; }
.bubble { max-width: 68%; padding: 7px 9px; border-radius: 8px; background: #fff; align-self: flex-start; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.bubble.out { align-self: flex-end; background: #d9fdd3; }
.bubble .by { font-size: .7rem; color: var(--green-dark); font-weight: 700; }
.bubble time { display: block; text-align: right; color: var(--muted); font-size: .67rem; margin-top: 4px; }
.composer { display: flex; gap: 9px; padding: 9px 12px; background: #f0f2f5; }
.composer textarea { resize: none; min-height: 42px; max-height: 110px; border: 0; border-radius: 8px; }
.composer button { border: 0; border-radius: 9px; padding: 0 18px; background: transparent; color: #54656f; font-weight: 700; }
.bubble.has-media { padding: 5px; min-width: 230px; }
.message-image, .message-video { display: block; width: min(360px, 52vw); max-height: 420px; object-fit: contain; border-radius: 6px; background: rgba(0,0,0,.14); }
.message-audio { display: block; width: min(330px, 55vw); margin: 6px; }
.media-caption { padding: 7px 5px 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-text { white-space: normal; overflow-wrap: anywhere; }
.message-file { display: flex; align-items: center; gap: 11px; min-width: 260px; max-width: 390px; padding: 12px; border-radius: 7px; background: rgba(0,0,0,.07); color: inherit; text-decoration: none; }
.message-file span:last-child { min-width: 0; }
.message-file strong, .message-file small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-file small, .media-unavailable { color: var(--muted); }
.file-icon { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: #fff; font-size: 1.25rem; }
.attach-button { width: 42px; height: 42px; margin: 0; display: grid; place-items: center; flex: 0 0 42px; border-radius: 50%; color: #54656f; font-size: 1.7rem; cursor: pointer; }
.selected-file { align-self: center; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .75rem; color: var(--muted); }

.admin-grid { padding: 24px; overflow: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; background: #f0f2f5; }
.admin-grid h3 { margin-top: 0; }
.wide { grid-column: 1 / -1; }
.status { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: .75rem; background: #edf1f0; color: #62716d; }
.status.connected { background: #dcf7e9; color: #087c61; }
.status.qr { background: #fff1cc; color: #805d00; }

dialog { border: 0; border-radius: 12px; padding: 25px; width: min(430px, calc(100% - 30px)); box-shadow: 0 20px 70px rgba(0,0,0,.25); text-align: center; }
dialog::backdrop { background: rgba(8,27,23,.62); }
dialog img { width: 320px; max-width: 100%; }
.dialog-close { position: absolute; right: 12px; top: 9px; border: 0; background: transparent; font-size: 1.6rem; }
.qr-placeholder { padding: 55px 20px; background: #f2f5f4; border-radius: 10px; color: var(--muted); }
.qr-placeholder small { display: block; margin-top: 8px; }

[data-theme="dark"] { color-scheme: dark; --line: #2b2f2d; --muted: #9aa09d; }
[data-theme="dark"] body { background: #0d100e; color: #e9edef; }
[data-theme="dark"] .app, [data-theme="dark"] .workspace, [data-theme="dark"] #queue-view { background: #111412; }
[data-theme="dark"] .sidebar, [data-theme="dark"] .workspace > header, [data-theme="dark"] .chat-header, [data-theme="dark"] .composer { background: #202321; border-color: #2b2f2d; }
[data-theme="dark"] .nav, [data-theme="dark"] .link-button, [data-theme="dark"] .header-icon, [data-theme="dark"] .chat-menu { color: #aebac1; }
[data-theme="dark"] .nav.active { background: #303432; color: #e9edef; }
[data-theme="dark"] .profile-avatar, [data-theme="dark"] .avatar { background: #353a37; color: #aebac1; }
[data-theme="dark"] .chat-sidebar, [data-theme="dark"] .chat-tools, [data-theme="dark"] .chat-list, [data-theme="dark"] .list-item, [data-theme="dark"] .card { background: #111412; color: #e9edef; border-color: #2b2f2d; }
[data-theme="dark"] .list-item:hover { background: #242825; }
[data-theme="dark"] .chat-list .list-item.active { background: #303432; }
[data-theme="dark"] .search-box { background: #292d2a; color: #9aa09d; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { background: #292d2a; color: #e9edef; border-color: #3a403c; }
[data-theme="dark"] .filter { background: #111412; border-color: #3a403c; color: #aebac1; }
[data-theme="dark"] .filter.active { background: #0a332c; border-color: #0a6655; color: #00a884; }
[data-theme="dark"] .chat-panel.empty { background: #181b19; color: #9aa09d; }
[data-theme="dark"] .empty-chat-mark { background: #0a332c; color: #00a884; }
[data-theme="dark"] .messages { background-color: #0d100e; background-image: linear-gradient(rgba(13,16,14,.38),rgba(13,16,14,.38)),url('/chat-pattern.svg'); background-size: auto,320px 190px; }
[data-theme="dark"] .bubble { background: #202321; color: #e9edef; }
[data-theme="dark"] .bubble.out { background: #005c4b; }
[data-theme="dark"] .bubble .by { color: #06cf9c; }
[data-theme="dark"] .admin-grid { background: #0d100e; }
[data-theme="dark"] dialog { background: #202321; color: #e9edef; }
[data-theme="dark"] .qr-placeholder { background: #111412; }

@media (max-width: 800px) {
  body { background: #fff; }
  .app { width: 100%; height: 100vh; min-height: 100vh; margin: 0; grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 58px; }
  .sidebar { position: static; grid-row: 2; padding: 5px 12px; display: flex; flex-direction: row; width: 100%; justify-content: space-around; border-top: 1px solid #d8dcdf; }
  .sidebar-brand { display: none; }
  .sidebar nav { display: flex; width: auto; flex: 1; justify-content: space-around; }
  .profile { margin: 0; width: auto; display: flex; }
  .link-button { display: none; }
  .workspace { grid-row: 1; height: 100%; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-sidebar { max-height: 38vh; }
  .chat-list { max-height: 35vh; }
  .chat-panel { height: auto; }
  .admin-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
}
