/* Pictify WhatsApp Dashboard — "Paper & Ink" design system on top of Tailwind (CDN).
   Warm paper surfaces, ink-black type (Manrope), soft warm shadows, WhatsApp green
   only where something is sent. Motion follows Emil Kowalski's rules: custom ease-out,
   ≤ 300 ms, press = scale(0.97), explicit transition properties, reduced-motion respected. */

:root {
  --paper: #f4efe6; --paper-2: #ece5d8; --card: #fffdf8;
  --ink: #1c1a17; --ink-2: #2b2925; --muted: #6f675c; --faint: #a49b8d; --line: #e3dacb; --line-soft: #efe8dc;
  --go: #128C7E; --go-bright: #25D366; --go-soft: #dcefe3; --go-ink: #1d5a3f;
  --warn-bg: #fff6dc; --warn-line: #f0d98a; --warn-ink: #7a5a06;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --shadow-card: 0 1px 0 rgba(80, 60, 20, .05), 0 10px 30px -18px rgba(80, 60, 20, .28);
  --shadow-pop: 0 1px 0 rgba(80, 60, 20, .05), 0 12px 40px -16px rgba(60, 45, 15, .35);
}

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { font-family: Manrope, Inter, ui-sans-serif, system-ui, sans-serif; color: var(--ink); }
h1, h2, h3 { text-wrap: balance; letter-spacing: -0.015em; }
p, li, td { text-wrap: pretty; }
.tabular { font-variant-numeric: tabular-nums; }
img { outline: 1px solid rgba(0, 0, 0, 0.08); outline-offset: -1px; }
img.no-outline { outline: none; }
.ico { width: 18px; height: 18px; flex: none; }

/* ── Sidebar navigation ── */
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border-radius: 12px; font-size: 14px; font-weight: 500; text-align: left;
  color: var(--muted);
  transition-property: transform, background-color, color, box-shadow; transition-duration: 160ms; transition-timing-function: var(--ease-out);
}
.nav-btn:hover { background: rgba(28, 26, 23, .06); color: var(--ink); }
.nav-btn:active { transform: scale(0.97); }
.nav-btn.active { background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 8px 18px -10px rgba(28, 26, 23, .55); }
.nav-ico { width: 20px; display: inline-flex; justify-content: center; color: inherit; opacity: .85; }
.nav-btn.active .nav-ico { opacity: 1; }
.nav-section { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); padding: 16px 12px 6px; font-weight: 700; }
.nav-badge { margin-left: auto; background: var(--go); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.nav-btn.active .nav-badge { background: var(--go-bright); color: #0b2e1a; }

/* ── Surfaces & type ── */
.card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow-card); }
.card .card { box-shadow: none; border: 1px solid var(--line); border-radius: 16px; }
.card-title { font-weight: 800; font-size: 16px; letter-spacing: -0.015em; margin-bottom: 12px; }
.subhead { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 34px; font-weight: 800; line-height: 1.1; margin-top: 2px; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.link { font-size: 12px; font-weight: 600; color: var(--go); }
.link:hover { text-decoration: underline; }
.fieldset { border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.fieldset > legend { font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 6px; }

/* ── Controls ── */
.input, .select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; font-size: 14px; background: #fff;
  min-height: 40px; color: var(--ink);
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.input::placeholder { color: var(--faint); }
.input:focus, .select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(28, 26, 23, .10); }
.input-sm, .select-sm { padding: 6px 10px; font-size: 13px; min-height: 34px; border-radius: 10px; }
textarea.input { min-height: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 12px; font-size: 14px; font-weight: 700; min-height: 40px;
  transition-property: transform, background-color, color, box-shadow; transition-duration: 160ms; transition-timing-function: var(--ease-out);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 34px; border-radius: 10px; }
.btn-primary { background: var(--ink); color: #fff; box-shadow: 0 6px 14px -8px rgba(28, 26, 23, .6); }
.btn-primary:hover { background: var(--ink-2); }
.btn-outline { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn-outline:hover { background: var(--paper-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(28, 26, 23, .06); color: var(--ink); }
.btn-ghost.btn-sm { min-width: 40px; min-height: 40px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.send-btn {
  width: 40px; height: 40px; border-radius: 999px; background: var(--go-bright); color: #0b2e1a; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 14px -8px rgba(37, 211, 102, .8); transition: transform 160ms var(--ease-out), background-color 160ms var(--ease-out);
}
.send-btn:hover { background: #2fe173; } .send-btn:active { transform: scale(0.94); }

.chip { padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--paper-2); color: var(--muted); transition: transform 160ms var(--ease-out), background-color 160ms var(--ease-out), color 160ms var(--ease-out); }
.chip:hover { background: var(--line); color: var(--ink); }
.chip:active { transform: scale(0.97); }
.chip.chip-on { background: var(--ink); color: #fff; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--paper-2); color: var(--muted); }
.badge-on { background: var(--go-soft); color: var(--go-ink); }
.badge-off { background: var(--paper-2); color: var(--muted); }

/* ── Campaign wizard ── */
.wizard-steps { display: flex; gap: 6px; }
.wizard-steps li { display: flex; align-items: center; gap: 8px; flex: 1; font-size: 13px; font-weight: 600; color: var(--faint); padding: 8px 10px; border-radius: 12px; background: var(--paper-2); }
.wizard-steps li span { width: 22px; height: 22px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; background: #fff; color: var(--faint); box-shadow: inset 0 0 0 1px var(--line); }
.wizard-steps li.on { color: var(--ink); background: var(--card); box-shadow: inset 0 0 0 1px var(--line), var(--shadow-card); }
.wizard-steps li.on span { background: var(--ink); color: #fff; box-shadow: none; }
.wizard-steps li.done { color: var(--muted); }
.wizard-steps li.done span { background: var(--go-soft); color: var(--go-ink); box-shadow: none; }
.kind-card { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 14px; border-radius: 16px; background: #fff; box-shadow: inset 0 0 0 1px var(--line); transition: transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out), background-color 160ms var(--ease-out); }
.kind-card:hover { box-shadow: inset 0 0 0 1px var(--faint); }
.kind-card:active { transform: scale(0.98); }
.kind-card.on { background: var(--ink); color: #fff; box-shadow: 0 10px 24px -14px rgba(28,26,23,.6); }
.kind-card.on .kind-desc { color: rgba(255,255,255,.72); }
.kind-emoji { font-size: 22px; line-height: 1; }
.kind-title { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }
.kind-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }

/* ── Tables ── */
.table { width: 100%; font-size: 14px; }
.table th { text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }

/* ── Chat ── */
#thread-messages { background-color: #efe7d9; background-image: radial-gradient(rgba(60, 45, 15, .06) 1px, transparent 1px); background-size: 18px 18px; }
.bubble { max-width: 65%; min-width: 90px; padding: 6px 9px 4px; border-radius: 10px; font-size: 14px; line-height: 1.35; position: relative; box-shadow: 0 1px 0.5px rgba(60, 45, 15, .12); overflow-wrap: anywhere; }
.bubble .body { white-space: pre-wrap; }
.bubble-in { background: var(--card); align-self: flex-start; border-top-left-radius: 3px; }
.bubble-out { background: #dff5d6; align-self: flex-end; border-top-right-radius: 3px; }
.bubble .meta { font-size: 10px; color: #7d766a; margin-top: 1px; display: flex; gap: 3px; align-items: center; justify-content: flex-end; line-height: 1.2; }
.bubble-in .body, .bubble-out .body { padding-right: 2px; }
.ticks { font-size: 11px; letter-spacing: -2px; }
.ticks.read { color: #53bdeb; }
.ticks.failed { color: #dc2626; letter-spacing: 0; }
.convo-row { transition: background-color 160ms var(--ease-out); }
.convo-row.active { background: var(--paper-2); }
.wa-buttons { display: flex; flex-direction: column; gap: 3px; margin: 6px -9px -4px; border-top: 1px solid rgba(60, 45, 15, .08); padding-top: 4px; }
.wa-buttons span { text-align: center; color: #027eb5; font-size: 13px; font-weight: 600; padding: 5px 8px; border-radius: 6px; background: rgba(255, 255, 255, .55); }
.window-closed { background: var(--warn-bg); border-top: 1px solid var(--warn-line); color: var(--warn-ink); font-size: 12px; padding: 8px 14px; }

/* ── Help drawer ── */
#help-drawer { background: var(--card); border-left: 1px solid var(--line); box-shadow: var(--shadow-pop); animation: drawer-in 220ms var(--ease-out) both; }
@keyframes drawer-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
#help-content h3 { font-weight: 800; margin-top: 10px; letter-spacing: -0.01em; }
#help-content ol, #help-content ul { padding-left: 20px; }
#help-content ol { list-style: decimal; }
#help-content ul { list-style: disc; }
#help-content li { margin: 4px 0; }
#help-content .tip { background: var(--go-soft); border: 1px solid #bfe0cc; border-radius: 12px; padding: 10px 12px; font-size: 13px; }
#help-content .warn { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 12px; padding: 10px 12px; font-size: 13px; }
#help-content kbd { font-family: ui-monospace, monospace; background: var(--paper-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ── Popovers & toast ── */
#qr-menu { transform-origin: bottom left; animation: pop-in 180ms var(--ease-out) both; box-shadow: var(--shadow-pop); border-color: var(--line); background: var(--card); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96) translateY(4px); } to { opacity: 1; transform: none; } }
#toast { background: var(--ink); border-radius: 12px; transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-out); }
#toast:not(.hidden) { @starting-style { opacity: 0; transform: translateY(12px); } }

.overflow-y-auto::-webkit-scrollbar { width: 6px; }
.overflow-y-auto::-webkit-scrollbar-thumb { background: rgba(60, 45, 15, .18); border-radius: 3px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .btn:active, .chip:active, .nav-btn:active, .send-btn:active { transform: none; }
}

/* ── Roles: staff (agent) get a reduced dashboard ── */
.is-staff .admin-only { display: none !important; }
body:not(.is-staff) .staff-only { display: none !important; }

/* ── Phones: off-canvas sidebar, stacked inbox ── */
#app-view { height: 100dvh; }
.sidebar-backdrop { display: none; }
@media (max-width: 767px) {
  #app-view .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: 264px; z-index: 40;
    transform: translateX(-100%);
    transition-property: transform, box-shadow; transition-duration: 240ms; transition-timing-function: var(--ease-out);
  }
  #app-view.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  #app-view.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(28, 26, 23, .45); z-index: 35; }
  .inbox-grid .thread-pane { display: none; }
  /* thread header: name row, then the action row */
  #thread-header { flex-wrap: wrap; height: auto; min-height: 56px; padding-top: 8px; padding-bottom: 8px; }
  #thread-header > .ml-auto { margin-left: 0; width: 100%; justify-content: flex-end; }
  .inbox-grid.thread-open .inbox-list-pane { display: none; }
  .inbox-grid.thread-open .thread-pane { display: flex; }
  .stat-value { font-size: 28px; }
  .card { border-radius: 16px; }
  #toast { left: 16px; right: 16px; bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) { #app-view .sidebar { transition: none; } }
