:root {
  --bg: #f6f8fc;
  --ink: #0f172a;
  --muted: #475569;
  --panel: #ffffff;
  --line: #dbe4f0;
  --accent: #0f766e;
  --accent-2: #0284c7;
  --warn: #dc2626;
  --ok: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Cairo", sans-serif;
  background:
    radial-gradient(circle at 0% 0%, rgba(59, 130, 246, 0.08), transparent 34%),
    radial-gradient(circle at 100% 100%, rgba(16, 185, 129, 0.07), transparent 34%),
    linear-gradient(180deg, #f9fbff 0%, var(--bg) 100%);
}

.layout {
  width: min(1260px, 95%);
  margin: 18px auto 34px;
}

.hero {
  background: linear-gradient(135deg, #f9fcff 0%, #eef5ff 68%, #ecfdf7 100%);
  color: var(--ink);
  border-radius: 24px;
  border: 1px solid #d8e4f1;
  padding: 26px;
  margin-bottom: 14px;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.08);
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.hero-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  letter-spacing: 1.6px;
  font-size: 12px;
  opacity: 0.75;
}

h1 {
  margin: 0;
  font-family: "Changa", sans-serif;
  font-size: clamp(22px, 3.2vw, 38px);
  line-height: 1.2;
}

.subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 760px;
  font-size: 15px;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  justify-content: flex-start;
  min-width: 165px;
}

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

.top-tab {
  text-decoration: none;
  color: #1e3a5f;
  border: 1px solid #c7d7ea;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 13px;
}

.top-tab.active {
  background: #e0edff;
  border-color: #9ebbe3;
  color: #0b2a4d;
}

.me-badge {
  margin: 0;
  font-size: 13px;
  color: #334155;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.status-card {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
}

.label {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.value {
  margin: 5px 0 0;
  font-size: 18px;
  font-weight: 800;
  word-break: break-word;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
}

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

h2 {
  margin: 0;
  font-family: "Changa", sans-serif;
  font-size: 22px;
}

h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.panel-desc {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-page {
  display: grid;
  gap: 14px;
}

.settings-page .hero {
  margin-bottom: 2px;
}

.settings-section {
  border-color: #cfdae8;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  box-shadow: 0 6px 16px rgba(15, 35, 63, 0.06);
}

.settings-section-highlight {
  border-color: #bdd0e6;
}

.settings-page .panel-head {
  margin-bottom: 14px;
}

.settings-page .panel-head h2 {
  font-size: 20px;
}

.settings-page .auto-form input,
.settings-page .auto-form select,
.settings-page .auto-form textarea {
  background: #fdfefe;
  border-color: #c8d7e8;
}

.settings-page .auto-form input:focus,
.settings-page .auto-form select:focus,
.settings-page .auto-form textarea:focus {
  outline: 0;
  border-color: #77a9d8;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}

.settings-page .table-wrap {
  border-color: #d8e3ef;
}

.settings-page thead th {
  background: #eef5fc;
}

.smart-reply-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(260px, 0.85fr);
  gap: 12px;
  align-items: start;
}

.smart-reply-config-col {
  display: grid;
  gap: 10px;
}

.smart-form {
  background: #f8fbff;
  border: 1px solid #d7e5f3;
  border-radius: 14px;
  padding: 12px;
}

.smart-reply-help {
  border: 1px solid #d7e5f3;
  border-radius: 14px;
  background: #f8fbff;
  padding: 12px;
}

.smart-reply-help h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.smart-flow-list {
  margin: 8px 0;
  padding-inline-start: 20px;
  color: #314a66;
  font-size: 13px;
  line-height: 1.7;
}

.smart-preview-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  border: 1px solid #d7e5f3;
  border-radius: 12px;
  background: #f8fbff;
  padding: 10px;
}

.contacts-page {
  display: grid;
  gap: 14px;
}

.contacts-layout-panel {
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

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

.group-toolbar input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
}

button {
  border: 0;
  border-radius: 11px;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 9px 14px;
  font-family: inherit;
  transition: transform 0.15s ease, filter 0.2s ease;
}

button:hover {
  filter: brightness(0.95);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
  filter: none;
}

.ghostBtn {
  background: #f8fbff;
  border: 1px solid #ccd9ea;
  color: #1e293b;
}

#clearQrBtn,
.deleteBtn {
  background: var(--warn);
}

.primaryBtn {
  background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
}

.link-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.toggleBtn {
  background: #475569;
}

.editBtn {
  background: var(--ok);
}

.smallBtn {
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 12px;
  margin-left: 6px;
}

#qrBox {
  width: 100%;
  min-height: 260px;
  border: 1px dashed #9fb5cd;
  border-radius: 14px;
  background: #f8fbff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  color: #466286;
}

#connectedPhoneInput {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-family: "Cairo", sans-serif;
  margin-bottom: 10px;
  background: #f8fbff;
}

#qrText {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 10px;
  font-family: "Courier New", monospace;
}

.hint {
  margin: 0 0 6px;
}

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

.auto-form.wide {
  grid-template-columns: 1fr 2fr 0.9fr 110px auto;
}

.auto-form input,
.auto-form select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: inherit;
}

.auto-form textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: "Courier New", monospace;
  grid-column: span 4;
}

#smartReplyFallbackInput {
  min-height: 90px;
  font-family: inherit;
}

#smartReplyIntentsInput {
  min-height: 260px;
  font-family: "Courier New", monospace;
}

#smartReplyPreviewResult {
  white-space: pre-line;
}

#campaignForm {
  grid-template-columns: 1fr 1fr 1fr 1fr auto;
}

#campaignMessageInput {
  grid-column: 1 / -2;
  min-height: 170px;
  font-family: inherit;
}

.checkbox-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.field-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-block > span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.field-block-wide {
  grid-column: span 4;
}

.contacts-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 10px;
}

.groups-sidebar {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #f8fbff;
}

.groups-sidebar h3 {
  margin: 0 0 8px;
}

.groups-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
}

.hours-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(90px, 1fr));
  gap: 6px;
}

.hour-btn {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 8px;
  font-size: 12px;
  color: #0f172a;
}

.hour-btn.active {
  background: #d1fae5;
  border-color: #34d399;
}

.hour-btn.inactive {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #64748b;
}

.campaign-timing {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbff;
  padding: 10px;
}

.campaign-timing h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}

.campaign-timing-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(170px, 1fr));
  gap: 8px;
}

.campaign-timing-grid input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: inherit;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #dde6f1;
  border-radius: 12px;
}

.table-wrap.tight {
  max-height: 330px;
}

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

thead th {
  position: sticky;
  top: 0;
  background: #f3f7fd;
  z-index: 1;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid #e3ebf5;
  text-align: right;
  vertical-align: top;
  font-size: 14px;
}

tbody tr:nth-child(even) {
  background: #fcfdff;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.inbox-tools input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
}

.chat-box {
  border: 1px solid #e0e8f1;
  border-radius: 12px;
  padding: 10px;
  background: #f8fbff;
}

.chat-messages {
  max-height: 300px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.msg {
  border: 1px solid #dbe7f3;
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.msg.outbound {
  border-color: #a7f3d0;
  background: #ecfdf5;
}

.chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.chat-compose textarea {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-family: inherit;
  resize: vertical;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}

.metric {
  border: 1px solid #d7e4f1;
  border-radius: 12px;
  padding: 10px;
  background: #f8fbff;
}

.metric span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.metric strong {
  font-size: 24px;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-overlay.show {
  display: flex;
}

.wa-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 950;
  padding: 16px;
}

.wa-modal-overlay.show {
  display: flex;
}

.wa-modal-card {
  width: min(760px, 96vw);
  max-height: 94vh;
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.24);
  padding: 16px;
}

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

.wa-close-btn {
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  color: #1e293b;
}

.auth-card {
  width: min(420px, 92%);
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 20px;
  display: grid;
  gap: 10px;
}

.auth-card h2 {
  margin: 0;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-card input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px;
}

.error-text {
  color: #b91c1c;
  min-height: 18px;
}

.connection-banner {
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  font-weight: 700;
  margin-bottom: 10px;
}

.connection-banner.connected {
  color: #14532d;
  border-color: #86efac;
  background: #f0fdf4;
}

.connection-banner.disconnected {
  color: #92400e;
  border-color: #fcd34d;
  background: #fffbeb;
}

.connect-delay-msg {
  margin: 0 0 10px;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 700;
}

.connect-delay-msg.hidden {
  display: none;
}

.qr-connected {
  text-align: center;
  color: #166534;
  font-weight: 700;
  line-height: 1.8;
}

@media (max-width: 1100px) {
  .status-strip {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .layout {
    width: min(1260px, 97%);
  }

  .hero {
    flex-direction: column;
    border-radius: 18px;
    padding: 18px;
  }

  .hero-main,
  .hero-actions {
    width: 100%;
  }

  .hero-actions {
    align-items: flex-start;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .auto-form,
  .auto-form.wide,
  .smart-reply-layout,
  .smart-preview-box,
  .group-toolbar,
  .contacts-layout,
  .split,
  .metrics-grid,
  .chat-compose,
  .inbox-tools {
    grid-template-columns: 1fr;
  }

  .hours-grid {
    grid-template-columns: repeat(3, minmax(90px, 1fr));
  }

  .campaign-timing-grid {
    grid-template-columns: 1fr;
  }

  .smallBtn {
    margin-bottom: 4px;
  }
}
