:root {
  --bg: #f4efe6;
  --bg-accent: #e7d7c4;
  --panel: rgba(255, 251, 246, 0.82);
  --panel-strong: rgba(255, 249, 243, 0.96);
  --border: rgba(121, 84, 50, 0.16);
  --text: #22170f;
  --muted: #786252;
  --primary: #23443a;
  --primary-contrast: #f6efe5;
  --warning: #9a5d2f;
  --success: #215b44;
  --shadow: 0 24px 64px rgba(48, 27, 13, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 32%),
    radial-gradient(circle at bottom right, rgba(35, 68, 58, 0.12), transparent 30%),
    linear-gradient(160deg, var(--bg), var(--bg-accent));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(34, 23, 15, 0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(34, 23, 15, 0.03) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent);
}

button,
input,
select {
  font: inherit;
}

code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.glass-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-shell,
.app-shell {
  position: relative;
  z-index: 1;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(480px, 100%);
  padding: 40px;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  padding: 24px;
}

.sidebar,
.main-column {
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
}

.sidebar-title,
.hero h2,
.panel h3,
.auth-panel h1 {
  margin: 0;
  line-height: 1;
}

.sidebar-title {
  font-size: 2rem;
}

.hero,
.panel {
  padding: 28px;
}

.main-column {
  display: grid;
  gap: 24px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 0.74rem;
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.92rem;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-link {
  display: block;
  padding: 12px 14px;
  border-radius: 14px;
  color: var(--text);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.35);
}

.nav-link.active {
  background: rgba(35, 68, 58, 0.14);
  color: var(--primary);
  font-weight: 700;
}

.metric-grid,
.content-grid,
.subscribers-layout,
.editor-layout {
  display: grid;
  gap: 20px;
}

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

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

.subscribers-layout {
  display: grid;
  gap: 0;
}

.import-section {
  margin-top: 16px;
}

.import-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 16px;
}

.import-card.inline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.import-card.inline .upload-box {
  display: flex;
  align-items: center;
}

.import-card.inline .upload-box input {
  padding: 8px 12px;
}

.inline-label {
  font-size: 0.9rem;
}

.inline-hint {
  margin: 0;
  font-size: 0.85rem;
}

/* Post Modal */
.post-modal {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  max-width: 100vw;
  max-height: 100vh;
}

.post-modal::backdrop {
  background: rgba(34, 23, 15, 0.55);
  cursor: pointer;
}

.post-modal-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow);
}

.post-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.post-modal-header h3 {
  margin: 0;
}

.post-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-field-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.modal-status-field {
  min-width: 140px;
}

.modal-tabs-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-tabs-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.modal-tab {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}

.modal-tab.active {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}

.modal-tab-add {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  font-family: inherit;
}

.modal-tab-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.format-toolbar {
  display: flex;
  flex-direction: row;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.format-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}

.format-btn:hover {
  background: var(--bg-accent);
  border-color: var(--muted);
}

.format-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}

.emoji-picker {
  position: absolute;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  width: 300px;
  max-height: 320px;
  overflow-y: auto;
  display: none;
  right: 0;
  top: 100%;
}

.emoji-picker.open {
  display: block;
}

.emoji-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
}

.emoji-picker-title {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}

.emoji-picker-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  line-height: 1;
}

.emoji-category {
  padding: 8px;
}

.emoji-category-name {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.emoji-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.1s;
}

.emoji-btn:hover {
  background: var(--bg-accent);
}

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

.modal-image-row {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
  align-items: start;
}

.post-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.posts-table-layout {
  display: grid;
  gap: 20px;
}

.broadcast-screen {
  display: grid;
  gap: 20px;
}

.broadcast-layout {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
}

.metric-card {
  padding: 22px;
  display: grid;
  gap: 8px;
}

.metric-card strong {
  font-size: 2.1rem;
}

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

.panel-head-wrap {
  flex-wrap: wrap;
}

.toolbar-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.field,
.upload-box {
  display: grid;
  gap: 8px;
}

.field span,
.upload-box span {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
}

.field input,
.select,
.upload-box input {
  width: 100%;
  border: 1px solid rgba(120, 98, 82, 0.2);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
}

.stack-lg,
.stack-md {
  display: grid;
}

.stack-lg {
  gap: 18px;
}

.stack-md {
  gap: 14px;
}

.primary-button,
.ghost-button {
  border-radius: 999px;
  padding: 13px 18px;
  border: none;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
}

.primary-button {
  background: var(--primary);
  color: var(--primary-contrast);
}

.ghost-button {
  background: rgba(35, 68, 58, 0.08);
  color: var(--primary);
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled {
  cursor: wait;
  opacity: 0.7;
  transform: none;
}

.ghost-button.danger {
  color: var(--warning);
  background: rgba(154, 93, 47, 0.08);
}

.ghost-button.danger:hover {
  background: rgba(154, 93, 47, 0.14);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  border-radius: 999px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
}

.status-pill.ok {
  background: rgba(33, 91, 68, 0.13);
  color: var(--success);
}

.status-pill.warn {
  background: rgba(154, 93, 47, 0.14);
  color: var(--warning);
}

.status-pill.neutral {
  background: rgba(35, 68, 58, 0.08);
  color: var(--primary);
}

.bot-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.36);
  border: 1px solid rgba(120, 98, 82, 0.12);
}

.bot-summary-primary,
.bot-summary-meta,
.bot-summary-empty {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.bot-summary-empty {
  padding: 18px 20px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.36);
  border: 1px solid rgba(120, 98, 82, 0.12);
}

.bot-summary-name {
  font-size: 1rem;
}

.bot-summary-token {
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(35, 68, 58, 0.08);
  color: var(--primary);
  border: 1px solid rgba(35, 68, 58, 0.1);
  font-size: 0.85rem;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(120, 98, 82, 0.12);
  color: var(--muted);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
}

.import-card,
.table-card {
  background: rgba(255, 255, 255, 0.36);
  border: 1px solid rgba(120, 98, 82, 0.12);
  border-radius: 18px;
  padding: 18px;
}

.subscriber-table-card {
  padding: 14px 18px 18px;
}

.subscriber-filter-grid {
  display: grid;
  grid-template-columns: 1.15fr 1.15fr 0.8fr 0.8fr;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.post-filter-grid {
  display: grid;
  grid-template-columns: 1.6fr 0.8fr 1fr;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.broadcast-filter-grid {
  display: grid;
  grid-template-columns: 0.9fr 1.4fr 1fr 1fr 1fr;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.post-filter-search {
  min-width: 0;
}

.post-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.post-tabs .ghost-button.active {
  background: rgba(35, 68, 58, 0.16);
  color: var(--primary);
}

.subscriber-filter {
  display: grid;
  gap: 6px;
}

.subscriber-filter span {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.subscriber-filter-search {
  grid-column: span 2;
}

.broadcast-filter-search {
  min-width: 0;
}

.subscriber-filter-control,
.subscriber-search {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.94rem;
}

.subscriber-table-card th,
.subscriber-table-card td {
  padding-top: 12px;
  padding-bottom: 12px;
}

.broadcast-language-select {
  position: relative;
}

.broadcast-language-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
}

.broadcast-language-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 12px;
  border: 1px solid rgba(120, 98, 82, 0.16);
  border-radius: 14px;
  background: var(--panel-strong);
  box-shadow: 0 16px 32px rgba(70, 48, 34, 0.12);
}

.broadcast-language-option {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.94rem;
  color: var(--text);
}

.broadcast-language-option input {
  width: 16px;
  height: 16px;
}

.table-sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.table-sort-button.active {
  color: var(--primary);
}

.editor-card,
.localization-card {
  background: rgba(255, 255, 255, 0.36);
  border: 1px solid rgba(120, 98, 82, 0.12);
  border-radius: 18px;
  padding: 18px;
}

.editor-header,
.compact-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.compact-row {
  align-items: center;
}

.small-button {
  padding: 10px 14px;
  font-size: 0.92rem;
}

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

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

textarea {
  width: 100%;
  border: 1px solid rgba(120, 98, 82, 0.2);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  resize: vertical;
}

.upload-preview-row {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
  align-items: start;
  margin-top: 16px;
}

.compact-upload input {
  padding: 10px;
}

.asset-meta {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.inline-link {
  color: var(--primary);
  text-decoration: none;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-weight: 600;
}

.inline-link:hover {
  text-decoration: underline;
}

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

.chip-button {
  border: 1px solid rgba(35, 68, 58, 0.14);
  background: rgba(35, 68, 58, 0.08);
  color: var(--primary);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.detail-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding-bottom: 6px;
}

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

.detail-summary-card {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.44);
  border: 1px solid rgba(120, 98, 82, 0.1);
}

.detail-summary-card strong {
  font-size: 1rem;
}

.detail-summary-wide {
  grid-column: span 2;
}

.compact-section {
  display: grid;
  gap: 8px;
}

.compact-table {
  width: 100%;
  border-collapse: collapse;
}

.compact-table th,
.compact-table td {
  padding: 10px 8px;
  vertical-align: top;
}

.delivery-log-table {
  table-layout: fixed;
}

.delivery-log-table th:nth-child(1),
.delivery-log-table td:nth-child(1) {
  width: 28%;
}

.delivery-log-table th:nth-child(2),
.delivery-log-table td:nth-child(2) {
  width: 14%;
}

.delivery-log-table th:nth-child(3),
.delivery-log-table td:nth-child(3) {
  width: 40%;
}

.delivery-log-table th:nth-child(4),
.delivery-log-table td:nth-child(4) {
  width: 18%;
}

.delivery-log-message {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delivery-log-time {
  white-space: nowrap;
}

.detail-list {
  display: grid;
  gap: 10px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(120, 98, 82, 0.1);
}

.detail-item:last-child {
  border-bottom: none;
}

.detail-item > div {
  display: grid;
  gap: 4px;
}

.detail-log-item {
  align-items: start;
}

.table-stack {
  display: grid;
  gap: 4px;
}

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

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: rgba(35, 68, 58, 0.05);
}

.selected-row {
  background: rgba(35, 68, 58, 0.08);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(120, 98, 82, 0.1);
}

th {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.empty-state {
  color: var(--muted);
  text-align: center;
}

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid transparent;
  min-width: 280px;
  max-width: 400px;
  pointer-events: all;
  cursor: pointer;
  animation: toastIn 0.25s ease-out;
}

.toast.out {
  animation: toastOut 0.25s ease-in forwards;
}

.toast.success {
  background: rgba(33, 91, 68, 0.12);
  border-color: rgba(33, 91, 68, 0.14);
}

.toast.error {
  background: rgba(154, 93, 47, 0.12);
  border-color: rgba(154, 93, 47, 0.14);
}

.toast-close {
  margin-left: auto;
  opacity: 0.5;
  font-size: 14px;
  line-height: 1;
  padding: 2px;
}

.toast-close:hover {
  opacity: 1;
}

/* Subscriber search input */
.subscriber-search {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  width: 100%;
}

/* Pagination bar */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px 4px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination-controls .ghost-button.small {
  padding: 6px 12px;
  font-size: 13px;
}

.broadcast-modal-dialog {
  width: min(640px, 95vw);
}

.broadcast-modal-section {
  display: grid;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(120, 98, 82, 0.08);
}

.broadcast-modal-audience-grid {
  display: grid;
  grid-template-columns: minmax(180px, 0.5fr) minmax(0, 1fr);
  gap: 14px;
  align-items: end;
}

.bot-settings-modal-dialog {
  width: min(560px, 95vw);
}

.delivery-log-modal-dialog {
  width: min(1180px, 98vw);
  max-height: 82vh;
}

@media (max-width: 1100px) {
  .app-shell,
  .metric-grid,
  .content-grid,
  .subscribers-layout,
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }
}

@media (max-width: 720px) {
  .auth-panel,
  .hero,
  .panel,
  .sidebar {
    padding: 22px;
  }

  .hero,
  .panel-head,
  .editor-header,
  .compact-head,
  .detail-item,
  .bot-summary-row {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-row {
    flex-direction: column;
  }

  .subscriber-filter-grid {
    grid-template-columns: 1fr;
  }

  .post-filter-grid {
    grid-template-columns: 1fr;
  }

  .broadcast-filter-grid {
    grid-template-columns: 1fr;
  }

  .broadcast-modal-audience-grid {
    grid-template-columns: 1fr;
  }

  .subscriber-filter-search {
    grid-column: span 1;
  }

  .localization-grid,
  .upload-preview-row {
    grid-template-columns: 1fr;
  }

  .detail-summary-grid {
    grid-template-columns: 1fr 1fr;
  }

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

  th:nth-child(2),
  td:nth-child(2) {
    display: none;
  }
}
