:root {
  --ink: #18202a;
  --muted: #687382;
  --line: #d9e0e8;
  --soft: #f1f8f5;
  --panel: #ffffff;
  --brand: #16a36f;
  --brand-dark: #0b7d55;
  --whatsapp: #16a36f;
  --whatsapp-dark: #0b7d55;
  --gold: #b58b2a;
  --mint: #2f9d78;
  --blue: #376cb2;
  --danger: #b94242;
  --shadow: 0 14px 36px rgba(24, 32, 42, .08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #edf7f2;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 22px 18px;
  color: #f8fbfd;
  background: #0d1f19;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: var(--radius);
  background: var(--brand);
  font-weight: 800;
}

.brand strong,
.brand span,
.sidebar-footer strong,
.sidebar-footer span {
  display: block;
}

.brand span,
.sidebar-footer span {
  color: #aeb9c5;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  color: #c8d2dc;
  background: transparent;
  text-align: left;
}

.nav-item svg {
  width: 18px;
  height: 18px;
}

.nav-item:hover,
.nav-item.is-active {
  color: #fff;
  background: rgba(22, 163, 111, .22);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .06);
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1,
.panel h2,
.dialog-card h2 {
  margin: 0;
  line-height: 1.15;
}

.topbar h1 {
  font-size: 30px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand-dark);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions,
.toolbar,
.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search {
  width: min(360px, 48vw);
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.search svg {
  width: 17px;
  color: var(--muted);
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  white-space: nowrap;
}

.primary-button {
  padding: 0 14px;
  color: #fff;
  background: var(--brand);
}

.primary-button:hover {
  background: var(--whatsapp-dark);
}

.secondary-button,
.ghost-button {
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.ghost-button {
  color: var(--brand-dark);
}

.icon-button {
  width: 40px;
  padding: 0;
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.status-pill {
  padding: 0 12px;
  color: #0b6b4a;
  border-color: #bfe7d7;
  background: #effaf5;
  font-weight: 800;
}

.status-pill.is-connected {
  color: #fff;
  border-color: var(--whatsapp);
  background: var(--whatsapp);
}

.status-pill.is-warning {
  color: #7b5900;
  border-color: #f0d48a;
  background: #fff8df;
}

button svg {
  width: 17px;
  height: 17px;
}

.view {
  display: none;
}

.view.is-visible {
  display: grid;
  gap: 16px;
}

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

.metric {
  min-height: 118px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric span,
.muted {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--mint);
}

.content-grid {
  display: grid;
  gap: 16px;
}

.two-col {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
}

.conversation-preview {
  display: grid;
  gap: 10px;
}

.preview-item,
.conversation-item {
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  text-align: left;
}

.preview-line,
.conversation-meta,
.chat-head,
.mini-toolbar,
.broadcast-stats,
.template-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.conversation-item.is-active {
  border-color: #8ed8bb;
  background: #f2fbf6;
}

.conversation-item strong,
.preview-item strong {
  overflow-wrap: anywhere;
}

.conversation-meta {
  color: var(--muted);
  font-size: 12px;
}

.unread-dot {
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 99px;
  color: #fff;
  background: var(--whatsapp);
  font-size: 12px;
  font-weight: 800;
}

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.stage-bars,
.report-list,
.task-list,
.task-board {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 130px 1fr 90px;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.bar-track {
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--soft);
}

.bar-fill {
  height: 100%;
  background: var(--whatsapp);
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 99px;
  color: var(--ink);
  background: var(--soft);
  font-size: 12px;
  font-weight: 700;
}

.chip.high {
  color: #fff;
  background: var(--danger);
}

.chip.medium {
  color: #fff;
  background: var(--gold);
}

.chip.low {
  color: #fff;
  background: var(--blue);
}

.toolbar {
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.inbox-layout {
  min-height: calc(100vh - 138px);
  display: grid;
  grid-template-columns: 310px minmax(360px, 1fr) 300px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
}

.conversation-list,
.contact-panel {
  min-width: 0;
  padding: 12px;
  background: #f7fafc;
}

.conversation-list {
  border-right: 1px solid var(--line);
}

.contact-panel {
  border-left: 1px solid var(--line);
}

.mini-toolbar {
  margin-bottom: 10px;
}

.mini-toolbar select {
  width: 100%;
}

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

.chat-head {
  min-height: 70px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  overflow: auto;
}

.message-bubble {
  max-width: min(72%, 560px);
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 5px 14px rgba(24, 32, 42, .04);
}

.message-bubble.agent {
  align-self: flex-end;
  border-color: #c5ead9;
  background: #eaf9f1;
}

.message-bubble small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.quick-replies {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  background: #fff;
}

.quick-replies button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #bfe7d7;
  border-radius: 99px;
  color: #0b6b4a;
  background: #effaf5;
  white-space: nowrap;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.composer input {
  flex: 1;
  min-width: 0;
}

.contact-card {
  display: grid;
  gap: 12px;
}

.contact-section {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

select,
input,
textarea {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline-color: var(--brand);
}

textarea {
  padding-top: 9px;
  resize: vertical;
}

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
  overflow: auto;
}

.segmented button {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.segmented button.is-active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 2px 8px rgba(24, 32, 42, .09);
}

.kanban {
  display: grid;
  grid-template-columns: repeat(5, minmax(260px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.kanban-column {
  min-height: 560px;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid #cfe7dc;
  border-radius: var(--radius);
  background: #f8fcfa;
  box-shadow: var(--shadow);
  transition: border-color .22s ease, background .22s ease, transform .22s ease;
}

.kanban-column.is-drop-target {
  border-color: var(--whatsapp);
  background: #eefaf4;
  transform: translateY(-2px);
}

.kanban-head {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid #d8eee4;
  background: linear-gradient(90deg, #f3fbf7, #ffffff);
}

.pipeline-dropzone {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 470px;
  padding: 12px;
  border: 2px dashed transparent;
  transition: border-color .22s ease, background .22s ease;
}

.kanban-column.is-drop-target .pipeline-dropzone {
  border-color: #8ed8bb;
  background: rgba(22, 163, 111, .06);
}

.pipeline-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.stage-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 99px;
  background: var(--whatsapp);
  box-shadow: 0 0 0 6px rgba(22, 163, 111, .12);
}

.pipeline-title strong,
.pipeline-title span {
  display: block;
}

.pipeline-title span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

@keyframes cardRise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.client-card,
.stone-card,
.task-card,
.user-card,
.report-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.client-card {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
  cursor: grab;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, opacity .18s ease;
  animation: cardRise .24s ease both;
}

.client-card:hover {
  border-color: #bfe7d7;
  box-shadow: 0 12px 28px rgba(13, 125, 85, .1);
  transform: translateY(-2px);
}

.client-card.is-dragging {
  opacity: .55;
  cursor: grabbing;
  transform: scale(.98);
  border-color: var(--whatsapp);
}

.card-actions {
  display: flex;
  gap: 8px;
}

.small-button {
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.inventory-grid,
.user-grid,
.automation-grid,
.template-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stone-card,
.user-card,
.task-card,
.report-row,
.automation-card,
.template-card {
  padding: 14px;
}

.stone-top,
.task-top,
.user-top,
.report-row,
.automation-top,
.template-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.automation-card,
.template-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.automation-card {
  display: grid;
  gap: 12px;
}

.automation-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.automation-steps li {
  padding: 9px 10px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
}

.broadcast-builder {
  display: grid;
  gap: 12px;
}

.broadcast-builder textarea {
  min-height: 180px;
}

.broadcast-stats {
  padding: 12px;
  border-radius: var(--radius);
  color: #0b6b4a;
  background: #effaf5;
  font-weight: 800;
}

.template-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.template-card {
  display: grid;
  gap: 10px;
}

.connect-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid #cfe7dc;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #effaf5, #ffffff);
}

.connect-hero strong,
.connect-hero span {
  display: block;
}

.connect-hero span {
  margin-top: 4px;
  color: var(--muted);
}

.connect-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--radius);
  color: #fff;
  background: var(--whatsapp);
}

.connect-mark svg {
  width: 28px;
  height: 28px;
}

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

.connection-box {
  min-height: 92px;
  padding: 14px;
  border: 1px solid #cfe7dc;
  border-radius: var(--radius);
  background: #f8fcfa;
}

.connection-box span,
.connection-box strong {
  display: block;
}

.connection-box span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.connection-box strong {
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.setup-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.setup-list div {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--soft);
  color: var(--muted);
}

.setup-list svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  color: var(--whatsapp);
}

.stone-specs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.stone-specs span {
  padding: 8px;
  border-radius: 6px;
  background: var(--soft);
  font-size: 12px;
}

.stone-specs strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
}

.task-card {
  display: grid;
  gap: 10px;
}

.task-card.is-overdue {
  border-color: #e1a0a0;
  background: #fff7f7;
}

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

dialog {
  width: min(820px, calc(100vw - 24px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(24, 32, 42, .28);
}

dialog::backdrop {
  background: rgba(15, 22, 31, .48);
}

.dialog-card {
  padding: 18px;
  background: #fff;
}

.qr-dialog-card {
  min-width: min(780px, calc(100vw - 24px));
}

.auth-card {
  max-width: 560px;
}

.auth-error {
  min-height: 20px;
  margin: 0 0 12px;
  color: var(--danger);
  font-weight: 700;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.qr-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.qr-preview-card {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 12px;
  padding: 18px;
  border: 1px solid #cfe7dc;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #f3fbf7, #ffffff);
  text-align: center;
}

.qr-frame {
  width: 248px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 12px;
  border: 1px solid #bfe7d7;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 12px 28px rgba(13, 125, 85, .12);
}

.qr-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qr-controls {
  display: grid;
  gap: 12px;
}

.qr-controls textarea {
  min-height: 118px;
}

.qr-controls input[readonly] {
  color: var(--whatsapp-dark);
  background: #f1fbf6;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.span-2 {
  grid-column: span 2;
}

@media (max-width: 1160px) {
  .metric-grid,
  .inventory-grid,
  .user-grid,
  .automation-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .inbox-layout {
    grid-template-columns: 260px minmax(340px, 1fr);
  }

  .contact-panel {
    display: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    gap: 14px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main {
    padding: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .search {
    width: 100%;
  }

  .metric-grid,
  .inventory-grid,
  .user-grid,
  .automation-grid,
  .template-grid,
  .connection-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .qr-layout {
    grid-template-columns: 1fr;
  }

  .qr-frame {
    width: min(248px, 100%);
  }

  .bar-row {
    grid-template-columns: 92px 1fr;
  }

  .bar-row strong {
    grid-column: 2;
  }

  .inbox-layout {
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .conversation-list {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-panel {
    min-height: 620px;
  }

  .message-bubble {
    max-width: 88%;
  }
}
