:root {
    --bg: #f1f5f9;
    --card: #ffffff;
    --soft: #e2e8f0;
    --soft-2: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --line: #cbd5e1;
    --p: #0d9488;
    --p2: #2563eb;
    --good: #16a34a;
    --warn: #d97706;
    --bad: #dc2626;
    --shadow: 0 14px 40px -10px rgba(15, 23, 42, 0.08);
    --r: 20px;
}

[data-theme="dark"] {
    --bg: #060b14;
    --card: #0f172a;
    --soft: #1e293b;
    --soft-2: #131d31;
    --text: #f8fafc;
    --muted: #94a3b8;
    --line: #26354d;
    --p: #14b8a6;
    --p2: #3b82f6;
    --shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: radial-gradient(circle at 50% -10%, rgba(37, 99, 235, 0.14) 0%, var(--bg) 48%);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.wrap {
    width: min(1200px, calc(100% - 28px));
    margin: 0 auto;
}

/* Header */
.top {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.brand {
    display: flex;
    gap: 11px;
    align-items: center;
    font-weight: 900;
    font-size: 17px;
}

.logo {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 20px;
    background: linear-gradient(135deg, var(--p), var(--p2));
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.28);
}

.brand small {
    display: block;
    font-size: 9.5px;
    color: var(--muted);
    letter-spacing: 0.1em;
    font-weight: 700;
    margin-top: 2px;
}

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

/* Buttons */
button, a, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
}

button, .btn, .icon, .tab, .preset, .switch, .link-btn {
    position: relative;
    z-index: 2;
    pointer-events: auto;
}

.btn, .icon {
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 14px;
    font-weight: 700;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.18s ease;
}

.btn:hover, .icon:hover {
    transform: translateY(-1px);
    border-color: var(--p);
}

.btn.primary {
    border: 0;
    color: #fff;
    background: linear-gradient(135deg, var(--p), var(--p2));
    box-shadow: 0 8px 22px rgba(13, 148, 136, 0.28);
}

.btn.soft {
    background: var(--soft);
    color: var(--text);
    border-color: transparent;
}

.btn.soft:hover {
    color: var(--p);
    border-color: var(--p);
}

.btn-sm {
    padding: 7px 11px;
    font-size: 12px;
    border-radius: 10px;
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 26px 0 24px;
}

.eyebrow {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--p);
    font-weight: 800;
}

.hero h1 {
    font-size: clamp(30px, 5vw, 54px);
    line-height: 1.04;
    letter-spacing: -0.04em;
    margin: 10px auto 12px;
    max-width: 820px;
    font-weight: 900;
}

.hero p {
    max-width: 720px;
    margin: 0 auto;
    color: var(--muted);
    font-size: clamp(13px, 1.6vw, 15px);
    line-height: 1.65;
}

/* Main Grid Layout */
.layout {
    display: grid;
    grid-template-columns: 1.3fr 0.7fr;
    gap: 18px;
    align-items: start;
}

.main-col, .side {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow);
}

.pad {
    padding: 20px;
}

.section {
    margin-top: 2px;
}

/* Result Hero Card */
.result {
    padding: 24px;
    background: linear-gradient(145deg, var(--card), color-mix(in srgb, var(--p) 9%, var(--card)));
    position: relative;
    overflow: hidden;
}

.result-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.big {
    font-size: clamp(34px, 5.5vw, 58px);
    font-weight: 900;
    letter-spacing: -0.04em;
    line-height: 1.05;
    margin: 10px 0 4px;
    word-break: break-word;
}

.sub {
    font-size: 12.5px;
    color: var(--muted);
}

.ring-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.ring {
    width: 98px;
    height: 98px;
    border-radius: 50%;
    background: conic-gradient(var(--ring-color, var(--p)) var(--pct, 0%), var(--soft) 0);
    display: grid;
    place-items: center;
    position: relative;
    transition: background 0.3s ease;
}

.ring::after {
    content: "";
    position: absolute;
    inset: 9px;
    background: var(--card);
    border-radius: 50%;
}

.ring span {
    z-index: 1;
    position: relative;
    font-weight: 900;
    font-size: 15px;
}

.ring-caption {
    font-size: 10px;
    color: var(--muted);
    font-weight: 700;
}

.overload-alert {
    margin-top: 14px;
    padding: 11px 14px;
    border-radius: 13px;
    background: rgba(220, 38, 38, 0.12);
    border: 1px solid rgba(220, 38, 38, 0.35);
    color: var(--bad);
    font-size: 12px;
    line-height: 1.5;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 20px;
}

.stat {
    border: 1px solid var(--line);
    background: var(--soft-2);
    border-radius: 14px;
    padding: 12px;
}

.stat small {
    color: var(--muted);
    font-size: 11px;
    display: block;
}

.stat b {
    display: block;
    font-size: 15px;
    margin-top: 4px;
    font-weight: 800;
}

/* Titles & Forms */
.title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.title h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
}

.title span {
    font-size: 11.5px;
    color: var(--muted);
    display: block;
    margin-top: 2px;
}

.actions-inline {
    display: flex;
    gap: 6px;
}

.formgrid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.field-row-2 {
    display: grid;
    grid-template-columns: 70px 1fr;
    gap: 8px;
}

.field label {
    display: block;
    font-size: 11.5px;
    font-weight: 700;
    margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="number"],
.field input:not([type]),
.field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--soft-2);
    color: var(--text);
    font-size: 13.5px;
    outline: 0;
    transition: border-color 0.15s;
}

.field input:focus,
.field select:focus {
    border-color: var(--p);
}

.field input[type="range"] {
    width: 100%;
    accent-color: var(--p);
}

.field-hint {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
    line-height: 1.5;
}

/* Device List */
.device-list {
    display: grid;
    gap: 10px;
}

.device {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    border: 1px solid var(--line);
    background: var(--soft-2);
    border-radius: 16px;
    padding: 12px 14px;
    transition: opacity 0.2s, border-color 0.2s;
}

.device:hover {
    border-color: var(--p);
}

.device.is-off {
    opacity: 0.55;
}

.devicon {
    width: 44px;
    height: 44px;
    border-radius: 13px;
    background: var(--soft);
    display: grid;
    place-items: center;
    font-size: 22px;
    flex-shrink: 0;
}

.devinfo {
    min-width: 0;
}

.devname {
    font-weight: 800;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.qty-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--soft);
    color: var(--p);
    font-weight: 800;
}

.devmeta {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 4px;
    line-height: 1.4;
}

.dev-actions {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

.link-btn {
    background: none;
    border: none;
    padding: 0;
    font-size: 11px;
    color: var(--muted);
    cursor: pointer;
    font-weight: 600;
}

.link-btn:hover {
    color: var(--p);
}

.link-btn.del-btn:hover {
    color: var(--bad);
}

.devright {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.devright b {
    font-size: 13.5px;
    font-weight: 800;
}

.devright small {
    color: var(--muted);
    font-size: 10px;
}

.switch {
    width: 42px;
    height: 24px;
    border: 0;
    border-radius: 99px;
    background: var(--line);
    position: relative;
    margin-top: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.switch::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: left 0.2s;
}

.switch.on {
    background: var(--p);
}

.switch.on::after {
    left: 21px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
    padding-bottom: 4px;
}

.tab {
    white-space: nowrap;
    border: 1px solid var(--line);
    background: var(--soft-2);
    color: var(--muted);
    border-radius: 12px;
    padding: 10px 14px;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.tab.active {
    color: #fff;
    background: linear-gradient(135deg, var(--p), var(--p2));
    border-color: transparent;
}

/* Info Components */
.money {
    font-size: 28px;
    font-weight: 900;
    letter-spacing: -0.03em;
    color: var(--p);
}

.note, .tip {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.6;
    background: var(--soft-2);
    border: 1px solid var(--line);
    padding: 11px 13px;
    border-radius: 12px;
}

.pill {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--soft);
    color: var(--p);
    font-size: 11px;
    font-weight: 800;
}

/* Analysis Bars & Charts */
.query-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.query {
    border: 1px solid var(--line);
    background: var(--soft-2);
    border-radius: 14px;
    padding: 12px;
}

.query small {
    display: block;
    color: var(--muted);
    font-size: 11px;
}

.query b {
    display: block;
    margin-top: 4px;
    font-size: 16px;
    font-weight: 800;
}

.bars {
    display: grid;
    gap: 10px;
}

.barrow {
    display: grid;
    grid-template-columns: 140px 1fr 80px;
    gap: 10px;
    align-items: center;
    font-size: 12px;
}

.bar-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.barrow b {
    text-align: right;
    font-size: 11.5px;
}

.track {
    height: 10px;
    border-radius: 99px;
    background: var(--soft);
    overflow: hidden;
}

.track i {
    height: 100%;
    display: block;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--p), var(--p2));
}

.chart {
    height: 190px;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    border: 1px solid var(--line);
    background: var(--soft-2);
    border-radius: 16px;
    padding: 16px 12px 12px;
}

.col {
    height: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
}

.col-val {
    font-size: 9px;
    color: var(--muted);
    font-weight: 700;
}

.col i {
    width: 100%;
    max-width: 28px;
    border-radius: 8px 8px 3px 3px;
    background: linear-gradient(180deg, var(--p), var(--p2));
    min-height: 4px;
    transition: height 0.25s ease;
}

.col small {
    font-size: 9.5px;
    color: var(--muted);
    font-weight: 600;
}

.actions-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

/* Share Link Box */
.share-box-output {
    border: 1px solid var(--p);
    background: var(--soft-2);
    padding: 14px;
    border-radius: 14px;
}

.share-box-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 8px;
}

.share-url-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 12.5px;
    font-family: monospace;
}

/* ==========================================
   SHARED REPORT VIEW (?s=...) STYLING
   ========================================== */
.share-banner {
    text-align: center;
    padding: 20px 0 22px;
}

.share-badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 99px;
    background: linear-gradient(135deg, rgba(13, 148, 136, 0.15), rgba(37, 99, 235, 0.15));
    color: var(--p);
    font-weight: 800;
    font-size: 11px;
    letter-spacing: 0.08em;
}

.share-banner h1 {
    margin: 10px 0 6px;
    font-size: clamp(26px, 4.5vw, 44px);
    font-weight: 900;
    letter-spacing: -0.03em;
}

.share-banner p {
    margin: 0;
    color: var(--muted);
    font-size: 13.5px;
}

.share-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 16px;
    margin-bottom: 16px;
}

.share-actions-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.share-table-wrap {
    overflow-x: auto;
}

.share-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 580px;
}

.share-table th,
.share-table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

.share-table th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.share-table tr.row-off {
    opacity: 0.5;
}

.status-dot {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
}

.status-dot.on {
    background: rgba(22, 163, 74, 0.15);
    color: var(--good);
}

.status-dot.off {
    background: var(--soft);
    color: var(--muted);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.72);
    backdrop-filter: blur(6px);
    display: none;
    visibility: hidden;
    pointer-events: none;
    align-items: center;
    justify-content: center;
    padding: 14px;
    z-index: 100;
}

.modal.show {
    display: flex;
    visibility: visible;
    pointer-events: auto;
}

.modal-card {
    width: min(680px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 22px;
    box-shadow: var(--shadow);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.modal-head h2 {
    margin: 0;
    font-size: 19px;
}

.section-sub {
    color: var(--muted);
    font-size: 12px;
    display: block;
    margin-bottom: 8px;
}

.presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}

.preset {
    border: 1px solid var(--line);
    background: var(--soft-2);
    color: var(--text);
    border-radius: 12px;
    padding: 10px;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s;
}

.preset:hover {
    border-color: var(--p);
    background: var(--soft);
}

.preset b {
    display: block;
    font-size: 12px;
    margin-bottom: 3px;
}

.preset small {
    color: var(--muted);
    font-size: 10px;
    display: block;
}

.divider {
    text-align: center;
    margin: 14px 0;
    position: relative;
}

.divider::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    background: var(--line);
}

.divider span {
    background: var(--card);
    padding: 0 10px;
    position: relative;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 28px 16px;
    font-size: 13px;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 150;
    background: var(--text);
    color: var(--card);
    box-shadow: var(--shadow);
    border-radius: 13px;
    padding: 12px 16px;
    display: none;
    max-width: 340px;
    font-size: 12.5px;
    font-weight: 700;
}

.toast.show {
    display: block;
}

footer {
    text-align: center;
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.65;
    padding: 32px 12px 44px;
    max-width: 860px;
    margin: 0 auto;
}

/* ==========================================
   FULL RESPONSIVE BREAKPOINTS
   ========================================== */
@media (max-width: 960px) {
    .layout,
    .share-grid {
        grid-template-columns: 1fr;
    }

    .side {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 680px) {
    .wrap {
        width: calc(100% - 20px);
    }

    .side,
    .formgrid {
        grid-template-columns: 1fr;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .query-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .presets {
        grid-template-columns: repeat(2, 1fr);
    }

    .barrow {
        grid-template-columns: 115px 1fr 68px;
    }

    .result {
        padding: 18px;
    }

    .pad {
        padding: 16px;
    }
}

@media (max-width: 440px) {
    .brand small {
        display: none;
    }

    .top {
        height: 62px;
    }

    .btn {
        padding: 8px 11px;
        font-size: 12px;
    }

    .result-top {
        flex-direction: column-reverse;
        align-items: flex-start;
    }

    .ring-wrap {
        flex-direction: row;
        width: 100%;
        justify-content: space-between;
        border-bottom: 1px solid var(--line);
        padding-bottom: 12px;
    }

    .ring {
        width: 64px;
        height: 64px;
    }

    .ring::after {
        inset: 6px;
    }

    .ring span {
        font-size: 12px;
    }

    .presets {
        grid-template-columns: 1fr;
    }

    .device {
        grid-template-columns: auto 1fr;
    }

    .devright {
        grid-column: 1 / -1;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        border-top: 1px dashed var(--line);
        padding-top: 8px;
        margin-top: 2px;
    }

    .switch {
        margin-top: 0;
    }
}

/* Print / PDF Mode */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
    }

    .no-print {
        display: none !important;
    }

    .wrap {
        width: 100% !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #cbd5e1 !important;
        break-inside: avoid;
    }

    .layout, .share-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Polesan interaksi: animasi ringan, fokus aksesibel, dan empty state lebih jelas */
@media (prefers-reduced-motion: no-preference) {
  .device, .card, .stat, .query, .preset, .btn, .icon { transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease, opacity .2s ease; }
  .device { animation: deviceIn .32s cubic-bezier(.2,.8,.2,1) both; }
  .device:nth-child(2) { animation-delay: .025s; }
  .device:nth-child(3) { animation-delay: .05s; }
  .device:nth-child(4) { animation-delay: .075s; }
  .btn:hover, .preset:hover { transform: translateY(-2px); }
  .card:hover { box-shadow: 0 12px 34px rgba(0,0,0,.08); }
  @keyframes deviceIn { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--p, #14b8a6); outline-offset: 3px; }
.empty { border: 1px dashed var(--border, #94a3b8); border-radius: 16px; padding: 24px 18px; text-align: center; line-height: 1.65; }
