/* ================================================================
   HELEN — Composition Platform Stylesheet
   Deep navy/slate dark UI · Amber accents · Internal tool aesthetic
   ================================================================ */

/* ── CSS Custom Properties ─────────────────────────────────────── */
:root {
  --bg-deep:       #0f1117;
  --bg-panel:      #1a1d2e;
  --bg-card:       #222638;
  --accent:        #f0a500;
  --accent-hover:  #ffbb33;
  --text-primary:  #f0f2f8;
  --text-muted:    #8b90a8;
  --border:        #2e3250;
  --success:       #22c55e;
  --error:         #ef4444;
  --warning:       #f59e0b;

  --header-height:     56px;
  --meta-bar-height:   52px;
  --action-bar-height: 52px;
  --sidebar-width:     240px;

  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  10px;
  --radius-pill: 999px;

  --font-ui:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: 'Courier New', 'Menlo', 'Monaco', monospace;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.6);

  --transition-fast: 120ms ease;
  --transition-std:  200ms ease;
}

/* ── Reset & Base ───────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ── App Shell ──────────────────────────────────────────────────── */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 24px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

#app-body {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────── */
.header-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.channel-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.channel-btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 16px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  transition: color var(--transition-fast),
              background var(--transition-fast),
              border-color var(--transition-fast);
}

.channel-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.channel-btn.active {
  color: var(--bg-deep);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.channel-btn.active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* ── Sidebar ────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.btn-new-campaign {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  transition: color var(--transition-fast),
              background var(--transition-fast);
}

.btn-new-campaign:hover {
  background: var(--accent);
  color: var(--bg-deep);
}

.campaign-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.campaign-list::-webkit-scrollbar {
  width: 4px;
}

.campaign-list::-webkit-scrollbar-track {
  background: transparent;
}

.campaign-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.campaign-list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

/* Campaign items (rendered by campaigns.js) */
.campaign-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  min-width: 0;
}

.campaign-item:hover {
  background: var(--bg-card);
}

.campaign-item.active {
  background: var(--bg-card);
  border-left-color: var(--accent);
}

.campaign-item__channel-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}

.campaign-item__channel-dot--email     { background: #60a5fa; }
.campaign-item__channel-dot--sms       { background: var(--success); }
.campaign-item__channel-dot--whatsapp  { background: #34d399; }

.campaign-item__title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.campaign-item__meta {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-status {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Main Area ──────────────────────────────────────────────────── */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-deep);
  position: relative;
}

/* ── Stub Banner ────────────────────────────────────────────────── */
.stub-banner {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.stub-banner[hidden] {
  display: none;
}

.stub-banner-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 40px;
}

.stub-banner-icon {
  font-size: 32px;
  color: var(--accent);
  display: block;
}

.stub-banner-msg {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 340px;
  line-height: 1.6;
}

/* ── Editor Container (Unlayer) ─────────────────────────────────── */
#editor-container {
  flex: 1;
  width: 100%;
  min-height: 0;
  background: var(--bg-deep);
  position: relative;
}

/* SMS / WA textarea stub rendered inside #editor-container */
#editor-container .sms-editor,
#editor-container .wa-editor {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 12px;
  background: var(--bg-deep);
}

#editor-container .sms-textarea,
#editor-container .wa-textarea {
  flex: 1;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 14px;
  resize: none;
  outline: none;
  transition: border-color var(--transition-fast);
  line-height: 1.6;
}

#editor-container .sms-textarea:focus,
#editor-container .wa-textarea:focus {
  border-color: var(--accent);
}

.sms-counter {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  display: flex;
  gap: 16px;
  align-items: center;
}

.sms-counter__chars { color: var(--text-primary); }
.sms-counter__segments { }
.sms-counter--warn .sms-counter__chars { color: var(--warning); }
.sms-counter--over .sms-counter__chars { color: var(--error); }

.wa-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* ── Metadata Bar ───────────────────────────────────────────────── */
.meta-bar {
  height: var(--meta-bar-height);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
  overflow: hidden;
}

.meta-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-right: 1px solid var(--border);
  height: 100%;
  flex: 1;
  min-width: 0;
}

.meta-field--from {
  flex: 1.2;
}

.meta-field--stack {
  flex: 0 0 auto;
  width: 180px;
}

.meta-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

.meta-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 3px 0;
  font-size: 12px;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast);
}

.meta-input::placeholder {
  color: var(--text-muted);
}

.meta-input:focus {
  border-bottom-color: var(--accent);
}

.meta-select {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 3px 0;
  font-size: 12px;
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

.meta-select:focus {
  border-bottom-color: var(--accent);
}

.meta-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ── Action Bar ─────────────────────────────────────────────────── */
.action-bar {
  height: var(--action-bar-height);
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast),
              color var(--transition-fast),
              border-color var(--transition-fast),
              opacity var(--transition-fast);
  white-space: nowrap;
  border: 1px solid;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-deep);
  font-weight: 600;
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--bg-card);
  border-color: var(--text-muted);
}

.btn--success {
  background: transparent;
  border-color: var(--success);
  color: var(--success);
}

.btn--danger {
  background: transparent;
  border-color: var(--error);
  color: var(--error);
}

/* ── Button Group (split buttons) ──────────────────────────────── */
.btn-group {
  display: inline-flex;
  position: relative;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  border-right: none;
}

.btn-group__arrow {
  border-radius: 0 var(--radius-md) var(--radius-md) 0 !important;
  padding: 6px 8px;
  border-left: 1px solid var(--border) !important;
}

/* ── Dropdown Menus ─────────────────────────────────────────────── */
.dropdown-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  animation: dropdownIn var(--transition-fast) ease both;
}

.dropdown-menu[hidden] {
  display: none;
}

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

.dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-primary);
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  font-family: var(--font-ui);
}

.dropdown-item:hover {
  background: var(--bg-panel);
  color: var(--accent);
}

/* ── Preflight Result Panel ─────────────────────────────────────── */
.preflight-result {
  position: absolute;
  bottom: calc(var(--action-bar-height) + var(--meta-bar-height) + 10px);
  right: 16px;
  width: 380px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 150;
  animation: panelIn var(--transition-std) ease both;
}

.preflight-result[hidden] {
  display: none;
}

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

.preflight-result::-webkit-scrollbar {
  width: 4px;
}
.preflight-result::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.preflight-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
}

.preflight-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.preflight-title--pass { color: var(--success); }
.preflight-title--fail { color: var(--error); }

.preflight-close {
  font-size: 16px;
  line-height: 1;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.preflight-close:hover {
  color: var(--text-primary);
  background: var(--bg-panel);
}

.preflight-body {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preflight-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.preflight-item--error {
  background: rgba(239,68,68,0.1);
  color: var(--error);
}

.preflight-item--warning {
  background: rgba(245,158,11,0.1);
  color: var(--warning);
}

.preflight-item--ok {
  background: rgba(34,197,94,0.1);
  color: var(--success);
}

.preflight-item__icon {
  font-size: 13px;
  flex-shrink: 0;
  line-height: 1.5;
}

.preflight-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px;
}

/* ── Toast Notifications ────────────────────────────────────────── */
.toast-area {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toastIn 200ms cubic-bezier(0.22, 1, 0.36, 1) both;
  border-left: 3px solid;
  max-width: 360px;
  line-height: 1.4;
}

.toast--success {
  background: var(--bg-card);
  border-color: var(--success);
  color: var(--text-primary);
}

.toast--error {
  background: var(--bg-card);
  border-color: var(--error);
  color: var(--text-primary);
}

.toast--warning {
  background: var(--bg-card);
  border-color: var(--warning);
  color: var(--text-primary);
}

.toast__icon {
  font-size: 14px;
  flex-shrink: 0;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to   { opacity: 0; transform: translateX(20px) scale(0.96); }
}

.toast--exit {
  animation: toastOut 180ms ease both;
}

/* ── Merge tag monospace display ────────────────────────────────── */
.merge-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  color: var(--accent);
}

/* ── Loading spinner ────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Scrollbars (global) ────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Utility ────────────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ── Responsive guard (desktop-only notice) ─────────────────────── */
@media (max-width: 900px) {
  body::before {
    content: 'Helen is designed for desktop. Please use a wider screen.';
    position: fixed;
    inset: 0;
    background: var(--bg-deep);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    z-index: 99999;
    text-align: center;
    padding: 40px;
  }
}
