/* Funix · dashboard operasional WhatsApp
   Tenang dan bersih: ground putih kebiruan, satu aksen biru tua, teks sistem.
   Warna hanya hadir untuk status (hijau, kuning, merah). */

:root {
  color-scheme: light dark;

  --bg: #ffffff;
  --card: #ffffff;
  --sidebar: transparent;
  --line: #ebedf0;
  --field-line: #c4c9d2;
  --text: #16181d;
  --muted: #626977;
  --hover: #f5f6f8;

  --accent: #1d4ed8;
  --accent-hover: #1a43b8;
  --navy: #ffffff;
  --on-accent: #ffffff;
  --accent-soft: #e6edfd;

  --hijau: #11803f;
  --merah: #c62f27;
  --kuning: #b87500;
  --tint-ok: #e6f4ec;
  --tint-bad: #fceceb;
  --tint-wait: #fdf3dc;
  --abu: #8a909c;

  --focus: var(--accent);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.06);

  --radius: 16px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --navy: #171a20;
    --card: #171a20;
    --sidebar: transparent;
    --line: #272b33;
    --field-line: #424852;
    --text: #eceef2;
    --muted: #9ba1ad;
    --hover: #20242b;

    --accent: #6f93ff;
    --accent-hover: #88a6ff;
    --on-accent: #0c1530;
    --accent-soft: #1c2745;

    --hijau: #3cc47a;
    --merah: #ff7a70;
    --kuning: #e9b44c;
    --tint-ok: #12261b;
    --tint-bad: #2e1614;
    --tint-wait: #2c2410;
    --abu: #6c7280;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--field-line) transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14.5px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

a {
  color: inherit;
  text-underline-offset: 3px;
}

main a:not(.btn):not(.papan):not(.convo-item) {
  color: var(--accent);
  text-decoration-thickness: 1px;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Ikon ---------- */
.i {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 18px 12px 14px;
  background: var(--card);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark,
.auth-logo {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.auth-logo {
  width: 56px;
  height: 56px;
}

@media (prefers-color-scheme: dark) {
  .brand-mark,
  .auth-logo {
    filter: invert(1);
    mix-blend-mode: screen;
  }
}

.brand-word {
  font-weight: 650;
  font-size: 17px;
  letter-spacing: 0.01em;
  text-transform: capitalize;
  line-height: 1;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-title {
  margin: 0 10px 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.nav-link:hover {
  background: var(--hover);
  color: var(--text);
}

.nav-link[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.rail-user {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--line);
}

.rail-user strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-user small {
  color: var(--muted);
}

.topbar {
  display: none;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 19;
  background: rgba(10, 12, 16, 0.4);
}

.main {
  min-width: 0;
  padding: 32px 36px 56px;
  background: var(--card);
}

.main > * {
  max-width: 1120px;
  margin-inline: auto;
}

/* ---------- Judul halaman ---------- */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 24px;
}

.page-head .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

h1,
.title {
  margin: 0;
  font-weight: 700;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

h2 {
  margin: 0 0 12px;
  font-weight: 600;
  font-size: 16px;
  line-height: 1.3;
}

h3 {
  margin: 20px 0 8px;
  font-weight: 600;
  font-size: 14.5px;
}

.lead {
  max-width: 68ch;
  margin: 6px 0 0;
  color: var(--muted);
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
}

.back:hover {
  color: var(--text);
}

/* ---------- Panel, tata letak ---------- */
.panel {
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel-flush {
  padding: 0;
  overflow: hidden;
}

.stack > * + * {
  margin-top: 20px;
}

.cols {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  align-items: start;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.row-between {
  justify-content: space-between;
}

.muted {
  color: var(--muted);
}

.help {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.today {
  margin: 0 0 24px;
  color: var(--muted);
}

.today b {
  color: var(--text);
  font-weight: 600;
}

.today .bad,
.today a.bad b {
  color: var(--merah);
}

/* filter berbentuk segmen */
.filter {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--hover);
  border-radius: var(--radius-sm);
}

.filter a {
  padding: 4px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
}

main .filter a:hover {
  color: var(--text);
}

main .filter a[aria-current='page'] {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}

.cols-form-table {
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
}

@media (max-width: 900px) {
  .cols-form-table {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* pemilih berkas */
.file {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.file input:focus-visible + .file-btn {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Status device ---------- */
.papan-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

.papan {
  --tone: var(--abu);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  min-height: 112px;
  padding: 16px 18px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background-color 0.3s var(--ease);
}

a.papan:hover {
  border-color: var(--field-line);
  box-shadow: var(--shadow);
}

.papan .word {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 18px;
  font-weight: 650;
  line-height: 1.2;
}

.papan .word::before {
  content: '';
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--tone);
}

.papan .meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 12px;
  font-weight: 600;
}

.papan .meta span {
  color: var(--muted);
  font-weight: 400;
}

.papan--ok {
  --tone: var(--hijau);
}

.papan--ok .word {
  color: var(--hijau);
}

.papan--wait {
  --tone: var(--kuning);
}

.papan--wait .word {
  color: var(--kuning);
}

.papan--bad {
  --tone: var(--merah);
}

.papan--bad .word {
  color: var(--merah);
}

.papan--idle .word {
  color: var(--muted);
}

.papan--wide {
  min-height: 128px;
}

.papan--wide .word {
  font-size: 22px;
}

@keyframes papan-berganti {
  from {
    background: var(--hover);
  }
  to {
    background: var(--card);
  }
}

.papan.berganti {
  animation: papan-berganti 0.8s var(--ease);
}

/* ---------- Tombol ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 14px;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn.ghost {
  background: var(--card);
  color: var(--text);
  border-color: var(--field-line);
}

.btn.ghost:hover {
  background: var(--hover);
}

.btn.danger {
  background: var(--card);
  color: var(--merah);
  border-color: var(--field-line);
}

.btn.danger:hover {
  background: var(--tint-bad);
  border-color: var(--merah);
}

.btn.sm {
  min-height: 32px;
  padding: 4px 11px;
  font-size: 13.5px;
}

.rail .btn,
.topbar .btn {
  background: var(--card);
  color: var(--text);
  border-color: var(--field-line);
}

.rail .btn:hover,
.topbar .btn:hover {
  background: var(--hover);
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

form.inline {
  display: inline;
}

/* ---------- Formulir ---------- */
label {
  display: block;
  margin: 14px 0 5px;
  font-weight: 500;
}

label:first-child {
  margin-top: 0;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='datetime-local'],
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--field-line);
  border-radius: var(--radius-sm);
  font: inherit;
}

textarea {
  resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
  outline-offset: 0;
}

input[type='file'] {
  max-width: 100%;
  font: inherit;
}

input[type='file']::file-selector-button {
  margin-right: 12px;
  padding: 6px 12px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--field-line);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

input[type='file']::file-selector-button:hover {
  background: var(--hover);
}

input[type='checkbox'] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 400;
}

.form-actions {
  margin-top: 18px;
}

.error {
  margin-top: 5px;
  color: var(--merah);
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Pesan sistem ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 20px;
  padding: 11px 14px;
  border: 1px solid;
  border-radius: var(--radius-sm);
}

.alert .i {
  margin-top: 2px;
}

.alert.success {
  background: var(--tint-ok);
  color: var(--hijau);
  border-color: color-mix(in srgb, var(--hijau) 30%, transparent);
}

.alert.error {
  background: var(--tint-bad);
  color: var(--merah);
  border-color: color-mix(in srgb, var(--merah) 30%, transparent);
  margin-top: 0;
  font-size: inherit;
  font-weight: 400;
}

.alert.warn {
  background: var(--tint-wait);
  color: var(--text);
  border-color: color-mix(in srgb, var(--kuning) 40%, transparent);
}

.alert strong {
  display: block;
}

/* ---------- Chip status ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 9px;
  background: var(--hover);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.6;
  white-space: nowrap;
}

.chip-connected,
.chip-delivered,
.chip-done,
.chip-on,
.chip-received,
.chip-read {
  background: var(--tint-ok);
  color: var(--hijau);
}

.chip-qr,
.chip-connecting,
.chip-queued,
.chip-processing,
.chip-running {
  background: var(--tint-wait);
  color: var(--kuning);
}

.chip-logged_out,
.chip-failed {
  background: var(--tint-bad);
  color: var(--merah);
}

/* ---------- Tabel ---------- */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 16px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--hover);
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--hover) 60%, transparent);
}

.table-wrap table {
  min-width: 560px;
}

td.wrap {
  min-width: 240px;
  overflow-wrap: break-word;
}

.body {
  white-space: pre-wrap;
}

td .i,
.phone-cell .i {
  vertical-align: -3px;
  margin-right: 6px;
  color: var(--muted);
}

tr.row-failed td {
  background: var(--tint-bad);
}

@media (max-width: 640px) {
  .table-stack {
    min-width: 0 !important;
  }

  .table-stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .table-stack tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'phone status'
      'body body'
      'time dev';
    gap: 4px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
  }

  .table-stack tbody tr:last-child {
    border-bottom: 0;
  }

  .table-stack td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .table-stack tr.row-failed td {
    background: transparent;
  }

  .table-stack tr.row-failed {
    background: var(--tint-bad);
  }

  .table-stack .c-phone {
    grid-area: phone;
    font-weight: 600;
  }

  .table-stack .c-status {
    grid-area: status;
  }

  .table-stack .c-body {
    grid-area: body;
    min-width: 0;
  }

  .table-stack .c-time {
    grid-area: time;
    color: var(--muted);
    font-size: 13px;
  }

  .table-stack .c-dev {
    grid-area: dev;
    color: var(--muted);
    font-size: 13px;
    text-align: right;
  }
}

td .cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

code {
  padding: 1px 6px;
  background: var(--hover);
  border-radius: 4px;
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 13px;
}

pre.code {
  margin: 8px 0 0;
  padding: 14px;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

.secret {
  font-size: 14.5px;
  user-select: all;
}

/* ---------- Keadaan kosong ---------- */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.empty strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-weight: 600;
  font-size: 16px;
}

/* ---------- QR ---------- */
.qr-box {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 18px;
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.qr-box img {
  width: 280px;
  max-width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: #fff;
}

/* ---------- Inbox ---------- */
.chat {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.convo-list {
  max-height: 560px;
  overflow-y: auto;
}

.convo-item {
  display: block;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.convo-item:hover {
  background: var(--hover);
}

.convo-item[aria-current='true'] {
  background: var(--accent-soft);
}

.convo-item strong {
  display: block;
  font-weight: 600;
}

.convo-item small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 440px;
  padding: 4px;
  overflow-y: auto;
}

.bubble {
  max-width: 78%;
  padding: 8px 12px;
  background: var(--hover);
  border-radius: 12px 12px 12px 3px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bubble.out {
  align-self: flex-end;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 12px 12px 3px 12px;
}

.bubble small {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  opacity: 0.7;
}

.reply-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.reply-form input {
  flex: 1;
  min-width: 200px;
}

/* ---------- Halaman masuk / daftar ---------- */
.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  min-height: 100vh;
  padding: 32px 20px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.auth-brand .wordmark {
  font-weight: 650;
  font-size: 26px;
  letter-spacing: -0.01em;
  text-transform: capitalize;
  line-height: 1.2;
}

.auth-brand p {
  margin: 0;
  color: var(--muted);
}

.auth-form {
  width: 100%;
  max-width: 400px;
}

.auth-form .panel {
  width: 100%;
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-form h1 {
  margin-bottom: 20px;
  font-size: 22px;
}

/* ---------- Responsif ---------- */
@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 18;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
  }

  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(290px, 86vw);
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 0.28s var(--ease), visibility 0.28s;
  }

  .rail.open {
    visibility: visible;
    transform: none;
  }

  .main {
    padding: 20px 16px 56px;
  }

  .rail {
    background: var(--card);
  }

  .chat {
    grid-template-columns: minmax(0, 1fr);
  }

  .convo-list {
    max-height: 240px;
  }
}

@media (max-width: 560px) {
  .papan-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .hide-sm {
    display: none;
  }

  .bubble {
    max-width: 90%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Ringkasan: sapaan + kartu hari ini ---------- */
.hero {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) 340px;
  margin-bottom: 24px;
}

.hero h1 {
  margin-bottom: 6px;
}

.hero .panel p {
  margin: 0;
  color: var(--muted);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.stat-dark {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  background: var(--hover);
  color: var(--text);
  border-radius: var(--radius);
}

.stat-dark h2 {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.stat-dark .big {
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
}

.stat-dark .big small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.stat-dark .mini {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-dark .mini div {
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12.5px;
}

.stat-dark .mini b {
  display: block;
  color: var(--text);
  font-size: 17px;
}

.stat-dark .mini .bad b {
  color: var(--merah);
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: minmax(0, 1fr);
  }
}
