/* Lubussa UI - simple, modern, light/dark */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #151a23;
  --muted: #646d7e;
  --border: #e3e6eb;
  --primary: #0f9d7a;
  --primary-hover: #0c8567;
  --primary-soft: #e3f5ef;
  --danger: #d4483b;
  --danger-soft: #fdecea;
  --warn: #c98a12;
  --warn-soft: #fdf3dc;
  --info-soft: #e8f0fd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --text: #e8ebf0;
    --muted: #98a1b2;
    --border: #262c38;
    --primary: #22b893;
    --primary-hover: #35c9a3;
    --primary-soft: #13312a;
    --danger: #ef6b5f;
    --danger-soft: #3a1d1b;
    --warn: #e6b04a;
    --warn-soft: #3a2f17;
    --info-soft: #1a2638;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
/* The hidden attribute must always win, even over class rules like .wa-card { display:flex } */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0 0 .25rem; line-height: 1.25; }
h1 { font-size: 1.75rem; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* Layout */
.container { max-width: 960px; margin: 0 auto; padding: 32px 16px 48px; }
.container.narrow { max-width: 720px; }
.page-head { margin-bottom: 24px; }
.page-head p { margin: 0; }
.back { display: inline-block; margin-bottom: 16px; color: var(--muted); font-size: .9rem; }
.back:hover { color: var(--text); }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar form { margin: 0; }
.user { font-size: .9rem; }
@media (max-width: 560px) { .user { display: none; } }

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.brand-mark { display: inline-flex; width: 32px; height: 32px; }
.brand-mark svg { width: 100%; height: 100%; display: block; }

/* Language switch */
.lang { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.lang a { padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; color: var(--muted); }
.lang a.active { background: var(--primary-soft); color: var(--primary); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }

.module { display: flex; flex-direction: column; gap: 6px; transition: transform .15s, border-color .15s; }
a.module:hover { transform: translateY(-2px); border-color: var(--primary); }
.module p { margin: 0 0 10px; }
.module-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.module-icon {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: var(--primary-soft); color: var(--primary);
}
.module-link { margin-top: auto; font-weight: 600; color: var(--primary); font-size: .92rem; }
.module-disabled { opacity: .6; cursor: not-allowed; filter: grayscale(.6); }
.module-disabled .module-link { color: var(--muted); font-weight: 500; }

/* Badges */
.badge { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; letter-spacing: .02em; }
.badge-ok { background: var(--primary-soft); color: var(--primary); }
.badge-soon { background: var(--warn-soft); color: var(--warn); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .95rem; padding: 10px 18px;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-sm { padding: 6px 12px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; font-weight: 600; }
.form input {
  font: inherit; font-weight: 400; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.alert { padding: 10px 14px; border-radius: 10px; font-size: .9rem; margin: 14px 0 0; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--info-soft); }

/* Login */
.auth { max-width: 400px; margin: 0 auto; padding: 48px 16px; }
.auth-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.auth-card p { margin: 0; }

/* WhatsApp Web page */
.wa-card { min-height: 340px; display: flex; align-items: center; justify-content: center; margin-bottom: 16px; }
.wa-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; max-width: 440px; }
.wa-state[hidden] { display: none; }
.wa-state p { margin: 0 0 8px; }
.wa-icon {
  display: grid; place-items: center; width: 76px; height: 76px; border-radius: 50%;
  background: var(--bg); color: var(--muted); margin-bottom: 8px;
}
.wa-icon.ok { background: var(--primary-soft); color: var(--primary); }
.wa-icon.warn { background: var(--warn-soft); color: var(--warn); }

.wa-qr { flex-direction: row; align-items: center; gap: 28px; text-align: left; max-width: none; }
.qr-box { background: #fff; padding: 12px; border-radius: 12px; border: 1px solid var(--border); line-height: 0; }
.qr-box img { width: 260px; height: 260px; image-rendering: pixelated; }
.steps { margin: 10px 0; padding-left: 20px; }
.steps li { margin: 6px 0; }
@media (max-width: 640px) {
  .wa-qr { flex-direction: column; text-align: center; }
  .qr-box img { width: 220px; height: 220px; }
  .steps { text-align: left; }
}

.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Consent notice on the linking screen */
.consent {
  background: var(--warn-soft); color: var(--text);
  border: 1px solid var(--warn); border-radius: 10px;
  padding: 12px 14px; margin: 4px 0 8px; text-align: left; max-width: 420px;
}
.consent strong { display: block; margin-bottom: 4px; color: var(--warn); }
.consent p { margin: 0; font-size: .9rem; }
.consent.small { background: none; border: none; padding: 6px 0 0; color: var(--muted); }
.consent.small strong { display: none; }

/* Minimal connected indicator */
.wa-bar { display: flex; align-items: center; gap: 8px; padding: 9px 13px; margin-bottom: 14px;
  background: var(--primary-soft); border: 1px solid var(--primary); border-radius: 10px; font-size: .9rem; }
.wa-bar .arrow { color: var(--primary); font-weight: 800; }
.wa-bar .num { font-weight: 600; }
.wa-bar .btn { margin-left: auto; }

/* Tabs */
.wa-panels { margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.tab { flex: 1; font: inherit; font-weight: 600; font-size: .9rem; padding: 9px 12px;
  border: none; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--primary-soft); color: var(--primary); }
.tab-panel[hidden] { display: none; }

/* Search box */
.search { width: 100%; font: inherit; padding: 10px 13px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }
.search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Rows (contacts, chats) */
.wa-list { max-height: 420px; overflow-y: auto; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 6px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: none; }
.row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-main .preview, .row-main .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw; }
[data-open] { cursor: pointer; border-radius: 8px; }
[data-open]:hover { background: var(--bg); }
.row-action strong { color: var(--primary); }

/* Conversation thread */
.thread { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; padding: 8px 0; }
.bubble { display: flex; flex-direction: column; gap: 2px; max-width: 80%;
  padding: 8px 12px; border-radius: 12px; font-size: .92rem; }
.bubble span:last-child { font-size: .7rem; }
.bubble.in { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
.bubble.out { align-self: flex-end; background: var(--primary-soft); color: var(--text); }
.bubble { position: relative; }
.bubble.has-media { padding: 4px; }
.msg-img { max-width: 240px; max-height: 320px; border-radius: 10px; display: block; cursor: pointer; }
.msg-sticker { width: 120px; height: 120px; object-fit: contain; }
.bubble.has-media .time { padding: 0 8px 4px; }
.reaction { position: absolute; bottom: -11px; right: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 0 5px; font-size: .85rem; line-height: 1.5; }
.thread .bubble { margin-bottom: 6px; }
.quoted { display: block; border-left: 3px solid var(--primary); padding: 2px 8px; margin-bottom: 4px;
  background: rgba(127, 127, 127, .08); border-radius: 4px; font-size: .82rem; color: var(--muted); }
#wa-thread-title { margin: 8px 0; }

/* Two-pane WhatsApp-like layout */
.wa-split { display: flex; gap: 16px; align-items: flex-start; }
.wa-list-view { flex: 0 0 320px; max-width: 320px; }
.wa-convo { flex: 1; min-height: 420px; display: flex; flex-direction: column; }
.convo-placeholder { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 360px; }
#wa-convo-active { display: flex; flex-direction: column; flex: 1; }
.only-mobile { display: none; }
@media (max-width: 760px) {
  .wa-split { flex-direction: column; }
  .wa-list-view { flex: none; max-width: none; width: 100%; }
  .wa-convo { width: 100%; }
  .only-mobile { display: inline-flex; }
  .wa-split:not(.open) .wa-convo { display: none; }
  .wa-split.open .wa-list-view { display: none; }
}
.row.active { background: var(--primary-soft); }

/* Contact import */
.import { margin-bottom: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.import summary { cursor: pointer; font-size: .88rem; font-weight: 600; color: var(--muted); }
.import textarea { width: 100%; margin-top: 8px; font: inherit; padding: 8px 10px; resize: vertical;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.import-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.import-file { display: block; margin-top: 8px; font-size: .85rem; }
.import-file span { display: block; margin-bottom: 4px; font-weight: 600; }
.import .muted.small { margin: 8px 0 4px; }

/* Conversation header + composer */
.convo-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.icon-btn { font: inherit; font-size: 1.15rem; background: transparent; border: none;
  cursor: pointer; color: var(--text); padding: 2px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--bg); }
.composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; }
.composer textarea { flex: 1; resize: none; font: inherit; padding: 10px 12px; max-height: 140px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text); }
.composer textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.composer button { padding: 10px 16px; font-size: 1.05rem; line-height: 1; }
