/* ==========================================================================
   FollowUp AI — design layer
   Loaded after the inline <style> blocks, so it refines without a rewrite.
   Everything here reads from the tokens below; change a token, not a rule.
   ========================================================================== */

:root {
  /* Brand — the WhatsApp-adjacent greens the product already used */
  --c-brand-900: #04443c;
  --c-brand-800: #075e54;
  --c-brand-600: #12876f;
  --c-accent:    #25d366;
  --c-accent-600:#1dbb57;

  /* Neutrals — one ramp, replacing the ad-hoc #888/#555/#333/#eee/#ddd set */
  --c-ink:       #10231f;
  --c-ink-2:     #47554f;
  --c-ink-3:     #78867f;
  --c-line:      #e6ebe8;
  --c-surface:   #ffffff;
  --c-bg:        #f4f7f6;

  /* Status */
  --c-warn-bg:   #fff8e6;
  --c-warn-ink:  #8a6100;
  --c-info-bg:   #e8f1fd;
  --c-info-ink:  #1a5fb4;
  --c-danger:    #c62828;

  /* Type scale */
  --t-xs: 0.75rem;
  --t-sm: 0.85rem;
  --t-md: 0.95rem;
  --t-lg: 1.15rem;
  --t-xl: 1.6rem;

  /* Spacing — 4px base */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 999px;

  --shadow-1: 0 1px 2px rgba(16, 35, 31, 0.06);
  --shadow-2: 0 2px 8px rgba(16, 35, 31, 0.08);
  --shadow-3: 0 8px 28px rgba(16, 35, 31, 0.14);
}

body {
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Rubik, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* --- Header ------------------------------------------------------------ */

.header {
  background: linear-gradient(180deg, var(--c-brand-800), var(--c-brand-900));
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow-2);
}
.header h1 { font-size: var(--t-md); letter-spacing: -0.01em; }
.header p  { font-size: var(--t-xs); opacity: 0.7; }

.btn-new-main {
  background: var(--c-accent);
  border-radius: var(--r-full);
  padding: var(--s-2) var(--s-4);
  font-size: var(--t-sm);
  box-shadow: var(--shadow-1);
  transition: background 0.15s ease, transform 0.15s ease;
}
.btn-new-main:hover { background: var(--c-accent-600); transform: translateY(-1px); }
.btn-new-main:active { transform: translateY(0); }

.btn-lang { border-radius: var(--r-full); font-size: var(--t-xs); }

/* --- Stats ------------------------------------------------------------- */

.crm-container { padding: var(--s-4); }
.crm-stats { gap: var(--s-3); margin-bottom: var(--s-4); }

.stat-card {
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow-1);
  border: 1px solid var(--c-line);
}
.stat-num   { font-size: var(--t-xl); color: var(--c-brand-800); line-height: 1.1; }
.stat-label { font-size: var(--t-xs); color: var(--c-ink-3); }

/* --- CRM list ---------------------------------------------------------- */

.crm-table-wrap {
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  border: 1px solid var(--c-line);
}
.crm-table th {
  background: transparent;
  color: var(--c-ink-3);
  font-size: var(--t-xs);
  letter-spacing: 0.02em;
  padding: var(--s-3);
  border-bottom: 1px solid var(--c-line);
}
.crm-table td {
  padding: var(--s-3);
  font-size: var(--t-sm);
  color: var(--c-ink-2);
  border-bottom: 1px solid var(--c-line);
}
.crm-table .customer-cell { color: var(--c-ink); font-weight: 600; }
.crm-table tr:hover td { background: #f7fbf9; }

/* Phones are data, not links to click through */
.phone-cell { color: var(--c-ink-2); font-variant-numeric: tabular-nums; }

.tone-badge {
  border-radius: var(--r-full);
  padding: 2px var(--s-2);
  font-size: var(--t-xs);
  font-weight: 600;
}

/* Mobile: a horizontally scrolling 640px table hides status and actions
   off-screen. Below 720px each row becomes a card instead. */
@media (max-width: 720px) {
  .crm-table { min-width: 0; }
  .crm-table thead { display: none; }
  .crm-table, .crm-table tbody, .crm-table tr, .crm-table td { display: block; width: 100%; }

  .crm-table-wrap {
    background: transparent;
    border: none;
    box-shadow: none;
    overflow-x: visible;
  }
  .crm-table tr {
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-1);
    padding: var(--s-3);
    margin-bottom: var(--s-3);
  }
  .crm-table tr:hover td { background: transparent; }
  .crm-table td {
    border-bottom: none;
    padding: var(--s-1) 0;
    max-width: none !important;
    white-space: normal !important;
    overflow: visible !important;
  }

  /* Name leads the card */
  .crm-table td.customer-cell { font-size: var(--t-lg); font-weight: 700; }

  /* Label the rest, so a value is never orphaned from its meaning.
     Label pinned to the start edge, value to the end edge — the pairing
     stays readable in both RTL and LTR. */
  .crm-table td[data-label] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    min-height: 30px;
  }
  .crm-table td[data-label]::before {
    content: attr(data-label);
    color: var(--c-ink-3);
    font-size: var(--t-xs);
    font-weight: 600;
    flex-shrink: 0;
  }
  .crm-table td.want-cell { text-align: end; }

  /* Actions get their own row along the bottom of the card */
  .crm-table td.actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
    align-items: center;
    margin-top: var(--s-2);
    padding-top: var(--s-3);
    border-top: 1px solid var(--c-line);
  }
  .crm-table td.actions-cell .btn-wa-small { margin-inline-start: auto; }
}

/* --- Controls ---------------------------------------------------------- */

.status-select {
  border: 1px solid var(--c-line);
  border-radius: var(--r-sm);
  padding: var(--s-1) var(--s-2);
  font-size: var(--t-xs);
  color: var(--c-ink-2);
  background: var(--c-surface);
}

.btn-view, .btn-edit, .btn-delete {
  border: 1px solid var(--c-line);
  background: var(--c-surface);
  border-radius: var(--r-sm);
  /* 36px keeps every tap target above the 44px-with-margin comfort line */
  min-width: 36px;
  min-height: 36px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.btn-view:hover, .btn-edit:hover { border-color: var(--c-brand-600); background: #f3faf7; }
.btn-delete:hover { border-color: var(--c-danger); background: #fdf3f3; }

.btn-wa-small {
  background: var(--c-accent);
  color: #fff;
  border-radius: var(--r-full);
  padding: var(--s-2) var(--s-3);
  font-size: var(--t-xs);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.btn-wa-small:hover { background: var(--c-accent-600); }

/* --- Auth modal -------------------------------------------------------- */

.auth-input {
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  font-size: var(--t-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.auth-input:focus {
  outline: none;
  border-color: var(--c-brand-600);
  box-shadow: 0 0 0 3px rgba(18, 135, 111, 0.15);
}

/* Visible keyboard focus everywhere, not just in the modal */
:where(button, a, select, input, textarea):focus-visible {
  outline: 2px solid var(--c-brand-600);
  outline-offset: 2px;
}

/* --- New-followup panel: upload state ---------------------------------- */

.panel-body { padding-bottom: var(--s-6); }

.upload-area {
  border: 1.5px dashed #b9d8c9;
  border-radius: var(--r-lg);
  background: var(--c-surface);
  padding: var(--s-6) var(--s-4);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.upload-area:hover,
.upload-area:focus-within { border-color: var(--c-accent); background: #f6fdf9; }
.upload-area.has-file { border-style: solid; border-color: var(--c-accent); background: #f6fdf9; }
.upload-icon { font-size: 2em; margin-bottom: var(--s-2); opacity: 0.9; }
.upload-text { color: var(--c-ink-3); font-size: var(--t-sm); line-height: 1.6; }
.upload-text strong { color: var(--c-ink); font-size: var(--t-md); display: inline-block; margin-bottom: 2px; }

.input-group label { color: var(--c-ink-2); font-size: var(--t-sm); }
.input-group input {
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
}
.input-group input:focus {
  border-color: var(--c-brand-600);
  box-shadow: 0 0 0 3px rgba(18, 135, 111, 0.15);
}
.phone-hint { color: var(--c-ink-3); font-size: var(--t-xs); }

.btn-analyze {
  border-radius: var(--r-md);
  padding: var(--s-4);
  box-shadow: var(--shadow-2);
  transition: background 0.15s ease, transform 0.15s ease;
}
.btn-analyze:hover { transform: translateY(-1px); }
.btn-analyze:active { transform: translateY(0); }

/* --- New-followup panel: result state ---------------------------------- */

/* The customer's name is the anchor of this screen, so it leads it. */
.result-section > div:first-child {
  font-size: var(--t-lg) !important;
  font-weight: 800 !important;
  color: var(--c-ink) !important;
  margin-bottom: var(--s-4) !important;
}

.analysis-grid { gap: var(--s-2); margin-bottom: var(--s-3); }
.analysis-item {
  background: var(--c-bg);
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  padding: var(--s-3);
}
.analysis-label {
  font-size: var(--t-xs);
  color: var(--c-ink-3);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: var(--s-1);
}
.analysis-value { font-size: var(--t-sm); color: var(--c-ink); line-height: 1.45; }

#r-phone { font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }

/* The generated message is the thing the user came for. Everything above
   is context; this gets the weight, the space, and the line length. */
.message-label {
  font-size: var(--t-xs);
  color: var(--c-ink-3);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: var(--s-2);
}
.message-box {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-inline-start: 3px solid var(--c-accent);
  border-radius: var(--r-md);
  padding: var(--s-4);
  font-size: var(--t-md);
  line-height: 1.7;
  color: var(--c-ink);
  text-align: start;
  box-shadow: var(--shadow-1);
  margin-bottom: var(--s-3);
}

.edit-btn {
  border: 1px solid var(--c-line);
  border-radius: var(--r-full);
  padding: var(--s-2) var(--s-3);
  font-size: var(--t-xs);
  color: var(--c-ink-2);
  background: var(--c-surface);
}
.edit-btn:hover { border-color: var(--c-brand-600); color: var(--c-brand-800); }

.message-edit {
  border-color: var(--c-line);
  border-radius: var(--r-md);
  padding: var(--s-4);
  font-size: var(--t-md);
  line-height: 1.7;
  font-family: inherit;
}
.message-edit:focus {
  outline: none;
  border-color: var(--c-brand-600);
  box-shadow: 0 0 0 3px rgba(18, 135, 111, 0.15);
}

.btn-whatsapp {
  border-radius: var(--r-md);
  padding: var(--s-4);
  box-shadow: 0 4px 14px rgba(37, 211, 102, 0.35);
  transition: background 0.15s ease, transform 0.15s ease;
}
.btn-whatsapp:hover { transform: translateY(-1px); }
.btn-whatsapp:active { transform: translateY(0); }

.btn-another {
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  padding: var(--s-3);
  color: var(--c-ink-2);
  font-size: var(--t-sm);
}
.btn-another:hover { background: var(--c-bg); border-color: var(--c-brand-600); color: var(--c-brand-800); }

/* Loading */
.spinner { border-color: var(--c-line); border-top-color: var(--c-accent); }
.loading-text { color: var(--c-ink-2); font-size: var(--t-md); }
.loading-step { color: var(--c-ink-3); font-size: var(--t-sm); }

.error-msg {
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  font-size: var(--t-sm);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
