/* ── Dark theme (default) ── */
:root, [data-theme="dark"] {
  --bg:         #0d1729;
  --surface:    #1a2540;
  --surface-2:  #1f2d4a;
  --border:     #2d3d5a;
  --accent:     #3b82f6;
  --accent-h:   #2563eb;
  --green:      #10b981;
  --amber:      #f59e0b;
  --red:        #ef4444;
  --text:       #e2e8f0;
  --text-muted: #94a3b8;
  --radius:     8px;
  --shadow:     0 2px 12px rgba(0,0,0,.4);
  --log-bg:     #000;
  --log-fg:     #9df;
  --badge-a:    20;
}

/* ── Light theme ── */
[data-theme="light"] {
  --bg:         #f1f5f9;
  --surface:    #ffffff;
  --surface-2:  #e9eef5;
  --border:     #cbd5e1;
  --accent:     #2563eb;
  --accent-h:   #1d4ed8;
  --green:      #059669;
  --amber:      #d97706;
  --red:        #dc2626;
  --text:       #0f172a;
  --text-muted: #64748b;
  --radius:     8px;
  --shadow:     0 1px 6px rgba(15,23,42,.10);
  --log-bg:     #0f172a;
  --log-fg:     #7dd3fc;
}

/* ── Anthropic terang ──
   Abu hangat condong ke cokelat, bukan abu kebiruan seperti tema bawaan.
   Aksen terakota dipakai di kedua skin Anthropic supaya terasa satu keluarga. */
[data-theme="anth-light"] {
  --bg:         #F0EEE6;
  --surface:    #FAF9F5;
  --surface-2:  #E8E5DC;
  --border:     #D6D2C4;
  --accent:     #C15F3C;
  --accent-h:   #A84B2A;
  --green:      #4A7C59;
  --amber:      #B8862B;
  --red:        #BC4A3C;
  --text:       #141413;
  --text-muted: #6B6862;
  --radius:     8px;
  --shadow:     0 1px 6px rgba(20,20,19,.08);
  --log-bg:     #262624;
  --log-fg:     #D4A27F;
}

/* ── Anthropic gelap ── */
[data-theme="anth-dark"] {
  --bg:         #1F1E1D;
  --surface:    #262624;
  --surface-2:  #30302D;
  --border:     #3E3D3A;
  --accent:     #D97757;
  --accent-h:   #C15F3C;
  --green:      #6BA77F;
  --amber:      #D4A27F;
  --red:        #E07B6A;
  --text:       #F5F4EF;
  --text-muted: #A3A098;
  --radius:     8px;
  --shadow:     0 2px 12px rgba(0,0,0,.35);
  --log-bg:     #141413;
  --log-fg:     #D4A27F;
  --badge-a:    22;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'Courier New', monospace; font-size: .85em; background: var(--surface); padding: .1em .3em; border-radius: 3px; }

/* ── Top Nav ── */
.topnav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .6rem 1rem;
}
.nav-brand { display: flex; align-items: center; gap: .4rem; font-weight: 700; font-size: 1rem; }
.nav-logo  { font-size: 1.2rem; }
.nav-title { color: var(--text); }
.nav-toggle { margin-left: auto; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 4px; padding: .3rem .6rem; cursor: pointer; display: none; }
.nav-links  { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav-link   { padding: .35rem .7rem; border-radius: 5px; color: var(--text-muted); font-size: .85rem; transition: background .15s, color .15s; }
.nav-link:hover, .nav-link.active { background: var(--accent); color: #fff; text-decoration: none; }
.nav-logout { margin-left: .5rem; }

@media (max-width: 640px) {
  .nav-toggle { display: block; }
  .nav-links  { display: none; width: 100%; flex-direction: column; gap: .1rem; }
  .nav-links.open { display: flex; }
  .nav-link   { padding: .6rem .8rem; }
}

/* ── Login ── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.login-logo  { font-size: 2.5rem; text-align: center; margin-bottom: .5rem; }
.login-title { text-align: center; font-size: 1.1rem; font-weight: 600; margin-bottom: 1.5rem; color: var(--text-muted); }
.login-form  { display: flex; flex-direction: column; gap: .75rem; }

/* ── Container / Layout ── */
.container   { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.25rem; }
.page-title  { font-size: 1.3rem; font-weight: 700; }
.section-title { font-size: .95rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: 1.5rem 0 .75rem; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

/* ── KPI Cards ── */
.kpi-grid  { display: grid; grid-template-columns: repeat(4,1fr); gap: .75rem; }
.kpi-card  { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1; }
.kpi-label { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }
.kpi-today    { border-top: 3px solid var(--green); }
.kpi-week     { border-top: 3px solid var(--accent); }
.kpi-abandoned{ border-top: 3px solid var(--amber); }

@media (max-width: 640px) { .kpi-grid { grid-template-columns: repeat(2,1fr); } }

/* ── Site Grid ── */
.site-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: .5rem; }
.site-card { display: flex; align-items: center; gap: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem 1rem; text-decoration: none; color: var(--text); transition: background .15s; }
.site-card:hover { background: var(--surface-2); text-decoration: none; }
.site-dot  { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.site-name { flex: 1; font-size: .85rem; }
.site-count{ font-weight: 700; font-size: 1.1rem; }

@media (max-width: 640px) { .site-grid { grid-template-columns: repeat(2,1fr); } }

/* ── Pipeline / Sync Lists ── */
.pipeline-list { display: flex; flex-direction: column; gap: .4rem; }
.pipeline-row  { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: .5rem .75rem; }
.pipeline-cnt  { font-weight: 700; }
.sync-list     { display: flex; flex-direction: column; gap: .4rem; }
.sync-row      { display: flex; align-items: center; gap: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: .45rem .75rem; flex-wrap: wrap; }
.sync-status   { font-size: 1rem; }
.sync-status.ok { color: var(--green); }
.sync-status.err { color: var(--red); }
.sync-status.pending { color: var(--amber); }
.sync-time     { color: var(--text-muted); font-size: .78rem; margin-left: auto; }

/* ── Badges ── */
.badge { display: inline-block; padding: .2em .55em; border-radius: 4px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-count { background: var(--accent); color: #fff; padding: .15em .5em; border-radius: 99px; font-size: .75rem; margin-left: .4rem; }

/* ── Table ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; }
.table thead { background: var(--surface-2); }
.table th { padding: .6rem .8rem; text-align: left; font-size: .78rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.table td { padding: .6rem .8rem; border-top: 1px solid var(--border); font-size: .85rem; vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.td-time   { color: var(--text-muted); white-space: nowrap; font-size: .78rem; }
.empty-row { text-align: center; color: var(--text-muted); padding: 2rem !important; }
.wa-link   { color: var(--green); white-space: nowrap; }

/* ── Forms / Inputs ── */
.input { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; color: var(--text); padding: .5rem .7rem; font-size: .9rem; transition: border-color .15s; }
.input:focus { outline: none; border-color: var(--accent); }
.input-sm { width: auto; min-width: 0; font-size: .82rem; padding: .4rem .6rem; }
select.input { cursor: pointer; }
textarea.input { resize: vertical; }

.filter-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }

.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; }
.form-hint  { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem 1rem; border-radius: 5px; font-size: .85rem; font-weight: 600; cursor: pointer; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); transition: background .15s, border-color .15s; text-decoration: none; }
.btn:hover { background: var(--surface); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-ghost { background: transparent; }
.btn-sm  { padding: .35rem .7rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Alerts ── */
.alert { padding: .75rem 1rem; border-radius: 5px; font-size: .88rem; border: 1px solid var(--border); background: var(--surface); }
.alert-error { border-color: var(--red); background: rgba(239,68,68,.1); color: var(--red); }
.alert-ok    { border-color: var(--green); background: rgba(16,185,129,.1); color: var(--green); }
.alert-warn  { border-color: var(--amber); background: rgba(245,158,11,.1); color: var(--amber); }

/* ── Detail Page ── */
.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; }
@media (max-width: 768px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.card-title  { font-size: .85rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .75rem; }
.def-list { display: grid; grid-template-columns: 100px 1fr; gap: .35rem .75rem; }
.def-list dt { color: var(--text-muted); font-size: .82rem; font-weight: 600; padding-top: .1rem; }
.def-list dd { font-size: .88rem; word-break: break-all; }
.save-msg { font-size: .78rem; color: var(--green); margin-top: .25rem; height: 1em; }

/* ── Log Pre ── */
.log-pre { background: var(--log-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; font-size: .75rem; overflow-x: auto; white-space: pre; color: var(--log-fg); max-height: 400px; overflow-y: auto; }

/* ── Info Box ── */
.info-box { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: .875rem 1rem; font-size: .85rem; }
.info-box code { display: block; margin-top: .4rem; font-size: .78rem; background: var(--bg); padding: .5rem; border-radius: 4px; word-break: break-all; }

/* ── Pagination ── */
.pagination { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: 1rem; }
.page-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; padding: 0 .5rem; border-radius: 4px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: .82rem; text-decoration: none; }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:hover { background: var(--surface-2); text-decoration: none; }

/* ── Misc ── */
.text-muted { color: var(--text-muted); }
.link { color: var(--accent); }

/* v1.1 additions */
.page-gap { color: var(--text-muted); padding: 0 .25rem; align-self: center; }
optgroup { background: var(--surface); color: var(--text-muted); font-style: normal; }
.filter-bar { align-items: stretch; }
.filter-bar .input-sm { min-height: 34px; }


/* ── Theme toggle ── */
.theme-btn {
  background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: 5px; padding: .3rem .55rem; cursor: pointer;
  font-size: .95rem; line-height: 1; margin-left: .25rem;
  transition: background .15s, border-color .15s;
}
.theme-btn:hover { background: var(--surface-2); border-color: var(--accent); }
@media (max-width: 640px) {
  .theme-btn { margin-left: auto; margin-right: .35rem; }
}

/* Light-mode legibility tweaks */
[data-theme="light"] body { background: var(--bg); }
[data-theme="light"] .table thead { background: var(--surface-2); }
[data-theme="light"] .nav-link { color: var(--text-muted); }
[data-theme="light"] .nav-link:hover,
[data-theme="light"] .nav-link.active { color: #fff; }
[data-theme="light"] input[type="date"] { color-scheme: light; }
[data-theme="dark"]  input[type="date"] { color-scheme: dark; }
[data-theme="light"] code { background: var(--surface-2); }

/* ── v1.4: Campaign & Segment ── */
.progress-wrap { margin-bottom: .85rem; }
.progress-bar  { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .35s ease; }

.email-preview {
  background: #ffffff; color: #1f2937; border: 1px solid var(--border);
  border-radius: 6px; padding: 1rem; font-size: .85rem; line-height: 1.6;
  max-height: 340px; overflow-y: auto;
}
.email-preview a { color: #2563eb; }
.email-preview img { max-width: 100%; height: auto; }

.seg-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
@media (max-width: 560px) { .seg-filters { grid-template-columns: 1fr; } }

.nav-links { flex-wrap: wrap; }
@media (min-width: 641px) and (max-width: 1080px) {
  .nav-link { padding: .35rem .5rem; font-size: .78rem; }
}

/* ── v1.6: Result info bar ── */
.result-info {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .4rem;
  font-size: .82rem; color: var(--text-muted);
  padding: .4rem .1rem .6rem;
}
.result-info strong { color: var(--text); font-weight: 700; }
.result-meta { font-size: .78rem; }
.result-info-bottom { padding-top: .8rem; border-top: 1px solid var(--border); margin-top: .5rem; }

/* ── v1.7: Bulk select, inline pipeline, modal ── */
.col-check { width: 38px; text-align: center; }
.col-check input[type="checkbox"] {
  width: 18px; height: 18px; cursor: pointer; accent-color: var(--accent); margin: 0;
}
.table-select tbody td:not(.col-check):not(.col-pipeline) { cursor: pointer; }

.pipe-btn {
  display: inline-flex; align-items: center; gap: .2rem;
  background: none; border: 1px solid transparent; border-radius: 5px;
  padding: .15rem .3rem; cursor: pointer; font: inherit; color: inherit;
  transition: border-color .15s, background .15s;
}
.pipe-btn:hover { border-color: var(--border); background: var(--surface-2); }
.pipe-caret { font-size: .65rem; color: var(--text-muted); }

/* Bulk toolbar */
.bulk-bar {
  display: none; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .6rem;
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: .6rem .85rem; margin-bottom: .85rem;
}
.bulk-bar.open { display: flex; }
.bulk-count { font-size: .85rem; }
.bulk-count strong { color: var(--accent); font-size: 1rem; }
.bulk-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
@media (max-width: 640px) {
  .bulk-bar { position: sticky; top: 52px; z-index: 50; box-shadow: var(--shadow); }
  .bulk-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.55); align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.25rem; width: 100%; max-width: 340px; box-shadow: var(--shadow);
  max-height: 85vh; overflow-y: auto;
}
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; }
.modal-options { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.modal-opt {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: .6rem .75rem; cursor: pointer; font: inherit; color: var(--text);
  text-align: left; transition: border-color .15s, background .15s;
}
.modal-opt:hover { border-color: var(--accent); background: var(--surface-2); }
@media (max-width: 560px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-sheet { max-width: none; border-radius: 14px 14px 0 0; padding-bottom: 1.5rem; }
}

/* ── v2.0: Suppressed indicator ── */
.supp-badge {
  background: rgba(245,158,11,.18); color: var(--amber);
  border: 1px solid rgba(245,158,11,.35);
  margin-left: .25rem; cursor: help;
}
tr:has(.supp-badge) { opacity: .72; }

/* ── v2.3: Service column ── */
.td-service { font-size: .8rem; max-width: 180px; }

/* ── v2.4: Pagination bar (phpMyAdmin style) ── */
.pagebar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .45rem .7rem; margin: .5rem 0;
  font-size: .82rem; color: var(--text-muted);
}
.pagebar-group { display: flex; align-items: center; gap: .35rem; }
.pagebar-label { font-size: .78rem; white-space: nowrap; }
.pagebar-range { white-space: nowrap; }
.pagebar-range strong { color: var(--text); }
.pagebar-select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); padding: .28rem 1.4rem .28rem .5rem; font-size: .82rem;
  cursor: pointer; max-height: 32px;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 8px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.pagebar-select:focus { outline: none; border-color: var(--accent); }
.pagebar-nav {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 5px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); font-size: 1.15rem; line-height: 1; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.pagebar-nav:hover { background: var(--surface-2); border-color: var(--accent); text-decoration: none; }
.pagebar-nav.disabled { opacity: .3; pointer-events: none; }

@media (max-width: 560px) {
  .pagebar { justify-content: center; gap: .4rem .6rem; }
  .pagebar-range { order: -1; width: 100%; text-align: center; }
}

/* ── v2.5: nomor halaman di desktop, dropdown di mobile ── */
.pagebar-nums { display: inline-flex; align-items: center; gap: .2rem; }
.pagebar-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 .45rem;
  border-radius: 5px; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); font-size: .82rem; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.pagebar-num:hover { background: var(--surface-2); border-color: var(--accent); text-decoration: none; }
.pagebar-num.active {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700;
}
.pagebar-gap { color: var(--text-muted); padding: 0 .15rem; }

/* Default (desktop): tombol angka tampil, dropdown halaman disembunyikan */
.pagebar-pagesel, .pagebar-pagesel-label { display: none; }

@media (max-width: 820px) {
  .pagebar-nums { display: none; }
  .pagebar-pagesel { display: inline-block; }
  .pagebar-pagesel-label { display: inline; }
}

/* ── v2.6: nomor internasional ── */
.wa-link { white-space: nowrap; }

/* ── v2.7: WhatsApp channel ── */
.channel-tabs { display: flex; gap: .3rem; margin-top: .6rem; }
.channel-tab {
  padding: .35rem .8rem; border-radius: 6px; font-size: .82rem; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-muted); text-decoration: none;
}
.channel-tab:hover { border-color: var(--accent); text-decoration: none; }
.channel-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.wa-preview {
  background: #dcf8c6; color: #111b21;
  border-radius: 10px 10px 10px 2px; padding: .75rem .9rem;
  font-size: .88rem; line-height: 1.55; max-width: 90%;
  box-shadow: 0 1px 2px rgba(0,0,0,.15); word-break: break-word;
}
[data-theme="dark"] .wa-preview { background: #005c4b; color: #e9edef; }

/* ── v2.8: form segment ── */
#seg-form { scroll-margin-top: 70px; }
