:root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1f2330;
    --border: #2a2f3d;
    --text: #e7e9ee;
    --muted: #9aa1b1;
    --primary: #4f7cff;
    --primary-hover: #3d68e8;
    --danger: #e5484d;
    --ok: #30a46c;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Topbar */
.topbar {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    padding: 18px 0;
    margin-bottom: 28px;
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.topbar h1 { margin: 0; font-size: 1.4rem; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }
.topbar-actions { display: flex; gap: 8px; }

/* Menubar di bawah judul */
.topbar-title { margin-bottom: 14px; }
.menubar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}
.menubar a {
    padding: 8px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.9rem;
    transition: background .15s, color .15s;
}
.menubar a:hover { background: var(--surface-2); color: var(--text); }
.menubar a.active { background: var(--primary); color: #fff; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 9px;
    border: 1px solid transparent;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, transform .05s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-copy { background: var(--primary); color: #fff; }
.btn-copy:hover { background: var(--primary-hover); }
.btn-copy.copied { background: var(--ok); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 0.8rem; }

/* Search */
.search-wrap {
    position: relative;
    margin-bottom: 26px;
    max-width: 520px;
}
.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}
.search-input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 13px 44px 13px 46px;
    font-size: 0.95rem;
    transition: border-color .15s, box-shadow .15s;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 124, 255, .25);
}
.search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: var(--surface);
    color: var(--muted);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}
.search-clear:hover { color: var(--text); background: var(--border); }

/* Groups + link cards (homepage) */
.group { margin-bottom: 26px; }
.group-title {
    margin: 0 0 12px;
    font-size: 1.1rem;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.link-list { display: flex; flex-direction: column; gap: 10px; }
.link-card {
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.label-badge {
    flex-shrink: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}
.label-badge.sm { padding: 2px 9px; font-size: 0.72rem; margin-right: 6px; }
.link-url {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 8px 12px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.88rem;
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 60px 20px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

/* Cards / forms */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 22px;
}
.card h2 { margin: 0 0 16px; font-size: 1.1rem; }

label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.88rem;
    color: var(--muted);
}
input[type=text], input[type=password], input[type=number], input[type=search], textarea {
    width: 100%;
    margin-top: 5px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 10px 12px;
    font-size: 0.95rem;
    font-family: inherit;
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}
textarea { resize: vertical; }
.form-actions { display: flex; gap: 8px; }
label.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}
label.checkbox input { width: auto; margin: 0; }
.example {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 12px;
    font-size: 0.8rem;
    color: var(--muted);
    overflow-x: auto;
    white-space: pre;
    margin: 0 0 14px;
}

/* Alerts */
.alert { padding: 10px 14px; border-radius: 9px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-ok { background: rgba(48,164,108,.15); color: #7ee2b0; border: 1px solid rgba(48,164,108,.4); }
.alert-error { background: rgba(229,72,77,.15); color: #ff9ea1; border: 1px solid rgba(229,72,77,.4); }

/* Auth page */
.auth-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin: 0 0 18px; font-size: 1.3rem; }
.back-link { display: inline-block; margin-top: 14px; color: var(--muted); font-size: 0.85rem; text-decoration: none; }
.back-link:hover { color: var(--text); }
.checkbox-row { display: flex; flex-direction: row; align-items: center; gap: 8px; font-size: 0.9rem; cursor: pointer; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row span { color: var(--muted); }

/* Admin table */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .03em; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; word-break: break-all; }
.bulk-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.cat-cell .row-check { margin-right: 8px; vertical-align: middle; }
.mt-12 { margin-top: 12px; }

/* Halaman kirim (copy semua link sekaligus) */
.send-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.send-head h2 { margin: 0; font-size: 1.1rem; }
.send-box {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 12px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    resize: vertical;
}
.send-box:focus { outline: none; border-color: var(--primary); }
.btn-primary.copied { background: var(--ok); }

@media (max-width: 560px) {
    .container { padding: 0 12px; }

    /* Topbar boleh turun ke baris baru */
    .topbar-inner { flex-wrap: wrap; }
    .topbar h1 { font-size: 1.2rem; }

    /* Kartu link di homepage: URL full di atas, label + copy di bawah */
    .link-card { flex-wrap: wrap; }
    .link-url { flex: 1 1 100%; order: 1; }
    .label-badge { order: 2; }
    .btn-copy { order: 3; margin-left: auto; }

    .card { padding: 16px; }

    /* Tabel admin diubah jadi tumpukan kartu biar muat di layar HP */
    .admin-table thead { display: none; }
    .admin-table,
    .admin-table tbody,
    .admin-table tr,
    .admin-table td { display: block; width: 100%; }
    .admin-table tr {
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 12px 14px;
        margin-bottom: 12px;
    }
    .admin-table td { border: none; padding: 4px 0; }
    .row-actions { margin-top: 10px; }
}

/* ============================================================
   DASHBOARD REALTIME + kontrol modern (tema gelap)
   ============================================================ */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 18px;
}
.toolbar .spacer { margin-left: auto; }

/* Segmented control */
.seg {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}
.seg button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 7px 14px;
    border-radius: 7px;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(79, 124, 255, .35);
}

/* Select modern */
.select, .toolbar select {
    appearance: none;
    background: var(--surface-2) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa1b1' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>") no-repeat right 12px center;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 9px 34px 9px 13px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}
.select:focus, .toolbar select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 124, 255, .22);
}
.toolbar input[type=date] {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 8px 11px;
    font: inherit;
    color-scheme: dark;
}

/* KPI cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.kpi {
    position: relative;
    background: linear-gradient(160deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    overflow: hidden;
    transition: transform .12s, border-color .15s;
}
.kpi:hover { transform: translateY(-2px); border-color: var(--primary); }
.kpi::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--primary);
    opacity: .8;
}
.kpi .label {
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
}
.kpi .value { font-size: 1.6rem; font-weight: 800; margin-top: 6px; letter-spacing: -.01em; }
.kpi .sub { font-size: 0.78rem; margin-top: 4px; }
.kpi.accent::before { background: var(--ok); }
.up { color: var(--ok); }
.down { color: var(--danger); }

/* Live dot */
.live-dot {
    display: inline-block;
    width: 9px; height: 9px;
    border-radius: 50%;
    background: var(--ok);
    margin-right: 8px;
    box-shadow: 0 0 0 0 rgba(48, 164, 108, .6);
    animation: livepulse 1.6s infinite;
}
@keyframes livepulse {
    0% { box-shadow: 0 0 0 0 rgba(48, 164, 108, .55); }
    70% { box-shadow: 0 0 0 7px rgba(48, 164, 108, 0); }
    100% { box-shadow: 0 0 0 0 rgba(48, 164, 108, 0); }
}

/* Chart */
.chart-wrap { position: relative; }
.chart-wrap canvas {
    width: 100%;
    height: 230px;
    display: block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}

/* Dashboard tables */
table.dash { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.dash th, table.dash td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
table.dash th { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: .04em; }
table.dash tbody tr { transition: background .12s; }
table.dash tbody tr:hover { background: var(--surface-2); }
table.dash .num { text-align: right; font-variant-numeric: tabular-nums; }
.prod-title { display: flex; align-items: center; gap: 9px; }
.prod-title img { width: 34px; height: 34px; border-radius: 7px; object-fit: cover; flex-shrink: 0; }

/* Account picker (dashboard pilih akun dulu) */
.acct-hero {
    text-align: center;
    padding: 56px 20px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--muted);
}
.acct-hero h2 { color: var(--text); margin: 0 0 6px; }
.badge-live {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--ok);
    background: rgba(48,164,108,.15);
    border: 1px solid rgba(48,164,108,.4);
    border-radius: 999px;
    padding: 2px 9px;
    margin-left: 6px;
}
.badge-off {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 9px;
    margin-left: 6px;
}
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .dash-grid { grid-template-columns: 1fr; } }

/* Tombol refresh bulat */
.btn-refresh {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
}
.btn-refresh:hover { border-color: var(--primary); color: var(--primary); }
.btn-refresh:active { transform: scale(.92); }
.btn-refresh:disabled { opacity: .6; cursor: default; }
.btn-refresh.spinning svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Search produk dashboard */
.dash-search {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 8px 13px;
    font: inherit;
    font-size: 0.9rem;
    min-width: 160px;
    transition: border-color .15s, box-shadow .15s;
}
.dash-search::placeholder { color: var(--muted); }
.dash-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,124,255,.22); }

/* Pager produk */
.pager {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 12px;
}

/* Modal konfirmasi (anti popup browser) */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    max-width: 430px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    animation: modalpop .15s ease-out;
}
@keyframes modalpop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h3 { margin: 0 0 10px; font-size: 1.1rem; }
.modal p { margin: 0 0 18px; color: var(--muted); font-size: .92rem; line-height: 1.6; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Dashboard lebih lebar */
.container-wide { max-width: 1180px; }

/* Tabel scroll horizontal sendiri (anti halaman kepotong di HP) */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll .dash { min-width: 600px; }

/* Tweak mobile dashboard */
@media (max-width: 600px) {
    .container-wide { padding: 0 12px; }
    .hero-value { font-size: 1.8rem; }
    .kpi .value { font-size: 1.3rem; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .toolbar { gap: 6px; }
    .toolbar .select, .toolbar input[type=date], .toolbar input[type=time] { font-size: 0.82rem; }
    .seg button { padding: 6px 10px; font-size: 0.8rem; }
}

/* Chip checkbox (filter multi-sesi) */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    user-select: none;
    transition: border-color .12s, background .12s;
}
.chip input { accent-color: var(--primary); margin: 0; }
.chip.on { border-color: var(--primary); color: #fff; background: rgba(79, 124, 255, .18); }

/* input time di toolbar */
.toolbar input[type=time] {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 8px 10px;
    font: inherit;
    color-scheme: dark;
}

/* panah sort di header tabel */
.dash th[data-col] { cursor: pointer; user-select: none; white-space: nowrap; }
.dash th[data-col] .arr { opacity: .45; font-size: .85em; }
.dash th[data-col].active .arr { opacity: 1; color: var(--primary); }

/* Hero GMV (mirip Shopee) */
.hero-card {
    text-align: center;
    background: linear-gradient(160deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 18px;
    margin-bottom: 16px;
}
.hero-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.hero-value { font-size: 2.6rem; font-weight: 800; margin: 6px 0 2px; letter-spacing: -.02em; }
.hero-sub { color: var(--muted); font-size: 0.9rem; }
@media (max-width: 560px) { .hero-value { font-size: 1.9rem; } }

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

/* Grid metrik kecil (12 angka) ala Shopee */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 18px;
}
.metric-grid .m { background: var(--surface); padding: 12px 14px; }
.metric-grid .m .ml { color: var(--muted); font-size: 0.72rem; }
.metric-grid .m .mv { font-size: 1.1rem; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.section-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; font-weight: 600; }

/* ---- Convert CSV ---- */
.convert-form { display: flex; flex-direction: column; gap: 14px; }
.field-label { font-weight: 600; font-size: 0.95rem; }
.radio-row { display: flex; flex-direction: column; gap: 10px; }
.radio-opt {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 9px;
    cursor: pointer;
}
.radio-opt:hover { border-color: var(--primary); }
.radio-opt input { accent-color: var(--primary); width: 16px; height: 16px; }
.radio-opt code { font-size: 0.82rem; opacity: 0.8; }
/* Kotak besar drag & drop */
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    min-height: 190px;
    padding: 28px 18px;
    border: 2px dashed var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.02);
    color: inherit;
    cursor: pointer;
    transition: border-color .15s, background .15s, transform .05s;
}
.dropzone:hover { border-color: var(--primary); }
.dropzone.dragover {
    border-color: var(--primary);
    background: rgba(79, 124, 255, 0.12);
    transform: scale(1.01);
}
.dropzone.has-file { border-style: solid; border-color: var(--ok, #2ecc71); }
.dz-icon { color: var(--primary); opacity: 0.9; }
.dz-title { font-weight: 600; font-size: 1rem; }
.dz-sub { font-size: 0.85rem; opacity: 0.7; }
.dz-file {
    margin-top: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--ok, #2ecc71);
    word-break: break-all;
}
.convert-form .btn-primary { align-self: flex-start; }
.hint {
    margin-top: 16px;
    font-size: 0.85rem;
    line-height: 1.7;
    opacity: 0.85;
}
.hint code {
    font-size: 0.8rem;
    background: var(--border);
    padding: 1px 5px;
    border-radius: 5px;
}
