@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f3f4f6;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --panel: #ffffff;
  --brand: #e11d48;
  --brand-hover: #be123c;
  --brand-soft: #fff1f2;
  --teal: #14b8a6;
  --ok: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  --sidebar-w: 248px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.hp {
  position: absolute !important;
  left: -10000px !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Auth */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 18px;
}
.auth-brand img {
  width: 28px; height: 28px; border-radius: 7px;
  object-fit: contain; background: transparent;
}
.auth-card h1 { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.auth-card > p { margin: 6px 0 18px; color: var(--muted); }
.auth-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 4px 0 14px; flex-wrap: wrap;
}
.auth-row .check {
  display: inline-flex; align-items: center; gap: 8px;
  color: #4b5563; font-size: .86rem; font-weight: 500;
}
.auth-row .check input { width: auto; }
.link-btn {
  border: 0; background: none; color: var(--brand); padding: 0;
  font-weight: 600; font-size: .86rem;
}
.link-btn:hover { text-decoration: underline; }
.auth-switch {
  margin: 14px 0 0; text-align: center; color: var(--muted); font-size: .9rem;
}
.input-with-btn {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch;
}
.input-with-btn .btn { white-space: nowrap; }

.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 6px; color: #4b5563; font-size: .84rem; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 12px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: #fda4af;
  box-shadow: 0 0 0 3px rgba(225, 29, 72, .12);
}
.btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
}
.btn:hover { background: var(--brand-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #111827; }
.btn.danger { background: var(--bad); }
.btn.ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn.ghost:hover { background: #f9fafb; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 10px; font-size: .82rem; }
.msg { margin-top: 12px; color: #b45309; min-height: 1.2em; font-size: .88rem; }
.hint { color: var(--muted); font-size: .84rem; margin: 8px 0 0; }

/* Shell */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 14px 0 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  z-index: 40;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px 18px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.02em;
  color: var(--ink);
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  object-fit: contain;
  background: transparent;
  display: block;
  flex-shrink: 0;
}
.brand-text { line-height: 1; }

.nav { padding: 0 10px; }
.nav-section { margin-bottom: 14px; }
.nav-label {
  color: #9ca3af;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 6px 12px 8px;
}
.nav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: 0;
  background: transparent;
  color: #4b5563;
  padding: 9px 12px;
  border-radius: 8px;
  margin-bottom: 2px;
  font-weight: 500;
  font-size: .9rem;
}
.nav button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .9;
}
.nav button:hover { background: #f3f4f6; color: var(--ink); }
.nav button.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}
.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}

.content-col { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar-app {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f3f4f6;
  border-radius: 999px;
  padding: 9px 14px;
  min-width: min(340px, 46vw);
  color: #9ca3af;
}
.topbar-search input {
  border: 0;
  background: transparent;
  outline: none;
  width: 100%;
  color: var(--ink);
  font-size: .9rem;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: #6b7280;
  display: grid;
  place-items: center;
}
.icon-btn:hover { color: var(--brand); border-color: #fecdd3; background: #fff1f2; }
.avatar-btn {
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 0;
  background: #111827;
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0;
}
.avatar-btn span { line-height: 1; }

.main { padding: 22px 22px 40px; flex: 1; }
.nav-toggle {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 11px;
  font-weight: 600;
}

.page-head { margin-bottom: 18px; }
.page-head h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -.03em;
}
.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .92rem;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 18px;
}
.topbar h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.topbar .meta { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
}
.stat-card .label {
  color: var(--muted);
  font-size: .84rem;
  font-weight: 500;
}
.stat-card .row-val {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}
.stat-card .value {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1;
}
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 650;
  background: #ecfdf5;
  color: #059669;
}
.pill.down { background: #fff1f2; color: #e11d48; }
.pill.neutral { background: #f3f4f6; color: #6b7280; }

.dash-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 14px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.card, .panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 16px; }
.card .label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.card .value { font-size: 1.4rem; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; }
.panel { padding: 16px 18px; margin-bottom: 16px; }
.panel h3 {
  margin: 0 0 14px;
  font-size: .98rem;
  font-weight: 650;
}
.panel.flat { margin-bottom: 0; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-avatar {
  width: 34px; height: 34px; border-radius: 999px;
  background: #111827; color: #fff;
  display: grid; place-items: center;
  font-size: .7rem; font-weight: 700;
  flex-shrink: 0;
}
.list-row .title { font-weight: 600; font-size: .88rem; }
.list-row .sub { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.meter {
  height: 8px;
  background: #f3f4f6;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.meter > span {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
}
.bar-row { margin-bottom: 12px; }
.bar-row .bar-top {
  display: flex;
  justify-content: space-between;
  font-size: .82rem;
  margin-bottom: 6px;
}
.bar-row .bar-top strong { font-weight: 650; }
.bar-row .bar-top span { color: var(--muted); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row .field { flex: 1; min-width: 160px; margin-bottom: 0; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; }
tr:last-child td { border-bottom: 0; }
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: #f3f4f6;
  color: #4b5563;
}
.badge.ok { background: #ecfdf5; color: #047857; }
.badge.warn { background: #fffbeb; color: #b45309; }
.badge.bad { background: #fef2f2; color: #b91c1c; }
.qr-box {
  display: grid; place-items: center; min-height: 220px;
  background: #fff; border: 1px dashed var(--line); border-radius: 12px; padding: 16px;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; }
/* AI Advance: daftar agen sempit, panel kelola (form + knowledge) lebih luas */
.grid-ai-advance {
  display: grid;
  grid-template-columns: minmax(240px, .62fr) minmax(0, 1.38fr);
  gap: 16px;
  align-items: start;
}
.grid-ai-advance #ai-agent-detail { min-width: 0; }
.grid-ai-advance .table-wrap { overflow-x: auto; }
.grid-ai-advance .row { margin-bottom: 12px; }

.inbox-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 14px;
  min-height: 62vh;
}
.inbox-list, .inbox-thread {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  box-shadow: var(--shadow);
}
.inbox-list-items { overflow: auto; flex: 1; }
.conv-item {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--ink); padding: 12px 14px;
}
.conv-item:hover, .conv-item.active { background: #fafafa; }
.conv-item.active { box-shadow: inset 3px 0 0 var(--brand); }
.conv-item .who { font-weight: 600; font-size: .9rem; }
.conv-item .preview { color: var(--muted); font-size: .8rem; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .meta-line { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .72rem; margin-top: 6px; }
.thread-head { padding: 12px 14px; border-bottom: 1px solid var(--line); background: #fafafa; }
.thread-messages { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f9fafb; }
.bubble {
  max-width: 78%; padding: 10px 12px; border-radius: 12px 12px 12px 4px;
  background: #fff; border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word;
}
.bubble.out {
  align-self: flex-end; background: var(--brand-soft); border-color: #fecdd3;
  border-radius: 12px 12px 4px 12px;
}
.bubble .bubble-meta { color: var(--muted); font-size: .7rem; margin-top: 6px; }
.thread-compose { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 8px; background: #fff; }
.thread-compose textarea { flex: 1; min-height: 64px; resize: vertical; }
.device-checks { display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow: auto; }
.device-checks label { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .88rem; }

.modal-root { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 18px; }
.modal-root.hidden { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 39, .4); }
.modal-card {
  position: relative; width: min(520px, 100%); max-height: min(88vh, 760px); overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,.16); padding: 18px;
}
.modal-card.wide { width: min(720px, 100%); }
.modal-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.modal-head .meta { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.modal-close {
  border: 0; background: #f3f4f6; width: 32px; height: 32px; border-radius: 8px; color: #6b7280; font-size: 1.05rem;
}
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line);
}
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
body.nav-open .sidebar-overlay { display: block; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-105%);
    transition: transform .2s ease; width: min(300px, 88vw);
    box-shadow: 12px 0 40px rgba(0,0,0,.14);
  }
  body.nav-open .sidebar { transform: none; }
  .nav-toggle { display: inline-flex; }
  .topbar-search { display: none; }
  .grid-2, .grid-ai-advance, .inbox-layout { grid-template-columns: 1fr; }
  .main { padding: 16px 14px 36px; }
  #quick-send { display: none; }
}
