:root {
  color-scheme: light;
  --bg: #eef2f4;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #66747d;
  --line: #d9e0e4;
  --accent: #0f8b6f;
  --accent-2: #235789;
  --warn: #b7791f;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.hidden {
  display: none !important;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--bg);
}

.login-box,
.modal-box,
.form-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.login-box {
  width: min(390px, 100%);
  padding: 24px;
  box-shadow: 0 18px 40px rgba(23, 32, 38, 0.12);
}

.login-box h1,
.section-header h1,
.chat-header h1,
.form-panel h2 {
  margin: 0;
}

.login-box p,
.section-header p,
.chat-header p,
.helper-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.login-box button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#loginError {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: 260px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.topbar span,
.conversation small,
.ticket-row span,
.user-row span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab.active {
  background: #ecfbf6;
  border-color: var(--accent);
  color: var(--accent);
}

.top-actions,
.actions,
.side-panel header,
.section-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.operator-name {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #f7fafb;
  color: var(--muted);
}

.tab-page {
  display: none;
  min-height: 0;
}

.tab-page.active {
  display: grid;
}

#attendanceTab {
  grid-template-columns: 320px minmax(420px, 1fr) 300px;
  min-height: calc(100vh - 65px);
}

.sidebar,
.side-panel {
  background: var(--panel);
  min-width: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 12px;
}

.side-panel {
  border-left: 1px solid var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.stats strong {
  display: block;
  font-size: 22px;
}

.wide-button {
  width: 100%;
}

.conversation-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.conversation {
  text-align: left;
  border-radius: 8px;
  padding: 12px;
}

.conversation.active {
  border-color: var(--accent);
  background: #ecfbf6;
}

.conversation .top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  background: #e7eef3;
  color: #24445a;
}

.badge.waiting {
  background: #fff3cd;
  color: var(--warn);
}

.badge.ticket_open {
  background: #e4f2ff;
  color: var(--accent-2);
}

.badge.closed {
  background: #f0f2f3;
  color: var(--muted);
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
}

.chat-header {
  padding: 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.messages {
  padding: 18px;
  overflow: auto;
}

.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 15vh;
}

.empty.compact {
  margin: 16px 0;
}

.message {
  max-width: 74%;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.message.out {
  margin-left: auto;
  background: #eaf8f4;
  border-color: #b8e2d6;
}

.message.system {
  max-width: 100%;
  background: #f7fafb;
  color: var(--muted);
}

.message strong {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.35;
}

.composer {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) auto;
  gap: 8px;
  padding: 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.details-box {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.details-box strong {
  color: var(--ink);
  font-size: 15px;
}

.workspace {
  padding: 18px;
  gap: 14px;
  align-content: start;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.report-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.report-filters label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.ticket-table,
.user-list,
.unit-list {
  display: grid;
  gap: 10px;
}

.ticket-row,
.user-row,
.unit-row {
  display: grid;
  grid-template-columns: 1.2fr 1.4fr 0.8fr;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.ticket-row details {
  grid-column: 1 / -1;
}

.ticket-row p {
  margin: 8px 0 0;
}

.report-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.report-cards article,
.grafana-panel {
  border: 1px solid #27323a;
  border-radius: 8px;
  background: #111920;
  color: #edf5f7;
}

.report-cards article {
  padding: 16px;
}

.report-cards strong {
  display: block;
  font-size: 30px;
}

.report-cards span {
  color: #9eb0b8;
  font-size: 13px;
}

.grafana-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.grafana-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  min-height: 260px;
}

.grafana-panel h2 {
  margin: 0;
  font-size: 16px;
  color: #f5c542;
}

.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 36px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #26333c;
}

.bar-track div {
  height: 100%;
  border-radius: inherit;
  background: #29a37a;
}

.integration-flags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.integration-flags span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
}

.integration-flags span.on {
  border-color: #b8e2d6;
  background: #eaf8f4;
  color: var(--accent);
}

.admin-layout,
.whatsapp-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.form-panel {
  padding: 16px;
}

.form-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

.permission-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.zapi-status {
  min-height: 44px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #f7fafb;
  color: var(--muted);
  font-size: 13px;
}

.qr-box {
  min-height: 260px;
  display: grid;
  place-items: center;
  gap: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.qr-box img {
  width: min(260px, 100%);
  aspect-ratio: 1;
  object-fit: contain;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 38, 0.35);
}

.modal-box {
  width: min(520px, 100%);
  padding: 18px;
}

.modal-box h2 {
  margin: 0;
}

.modal-box label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .topbar,
  #attendanceTab,
  .admin-layout,
  .whatsapp-layout,
  .filters,
  .report-filters {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .side-panel {
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat {
    min-height: 70vh;
  }

  .actions,
  .composer,
  .ticket-row,
  .user-row,
  .unit-row,
  .report-cards,
  .grafana-grid {
    grid-template-columns: 1fr;
  }
}
