/* WA Manager — mobile-first base styles */
:root {
  --c-bg:         #f5f6f8;
  --c-surface:    #ffffff;
  --c-surface-2:  #fafbfc;
  --c-text:       #1b1f23;
  --c-muted:      #5b6470;
  --c-border:     #e3e6ea;
  --c-primary:    #0b6d4e;
  --c-primary-2:  #088061;
  --c-error-bg:   #fdeaea;
  --c-error-fg:   #9b1c1c;
  --c-bubble-in:  #ffffff;
  --c-bubble-out: #d8f4dd;
  --c-status-read:#3b82f6;
  --r:            10px;
  --gap:          12px;
  --maxw:         1100px;
  --shadow-sm:    0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 16px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --c-bg:         #0e1014;
    --c-surface:    #16191f;
    --c-surface-2:  #1c2027;
    --c-text:       #e7eaef;
    --c-muted:      #8b95a3;
    --c-border:     #262b34;
    --c-primary:    #2fbb8b;
    --c-primary-2:  #36cc99;
    --c-error-bg:   #3a1e1e;
    --c-error-fg:   #f3a3a3;
    --c-bubble-in:  #1c2027;
    --c-bubble-out: #1d3b30;
    --c-status-read:#60a5fa;
    --shadow-sm:    0 1px 2px rgba(0,0,0,.4);
    --shadow-md:    0 4px 16px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--c-muted); }
.error {
  background: var(--c-error-bg); color: var(--c-error-fg);
  padding: 10px 12px; border-radius: var(--r); margin: 8px 0;
}

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 700; color: var(--c-text); margin-right: 8px; }
.topbar .nav { display: flex; gap: 12px; flex: 1; min-width: 0; overflow-x: auto; }
.topbar .actions { display: flex; gap: 10px; align-items: center; }
.topbar .me { font-size: 14px; color: var(--c-muted); display: none; }
@media (min-width: 600px) {
  .topbar .me { display: inline; }
}
.lang {
  font-size: 12px; padding: 4px 8px; border: 1px solid var(--c-border);
  border-radius: 999px; color: var(--c-text);
}

/* ---- main ---- */
.main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px;
}
.page h1 { margin: 0 0 6px; font-size: 22px; }
.page h2 { margin: 22px 0 10px; font-size: 16px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; }
.role {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: rgba(11,109,78,.08); color: var(--c-primary);
  font-size: 12px; vertical-align: middle;
}

/* ---- cards (dashboard) ---- */
.cards {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.card.wide { grid-column: 1 / -1; }
.card-label { font-size: 12px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.card-value.small { font-size: 16px; font-weight: 500; }

/* ---- login ---- */
.login-body {
  background: linear-gradient(160deg, #0b6d4e 0%, #044d3a 100%);
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  position: relative;
  background: var(--c-surface);
  width: 100%; max-width: 360px;
  padding: 26px 22px;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card .muted { margin: 4px 0 18px; }
.login-card .lang-corner { position: absolute; top: 12px; right: 12px; }
.login-card label { display: block; margin: 12px 0; }
.login-card label > span { display: block; font-size: 13px; color: var(--c-muted); margin-bottom: 4px; }
.login-card input {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--c-border); border-radius: var(--r);
  background: #fff;
}
.login-card input:focus { outline: 2px solid var(--c-primary); outline-offset: 1px; }
button.primary {
  width: 100%; padding: 11px; margin-top: 8px;
  font-size: 16px; font-weight: 600;
  border: 0; border-radius: var(--r);
  color: white; background: var(--c-primary);
  cursor: pointer;
}
button.primary:hover { background: var(--c-primary-2); }
button.primary:disabled { background: var(--c-muted); cursor: not-allowed; opacity: .8; }

/* ---- logout button (form-disguised-as-link) ---- */
.logout-form { margin: 0; }
button.logout {
  background: none; border: 1px solid var(--c-border); cursor: pointer;
  color: var(--c-muted); padding: 4px 10px; border-radius: 999px;
  font-size: 13px;
}
button.logout:hover { color: var(--c-text); border-color: var(--c-text); }

/* ---- page head & filter bar ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.filter-toggle { background: var(--c-surface); border: 1px solid var(--c-border); padding: 4px 10px; }
.filter-toggle .badge { display: inline-block; min-width: 16px; padding: 0 6px; margin-left: 4px;
  border-radius: 999px; background: var(--c-primary); color: white; font-size: 11px; line-height: 16px; }
.search-main {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--c-border); border-radius: var(--r);
  background: var(--c-surface); color: var(--c-text);
  margin: 8px 0;
}
.filter-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px; padding: 10px; background: var(--c-surface-2);
  border: 1px solid var(--c-border); border-radius: var(--r);
  margin-bottom: 12px;
}
.filter-bar.inline { margin: 0 0 8px; }
.filter-bar .f { display: flex; flex-direction: column; gap: 3px; }
.filter-bar .f > span { font-size: 11px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; }
.filter-bar select, .filter-bar input[type=text], .filter-bar input[type=date] {
  padding: 6px 8px; font-size: 13px;
  border: 1px solid var(--c-border); border-radius: 6px;
  background: var(--c-surface); color: var(--c-text);
}
.filter-bar .checkbox { flex-direction: row; align-items: center; gap: 6px; }
.filter-bar .checkbox input { transform: scale(1.1); margin: 0; }
.filter-bar .filter-actions { display: flex; gap: 8px; align-items: center; grid-column: 1 / -1; }
.filter-bar .filter-actions button { width: auto; margin: 0; padding: 6px 14px; }
.filter-bar .filter-actions .reset { font-size: 13px; color: var(--c-muted); }

.chats-page .chats-search input.search-main { margin: 0 0 8px; }
.chat-filters { padding: 0 14px; background: var(--c-surface-2); border-bottom: 1px solid var(--c-border); }
.chat-filters .search-main { margin: 8px 0; }

/* ---- chats list ---- */
.chats-page .chats-search input {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--c-border); border-radius: var(--r);
  background: var(--c-surface); color: var(--c-text);
  margin: 4px 0 14px;
}
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-row { border-bottom: 1px solid var(--c-border); }
.conv-link {
  display: flex; gap: 12px; padding: 10px 4px;
  color: var(--c-text); text-decoration: none;
}
.conv-link:hover { text-decoration: none; background: var(--c-surface-2); }
.conv-avatar {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-2) 100%);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
}
.conv-body { flex: 1; min-width: 0; }
.conv-top {
  display: flex; align-items: baseline; gap: 8px; justify-content: space-between;
}
.conv-name { font-weight: 600; }
.conv-time { color: var(--c-muted); font-size: 12px; flex-shrink: 0; }
.conv-bottom {
  display: flex; align-items: center; gap: 6px;
  color: var(--c-muted); font-size: 14px;
}
.conv-preview {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-count { font-size: 11px; color: var(--c-muted); }

/* ---- chat panel ---- */
.chat-page { display: grid; grid-template-rows: auto 1fr; gap: 0; padding: 0; }
.chat-page > .chat-header {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--c-surface); border-bottom: 1px solid var(--c-border);
  position: sticky; top: 56px; z-index: 5;
}
.chat-back {
  font-size: 22px; padding: 0 8px; line-height: 1; color: var(--c-text);
}
.chat-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-title strong { font-size: 16px; }
.chat-title .muted { font-size: 12px; }
.chat-actions { display: flex; gap: 8px; }
.pill {
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--c-border); background: var(--c-surface);
  color: var(--c-text); cursor: pointer;
}
.pill.amelia-pill { color: var(--c-primary); border-color: var(--c-primary); }
.pill.muted-pill { color: var(--c-muted); cursor: default; }

.chat-pane {
  display: grid; grid-template-rows: 1fr auto; gap: 0;
  background: var(--c-bg);
  min-height: calc(100dvh - 120px);
}
.bubbles {
  padding: 12px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
}
.bubble {
  max-width: 85%; padding: 8px 12px; border-radius: 14px;
  background: var(--c-bubble-in);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.bubble.b-out { align-self: flex-end; background: var(--c-bubble-out); }
.bubble.b-in  { align-self: flex-start; }
.bubble-text { white-space: pre-wrap; word-break: break-word; }
.bubble-meta {
  display: flex; gap: 6px; align-items: center; justify-content: flex-end;
  font-size: 11px; color: var(--c-muted); margin-top: 4px;
}
.ck { font-family: monospace; }
.ck-2 { letter-spacing: -2px; }
.ck-read { color: var(--c-status-read); }
.ck-fail { color: #c0392b; }
.rxn { font-size: 14px; }

.bubble-marks {
  display: flex; gap: 4px; margin-top: 4px; align-items: center;
}
.mark-btn {
  background: none; border: 0; cursor: pointer;
  padding: 2px 4px; border-radius: 6px;
  opacity: .35; font-size: 14px;
  transition: opacity .15s, transform .15s;
}
.mark-btn:hover { opacity: 1; }
.mark-btn.on { opacity: 1; transform: scale(1.15); }
.marks-count {
  margin-left: auto; font-size: 11px; color: var(--c-muted);
}

.composer {
  border-top: 1px solid var(--c-border);
  background: var(--c-surface); padding: 8px;
  position: sticky; bottom: 0;
}
.composer-form { display: flex; gap: 8px; align-items: flex-end; }
.composer-form textarea {
  flex: 1; min-height: 38px; max-height: 120px;
  padding: 8px 10px; font-size: 16px;
  border: 1px solid var(--c-border); border-radius: 8px;
  background: var(--c-bg); color: var(--c-text);
  resize: none;
}
.composer-form button { width: auto; min-width: 80px; margin: 0; padding: 8px 14px; }
.composer-hint { margin: 4px 0 0; font-size: 11px; }

.chat-side {
  padding: 12px 14px; border-top: 1px solid var(--c-border);
  background: var(--c-surface);
}
.chat-side h3 { margin: 0 0 8px; font-size: 14px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; }
.note-form textarea {
  width: 100%; padding: 8px; font-size: 14px;
  border: 1px solid var(--c-border); border-radius: 8px;
  background: var(--c-bg); color: var(--c-text);
}
.note-form button { width: auto; padding: 6px 12px; margin-top: 6px; font-size: 14px; }
.notes-list { list-style: none; padding: 0; margin: 8px 0 0; }
.notes-list li { padding: 8px 0; border-bottom: 1px solid var(--c-border); }
.notes-list li:last-child { border-bottom: 0; }
.note-meta { font-size: 12px; color: var(--c-muted); margin-bottom: 2px; }
.note-meta time { font-size: 11px; }
.note-body { font-size: 14px; }

/* ---- amelia card overlay ---- */
.amelia-card {
  position: fixed; inset: 12px;
  background: var(--c-surface); color: var(--c-text);
  border-radius: 14px; box-shadow: var(--shadow-md);
  padding: 18px; z-index: 50; overflow-y: auto;
  max-width: 480px; margin: auto;
  max-height: calc(100dvh - 24px);
}
.amelia-card .close {
  position: absolute; top: 8px; right: 12px; background: none; border: 0;
  font-size: 26px; line-height: 1; cursor: pointer; color: var(--c-muted);
}
.ac-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.ac-avatar {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-2));
  color: white; display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; object-fit: cover;
}
.ac-counts {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  margin: 12px 0;
}
.ac-count {
  background: var(--c-surface-2); padding: 8px; border-radius: 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.ac-count strong { font-size: 18px; }
.ac-count .muted { font-size: 10px; text-transform: uppercase; }
.ac-row { padding: 6px 0; border-top: 1px solid var(--c-border); font-size: 14px; }
.ac-row .muted { font-size: 12px; }
.status-pill {
  display: inline-block; font-size: 11px; padding: 1px 6px; margin-left: 4px;
  border-radius: 999px; background: var(--c-surface-2); color: var(--c-muted);
}
.status-pill.approved { background: rgba(11,109,78,.1); color: var(--c-primary); }
.status-pill.canceled { background: rgba(192,57,43,.1); color: #c0392b; }
.ac-actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px;
}
.ac-actions a {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--c-border);
  font-size: 14px;
}
.ac-actions a.primary-link { background: var(--c-primary); color: white; border-color: var(--c-primary); }

/* ---- audit table ---- */
.audit-filters {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 12px;
}
.audit-filters label { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 150px; }
.audit-filters label > span { font-size: 12px; color: var(--c-muted); }
.audit-filters input, .audit-filters select {
  padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--c-border); border-radius: 8px;
  background: var(--c-surface); color: var(--c-text);
}
.audit-filters button { width: auto; margin: 0; padding: 8px 14px; }
.audit-table {
  width: 100%; border-collapse: collapse; background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--r); overflow: hidden;
  font-size: 13px;
}
.audit-table th, .audit-table td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--c-border);
  vertical-align: top;
}
.audit-table th { background: var(--c-surface-2); font-weight: 600; color: var(--c-muted); text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
.audit-table tr:last-child td { border-bottom: 0; }
.audit-table .meta-cell { font-family: monospace; font-size: 11px; color: var(--c-muted); max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.audit-table code { font-size: 12px; padding: 1px 4px; background: var(--c-surface-2); border-radius: 4px; }

.center { text-align: center; }
.small { font-size: 12px; }

/* ---- skeleton ---- */
@keyframes sk-pulse {
  0%   { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}
.sk {
  background: linear-gradient(90deg, var(--c-surface-2) 0%, var(--c-border) 50%, var(--c-surface-2) 100%);
  background-size: 200px 100%; background-repeat: no-repeat;
  animation: sk-pulse 1.4s infinite linear;
  border-radius: 6px;
}
.sk-row { height: 14px; margin-bottom: 8px; width: 100%; }
.sk-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
.sk-tile { height: 56px; }

/* ---- date dividers ---- */
.date-divider {
  align-self: center;
  font-size: 11px; color: var(--c-muted);
  background: var(--c-surface);
  padding: 3px 10px; border-radius: 999px;
  margin: 6px 0;
  border: 1px solid var(--c-border);
}

/* ---- bubbles top sentinel ---- */
.bubbles-top-sentinel {
  height: 24px; margin: 4px 0; align-self: stretch;
  background: linear-gradient(90deg, transparent, var(--c-surface-2), transparent);
  background-size: 200% 100%;
  animation: sk-pulse 1.4s infinite linear;
  border-radius: 6px;
}

/* ---- conv-list sentinel ---- */
.conv-sentinel {
  height: 60px; margin-top: 12px;
  background: linear-gradient(180deg, var(--c-surface-2), transparent);
  border-radius: 8px;
}

/* ---- safe-area-inset for iOS ---- */
.composer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.topbar   { padding-top:    max(10px, env(safe-area-inset-top)); }

/* ---- touch targets >= 44px on small screens ---- */
@media (pointer: coarse), (max-width: 600px) {
  .mark-btn { min-width: 44px; min-height: 44px; padding: 8px 10px; font-size: 18px; }
  .pill { min-height: 36px; padding: 6px 12px; }
  .conv-link { padding: 14px 8px; }
  button.logout { min-height: 36px; }
}

/* ---- WP avatar fallback letter ---- */
.ac-avatar.fallback {
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-2));
}

.rxn-dot { font-size: 12px; }

/* ---- responsive ---- */
@media (min-width: 760px) {
  .chat-page {
    grid-template-areas:
      "header header"
      "main   side";
    grid-template-columns: 1fr 320px;
    grid-template-rows: auto 1fr;
  }
  .chat-page > .chat-header { grid-area: header; }
  .chat-page > .chat-pane { grid-area: main; }
  .chat-page > .chat-side { grid-area: side; border-top: 0; border-left: 1px solid var(--c-border); }
  .amelia-card { right: 12px; left: auto; top: 70px; bottom: auto; }
}
