/* ============================================================
   WS · Sender — Editorial Operator
   Cream parchment + warm ink + rust accent.
   Distinctive serif display, mono for data, refined hairlines.
============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;1,9..144,400;1,9..144,500&family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Noto+Sans+SC:wght@400;500;700&family=Noto+Serif+SC:wght@400;700&display=swap');

:root {
  /* Surfaces */
  --bg: #f1ece1;
  --bg-soft: #ebe5d6;
  --surface: #fcfaf3;
  --surface-raised: #fefcf5;

  /* Ink */
  --ink: #1c1a17;
  --ink-soft: #5a554c;
  --ink-mute: #8b8479;
  --ink-faint: #c2b9a6;

  /* Borders */
  --border: #ddd4bf;
  --border-soft: #e8dfca;
  --border-strong: #c9bda0;

  /* Accent — rust */
  --accent: #8b3a1f;
  --accent-deep: #6e2c14;
  --accent-soft: #d6996f;
  --accent-bg: #f3dfc7;

  /* Status */
  --green: #486f3a;
  --green-bg: #dde6cd;
  --red: #973524;
  --red-bg: #f0d3c8;
  --amber: #a16f0e;
  --amber-bg: #f5e3b8;

  /* Highlight */
  --highlight-bg: #faecc7;
  --highlight-ink: #6b4818;

  /* Type */
  --font-display: 'Fraunces', 'Noto Serif SC', Georgia, serif;
  --font-sans: 'DM Sans', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Noto Sans SC', ui-monospace, Consolas, monospace;

  /* Type scale */
  --fs-h1: 22px;
  --fs-h2: 16px;
  --fs-body: 13px;
  --fs-small: 11px;
  --fs-mono-data: 12px;

  /* Radius */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  /* Motion */
  --motion-fast: 120ms cubic-bezier(0.2, 0, 0, 1);
  --motion-mid: 220ms cubic-bezier(0.2, 0, 0, 1);
}

* { box-sizing: border-box; }
*::selection { background: var(--accent-bg); color: var(--accent-deep); }

html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--bg);
  background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 240 240' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1, 0 0 0 0 0.09, 0 0 0 0 0.07, 0 0 0 0.5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.07'/></svg>");
  margin: 0;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body > * { flex: 0 0 auto; }
body > #send-section { flex: 1 1 auto; min-height: 0; }

/* ============================================================
   Header — brand mark + title + user
============================================================ */
header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin: 0;
  position: relative;
  z-index: 100;
}
header h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--fs-h1);
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}
header h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
  letter-spacing: 0;
}

.brand-mark {
  font-family: var(--font-mono);
  font-style: normal;
  font-weight: 600;
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 4px 8px;
  border: 1px solid var(--accent-soft);
  border-radius: 3px;
  white-space: nowrap;
  background: var(--accent-bg);
}

.user-block {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: var(--fs-small);
  font-family: var(--font-mono);
  color: var(--ink-soft);
}
.user-block #username-display {
  color: var(--ink);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Header status pill (agent) — click to reveal menu */
.hdr-status-wrap { position: relative; display: inline-block; }
.hdr-status-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 4px 9px 4px 11px;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion-fast), border-color var(--motion-fast);
}
.hdr-status-btn:hover:not(:disabled) { background: var(--bg-soft); border-color: var(--ink-mute); }
.hdr-status-btn[aria-expanded="true"] {
  background: var(--bg-soft);
  border-color: var(--ink);
}
.hdr-status-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.hdr-status-btn:disabled .status-badge {
  filter: saturate(0.4);
}
.hdr-status-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.hdr-status-btn .status-badge {
  /* slightly tighter inside the pill */
  padding: 2px 8px 2px 7px;
  font-size: 10px;
}

.hdr-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 240px;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: 0 8px 28px rgba(28, 26, 23, 0.14), 0 1px 0 rgba(28, 26, 23, 0.04);
  padding: 6px;
  z-index: 60;
  animation: menu-pop 160ms cubic-bezier(0.2, 0, 0, 1) both;
}
.hdr-menu-wa { min-width: 280px; max-width: 360px; }
.hdr-menu-wa #qr-area {
  margin: 6px 2px 2px;
  padding: 14px 12px;
  background: var(--bg-soft);
  border-radius: var(--r-sm);
  text-align: center;
}
.hdr-menu-wa #qr-area[hidden] { display: none; }
.hdr-menu-wa #login-hint {
  font-size: 11.5px;
  color: var(--ink-soft);
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-style: italic;
}
.hdr-menu-wa #qr-canvas {
  margin: 0 auto;
  background: white;
  padding: 8px;
  border-radius: var(--r-sm);
  box-shadow: 0 1px 2px rgba(28, 26, 23, 0.08);
  max-width: 100%;
  height: auto;
}
.hdr-menu[hidden] { display: none; }
.hdr-menu > button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 3px;
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--ink);
}
.hdr-menu > button:hover:not(:disabled) {
  background: var(--bg-soft);
  border-color: transparent;
}
.hdr-menu > button[hidden] { display: none; }
.hdr-menu-hint {
  padding: 10px 12px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  border-left: 2px solid var(--accent-soft);
  background: var(--bg-soft);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin: 2px;
}
.hdr-menu-hint[hidden] { display: none; }
.hdr-menu-hint a {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  font-weight: 500;
}
.hdr-menu-hint a:hover { color: var(--accent-deep); }

@keyframes menu-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   Buttons
============================================================ */
button {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: 500;
  padding: 7px 14px;
  background: var(--surface-raised);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
}
button:hover:not(:disabled) {
  background: var(--bg-soft);
  border-color: var(--ink-mute);
}
button:active:not(:disabled) { background: var(--bg); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent-deep);
  color: #fbf6e9;
}
button.primary:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

/* ============================================================
   Form elements
============================================================ */
textarea, input[type="text"], input[type="password"], input[type="number"] {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  width: 100%;
  transition: border-color var(--motion-fast), background var(--motion-fast);
}
textarea:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-raised);
}
input[type="number"] { width: 84px; font-family: var(--font-mono); font-feature-settings: 'tnum' 1; }
textarea { resize: vertical; line-height: 1.6; min-height: 96px; }

label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  display: block;
  margin-bottom: 6px;
}

code {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  background: var(--bg-soft);
  border-radius: 3px;
  color: var(--accent-deep);
  font-weight: 500;
}

/* ============================================================
   Cards
============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  margin: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}
.row.between { justify-content: space-between; }
.row.controls { gap: 10px; margin-top: 14px; }

/* ============================================================
   Status badges (filled/empty dot + mono label)
============================================================ */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: transparent;
  line-height: 1.4;
  white-space: nowrap;
}
.status-badge::before {
  content: '●';
  font-size: 9px;
  line-height: 1;
}
.status-online { color: var(--green); background: var(--green-bg); }
.status-online::before { color: var(--green); animation: dot-pulse 2.4s ease-in-out infinite; }
.status-offline { color: var(--red); background: var(--red-bg); }
.status-offline::before { content: '○'; color: var(--red); }

@keyframes dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.9); }
}


/* ============================================================
   QR area / WA login hero
============================================================ */
#qr-area {
  margin-top: 16px;
  padding: 28px 20px 24px;
  background: var(--bg-soft);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  text-align: center;
}
#qr-area #login-hint {
  color: var(--ink-soft);
  font-size: 13px;
  font-family: var(--font-display);
  font-style: italic;
  margin: 0 0 16px;
  letter-spacing: 0.005em;
}
#qr-canvas {
  display: block;
  margin: 12px auto 0;
  background: white;
  padding: 10px;
  border-radius: var(--r-sm);
  box-shadow: 0 1px 2px rgba(28, 26, 23, 0.06);
}
#qr-canvas:not([data-loaded]) { display: none; }

/* ============================================================
   Three-column layout
============================================================ */
.three-col {
  display: grid;
  grid-template-columns: 320px 1fr 1fr;
  gap: 16px;
  align-items: stretch;
  min-height: 0;
}
.three-col[hidden] { display: none; }
.three-col > .card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 1024px) {
  .three-col { grid-template-columns: 1fr; }
}

/* Column section labels */
.three-col > .card[data-label]::before {
  content: attr(data-label);
  display: block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  color: var(--ink-mute);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ============================================================
   Recipients table
============================================================ */
.recipients-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-raised);
}
.recipients-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-mono-data);
  font-family: var(--font-mono);
  font-feature-settings: 'tnum' 1;
}
.recipients-table thead th {
  background: var(--bg-soft);
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.recipients-table th.col-status { width: 56px; text-align: center; }
.recipients-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}
.recipients-table tr:last-child td { border-bottom: 0; }
.recipients-table td:nth-child(1) { width: 36px; color: var(--ink-mute); }
.recipients-table td.status-cell {
  width: 56px;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
}
.recipients-table tr.row-pending { color: var(--ink-mute); }
.recipients-table tr.row-pending td.status-cell::before { content: '·'; color: var(--ink-faint); font-size: 18px; line-height: 0; }
.recipients-table tr.row-sending { background: var(--highlight-bg); color: var(--highlight-ink); font-weight: 500; }
.recipients-table tr.row-sending td.status-cell::before {
  content: '◐';
  color: var(--amber);
  display: inline-block;
  animation: spin 1.6s linear infinite;
}
.recipients-table tr.row-success td.status-cell::before { content: '✓'; color: var(--green); }
.recipients-table tr.row-fail td.status-cell::before { content: '✗'; color: var(--red); }
.recipients-table tr.row-fail td:not(.status-cell) { color: var(--red); }

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

/* file stats text */
#file-stats {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

/* ============================================================
   Template column
============================================================ */
.preview-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  margin-top: 16px;
  margin-bottom: 6px;
}
.preview {
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  padding: 12px 14px;
  border-radius: var(--r-sm);
  white-space: pre-wrap;
  font-size: 14px;
  font-family: var(--font-display);
  color: var(--ink);
  min-height: 30px;
  line-height: 1.55;
}

/* ============================================================
   Progress + Log column
============================================================ */
#progress {
  background: var(--accent-bg);
  border: 1px solid var(--accent-soft);
  padding: 12px 14px;
  border-radius: var(--r-sm);
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-feature-settings: 'tnum' 1;
  color: var(--accent-deep);
}
#progress[hidden] { display: none; }
#progress-text { font-weight: 600; letter-spacing: 0.04em; }
#current-text { margin-top: 4px; opacity: 0.78; font-size: 11.5px; }

.log-section {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.log-section .row.between strong {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-soft);
}
#log-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  background: #1f1c17;
  color: #d6cfba;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.7;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  margin-top: 10px;
  letter-spacing: 0.02em;
  border: 1px solid #2a261f;
}
.log-line { padding: 1px 0; }
.log-line.error { color: #d88a72; }
.log-line.info { color: #b3c79b; }

/* ============================================================
   Login page
============================================================ */
.login-card {
  max-width: 380px;
  margin: 80px auto;
  padding: 32px 36px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  position: relative;
}
.login-card::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 24px;
  right: 24px;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}
.login-card h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 12px;
}
.login-card h1 em { font-style: italic; font-weight: 400; color: var(--accent); }
.login-card .subhead {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--ink-mute);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 0 0 24px;
}
.login-card label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  margin: 16px 0 6px;
}
.login-card .error {
  color: var(--red);
  font-size: 11.5px;
  margin-top: 14px;
  min-height: 18px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.login-card button.primary {
  width: 100%;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ============================================================
   Page-load reveal (subtle stagger)
============================================================ */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
header { animation: fade-up 360ms cubic-bezier(0.2, 0, 0, 1) both; }
#send-section { animation: fade-up 420ms cubic-bezier(0.2, 0, 0, 1) 100ms both; }
.login-card { animation: fade-up 420ms cubic-bezier(0.2, 0, 0, 1) both; }
