:root {
  --ink: #14241c;
  --ink-soft: #3d5348;
  --paper: #f3efe4;
  --card: #fffdf7;
  --line: #d8d0bf;
  --gold: #c3921a;
  --gold-deep: #8c6810;
  --green: #2f6a4a;
  --danger: #9b2c2c;
  --shadow: 0 18px 40px rgba(20, 36, 28, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Poppins, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

h1, h2, strong { font-family: Poppins, "Segoe UI", sans-serif; }

button, input, textarea {
  font: inherit;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 10% 10%, #e7d7a3 0, transparent 28%),
    radial-gradient(circle at 90% 80%, #c9d7c4 0, transparent 32%),
    var(--paper);
}

.auth-card, .composer, .card, .table-wrap, .qr-box {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(420px, calc(100% - 32px));
  padding: 36px;
  border-radius: 22px;
}

.eyebrow, .label {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--gold-deep);
  font-weight: 600;
}

h1 { margin: 0 0 8px; font-size: 36px; }
.lede, .hint { color: var(--ink-soft); line-height: 1.5; }

label, .label { display: block; font-weight: 500; }

input, textarea {
  width: 100%;
  margin: 6px 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.linkish {
  background: none;
  color: var(--gold-deep);
  padding: 0;
}

.form-error { color: var(--danger); }

body:not(.auth-body) {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--ink);
  color: #e8eadf;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
}

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand small { display: block; color: #b7c4b8; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--gold);
  color: var(--ink);
  font-family: Poppins, sans-serif;
  font-weight: 700;
}

nav { display: grid; gap: 6px; }
nav button {
  text-align: left;
  background: transparent;
  color: #d7ddd4;
  border-radius: 12px;
}
nav button.active, nav button:hover { background: rgba(255,255,255,0.08); color: #fff; }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.workspace { padding: 36px 40px 64px; }
.panel { display: none; }
.panel.active { display: block; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.card, .composer {
  padding: 20px;
  border-radius: 18px;
}

.card-list { display: grid; gap: 14px; }
.card-top { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.muted { color: var(--ink-soft); font-size: 14px; }

.status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #ece6d6;
}
.status.connected, .status.sent, .status.completed { background: #d9eadf; color: var(--green); }
.status.qr, .status.scheduled, .status.sending, .status.partial { background: #f3e3b8; color: var(--gold-deep); }
.status.banned, .status.failed { background: #f3d4d4; color: var(--danger); }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions button { padding: 8px 12px; }

.table-wrap { overflow: auto; border-radius: 18px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}
.toolbar input[type="search"],
.toolbar select {
  width: min(360px, 100%);
  margin: 0;
}
.toolbar select {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.toolbar .muted { margin: 0; }
.toolbar .row-actions { margin-left: auto; }

.composer { margin-bottom: 24px; }
.form-section {
  margin: 0 0 36px;
  padding: 22px 0 8px;
  border-top: 1px solid var(--line);
}
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-section .label { margin-bottom: 12px; }
.form-section .muted { margin: 0 0 14px; }
.composer-grid { display: grid; grid-template-columns: 1fr 240px; gap: 16px; }
.mode-switch { display: flex; gap: 8px; margin-bottom: 18px; }
.mode-switch button {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.mode-switch button.active { background: var(--ink); color: #fff; }
.offer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.offer-grid .full { grid-column: 1 / -1; }
.offer-grid select { width: 100%; margin: 6px 0 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.offer-toggles { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
#offer-preview { min-height: 120px; margin: 0; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 18px; max-height: 280px; overflow: auto; }
.chip-list.compact { max-height: none; margin: 12px 0 0; }
.chip.plain { background: #f6f1e4; }

.editor { margin-bottom: 8px; }
.editor textarea { margin-bottom: 8px; min-height: 140px; }
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.editor-toolbar button,
.attach-btn {
  padding: 8px 12px;
  min-width: 40px;
}
.attach-btn { display: inline-flex; align-items: center; cursor: pointer; }
.attach-btn input { display: none; }
.editor-foot { margin-bottom: 16px; }
.wa-preview {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #e8efe6;
  white-space: pre-wrap;
  line-height: 1.5;
}
.wa-preview code {
  font-family: Consolas, monospace;
  background: rgba(20, 36, 28, 0.08);
  padding: 1px 4px;
  border-radius: 4px;
}
.media-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.media-preview img,
.media-preview video {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
}
.card-media {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 12px;
  background: #ece6d6;
}
.card-body { display: grid; gap: 8px; }
.chip {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}
.chip input { width: auto; margin: 0; }

dialog {
  border: 0;
  border-radius: 22px;
  padding: 0;
  background: transparent;
}
dialog::backdrop { background: rgba(20, 36, 28, 0.45); }
.qr-box { padding: 28px; text-align: center; min-width: min(360px, 90vw); }
.qr-box img { width: 240px; height: 240px; margin: 12px 0; }

@media (max-width: 860px) {
  body:not(.auth-body) { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; gap: 16px; }
  nav { grid-auto-flow: column; overflow: auto; }
  .sidebar-foot { width: 100%; }
  .workspace { padding: 24px 16px 48px; }
  .composer-grid,
  .offer-grid { grid-template-columns: 1fr; }
}
