/* Intellicom HQ — mobile first. Pierre clears approvals on his phone. */

:root {
  --bg: #12121c;
  --surface: #1a1a2e;
  --surface-2: #21213a;
  --line: #2e2e4a;
  --text: #e8e8f0;
  --muted: #9a9ab4;
  --blue: #1a73e8;
  --blue-hi: #4a93ff;
  --green: #2e9e5b;
  --amber: #d9a441;
  --red: #d0453f;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.screen { min-height: 100vh; }
[hidden] { display: none !important; }

/* --- login ---------------------------------------------------------------- */

#login { display: grid; place-items: center; padding: 24px; }

.login-card { width: 100%; max-width: 360px; }
.login-card h1 { margin: 0 0 4px; font-size: 26px; font-weight: 600; }
.login-card h1 span { color: var(--blue-hi); }

/* --- shell ---------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; letter-spacing: .2px; }
.brand span { color: var(--blue-hi); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.online { color: #7fe0a5; background: rgba(46,158,91,.16); }
.pill.offline { color: #ff9d99; background: rgba(208,69,63,.16); }

.banner {
  margin: 12px 16px; padding: 12px 14px; border-radius: var(--radius);
  font-size: 14px; line-height: 1.5;
}
.banner.danger { background: rgba(208,69,63,.14); border: 1px solid rgba(208,69,63,.4); }
.banner.warn { background: rgba(217,164,65,.14); border: 1px solid rgba(217,164,65,.4); }
.banner strong { display: inline-block; margin-right: 4px; }

.tabs {
  display: flex; gap: 4px; padding: 10px 12px 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 0 0 auto; background: none; border: 0; color: var(--muted);
  font: inherit; font-size: 15px; padding: 8px 12px; border-radius: 8px;
  cursor: pointer; white-space: nowrap;
}
.tab.active { color: var(--text); background: var(--surface-2); }
.count {
  display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 4px;
  border-radius: 999px; background: var(--blue); color: #fff;
  font-size: 12px; text-align: center;
}
.count.zero { background: var(--surface); color: var(--muted); }

.view { padding: 12px 16px 40px; }

/* --- cards ---------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.card h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }

.approval { cursor: pointer; }
.approval:active { background: var(--surface-2); }
.approval-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.approval-summary { font-weight: 500; }
.approval-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.approval-preview {
  margin-top: 10px; padding: 10px; border-radius: 8px;
  background: var(--bg); color: var(--muted); font-size: 13px;
  max-height: 4.6em; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}

.kind {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.kind.payment { background: rgba(217,164,65,.18); color: #f0c674; }
.kind.invoice { background: rgba(26,115,232,.18); color: var(--blue-hi); }

.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.big { font-size: 20px; display: block; margin: 8px 0; }

.state { font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.state-executed { background: rgba(46,158,91,.18); color: #7fe0a5; }
.state-rejected { background: rgba(154,154,180,.16); color: var(--muted); }
.state-failed { background: rgba(208,69,63,.18); color: #ff9d99; }
.state-approved { background: rgba(26,115,232,.18); color: var(--blue-hi); }
.state-pending { background: rgba(217,164,65,.18); color: #f0c674; }

/* --- team ----------------------------------------------------------------- */

.agent-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.agent-row:last-child { border-bottom: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.dot.working { background: var(--blue-hi); }
.dot.idle { background: #4a4a68; }
.dot.blocked { background: var(--amber); }
.dot.error { background: var(--red); }
.agent-name { font-weight: 500; }
.agent-activity { color: var(--muted); font-size: 13px; }

/* --- forms ---------------------------------------------------------------- */

label { display: block; margin: 14px 0 6px; font-size: 14px; color: var(--muted); }
input, textarea, select {
  width: 100%; padding: 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
input:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
textarea { min-height: 220px; resize: vertical; font-size: 14px; line-height: 1.6; }
.row { display: flex; align-items: center; gap: 10px; }
.row input { flex: 1; }

button { font: inherit; cursor: pointer; border-radius: 8px; }
.primary {
  width: 100%; margin-top: 18px; padding: 13px;
  background: var(--blue); color: #fff; border: 0; font-weight: 500;
}
.primary:active { background: #155ec0; }
.ghost { background: none; border: 1px solid var(--line); color: var(--muted); padding: 8px 12px; }
.ghost.small { padding: 4px 10px; font-size: 13px; margin-left: 8px; }
.danger-btn { width: 100%; padding: 13px; background: none; border: 1px solid var(--red); color: #ff9d99; }
.approve-btn { flex: 1; padding: 14px; background: var(--green); color: #fff; border: 0; font-weight: 500; }
.reject-btn { flex: 1; padding: 14px; background: none; border: 1px solid var(--red); color: #ff9d99; }
.done-btn { flex: 1; padding: 14px; background: var(--blue); color: #fff; border: 0; font-weight: 500; }
.actions { display: flex; gap: 10px; margin-top: 20px; }

.chip {
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; font-size: 14px;
}
.chip.active { background: var(--surface-2); color: var(--text); }
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }

.muted { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.error { color: #ff9d99; font-size: 14px; margin-top: 12px; }
.ok { color: #7fe0a5; font-size: 14px; margin-top: 12px; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; }

/* --- detail dialog -------------------------------------------------------- */

dialog#detail {
  width: 100%; max-width: 640px; margin: auto; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
dialog#detail::backdrop { background: rgba(0,0,0,.65); }
.detail-close { position: sticky; top: 0; display: flex; justify-content: flex-end; padding: 10px 10px 0; }
.detail-inner { padding: 4px 20px 24px; }
.detail-inner h2 { margin: 0 0 4px; font-size: 19px; }
.full-body {
  white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px; font-size: 14px; line-height: 1.6; margin-top: 12px;
}
.field { margin-top: 14px; }
.field-label { color: var(--muted); font-size: 13px; }
.warn-note {
  margin-top: 14px; padding: 12px; border-radius: 8px; font-size: 14px;
  background: rgba(217,164,65,.14); border: 1px solid rgba(217,164,65,.4);
}

/* --- chat ----------------------------------------------------------------- */

.new-row { display: flex; gap: 10px; margin-bottom: 14px; }
.new-row button { flex: 1; }
.primary.inline { width: auto; margin: 0; padding: 10px 16px; }

.thread-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.thread-card:active { background: var(--surface-2); }
.thread-card-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.thread-title { font-weight: 500; }
.thread-snippet {
  color: var(--muted); font-size: 13px; margin-top: 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.thread-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.thread-head .ghost { flex: 0 0 auto; }

.msg { margin-bottom: 14px; }
.msg-who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg-body {
  white-space: pre-wrap; word-break: break-word;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; font-size: 15px; line-height: 1.6;
}
.msg.me .msg-body { background: rgba(26,115,232,.14); border-color: rgba(26,115,232,.35); }
.msg.me .msg-who { text-align: right; }
.msg.me { margin-left: 14%; }
.msg.them { margin-right: 8%; }

.waiting {
  color: var(--muted); font-size: 13px; padding: 10px 0 4px;
  display: flex; align-items: center; gap: 8px;
}
.waiting::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--blue-hi); animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.say-row {
  position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 22%);
}
.say-row textarea { min-height: 46px; resize: none; }

.picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pick {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  padding: 8px 12px; font-size: 14px; border-radius: 999px; cursor: pointer;
}
.pick.on { background: rgba(26,115,232,.18); border-color: var(--blue); color: var(--blue-hi); }
.pick .role { color: var(--muted); font-size: 12px; margin-left: 6px; }
.pick.on .role { color: var(--blue-hi); }

@media (min-width: 720px) {
  .view { max-width: 760px; margin: 0 auto; }
  .banner { max-width: 760px; margin-left: auto; margin-right: auto; }
  .tabs { max-width: 760px; margin: 0 auto; }
}
