/* OpenClaw Gateway Dashboard — Pixel-perfect clone */
:root {
    --bg: #f5f5f7;
    --surface: #fff;
    --surface2: #f0f0f2;
    --border: #e2e2e7;
    --text: #1a1a1a;
    --text2: #6e6e80;
    --text3: #9292a0;
    --accent: #dc2626;
    --accent-hover: #b91c1c;
    --accent-bg: #fef2f2;
    --accent-border: #fecaca;
    --sidebar-w: 220px;
    --header-h: 50px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .06);
    --green: #16a34a;
    --orange: #d97706
}

[data-theme=dark] {
    --bg: #0f0f11;
    --surface: #1a1a1e;
    --surface2: #242428;
    --border: #2e2e36;
    --text: #f0f0f2;
    --text2: #9292a8;
    --text3: #5a5a6e;
    --accent-bg: #1f0a0a;
    --accent-border: #7f1d1d;
    --shadow: 0 1px 3px rgba(0, 0, 0, .3)
}

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

html,
body {
    height: 100%;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text)
}

button {
    cursor: pointer;
    font-family: inherit;
    border: none;
    outline: none;
    font-size: 13px
}

input,
textarea,
select {
    font-family: inherit;
    font-size: 13px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    padding: 8px 12px
}

input:focus,
textarea:focus {
    border-color: var(--accent)
}

code,
pre {
    font-family: 'JetBrains Mono', monospace
}

a {
    text-decoration: none;
    color: inherit
}

::-webkit-scrollbar {
    width: 5px
}

::-webkit-scrollbar-track {
    background: transparent
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px
}

/* Layout */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden
}

#header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    gap: 10px;
    z-index: 100;
    flex-shrink: 0
}

#body {
    display: flex;
    flex: 1;
    overflow: hidden
}

#sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    transition: width .2s
}

#sidebar.collapsed {
    width: 0;
    overflow: hidden
}

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden
}

/* Header */
.hdr-btn {
    background: none;
    color: var(--text2);
    width: 34px;
    height: 34px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    transition: background .15s
}

.hdr-btn:hover {
    background: var(--surface2)
}

#branding {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1
}

#logo {
    width: 30px;
    height: 30px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    flex-shrink: 0
}

.brand-name {
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .04em
}

.brand-sub {
    font-size: 10px;
    letter-spacing: .1em;
    color: var(--text3);
    text-transform: uppercase
}

#health {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace
}

#health.on {
    border-color: var(--green);
    color: var(--green)
}

#health.off {
    border-color: var(--accent);
    color: var(--accent)
}

#health .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor
}

.theme-group {
    display: flex;
    gap: 2px;
    padding: 2px;
    background: var(--surface2);
    border-radius: 8px;
    border: 1px solid var(--border)
}

.t-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text2);
    font-size: 13px;
    transition: .15s
}

.t-btn.on {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow)
}

/* Sidebar */
.nav-sec {
    padding: 14px 8px 2px
}

.nav-lbl {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text3);
    padding: 0 8px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: space-between
}

.nav-lbl .collapse-btn {
    background: none;
    color: var(--text3);
    font-size: 10px;
    padding: 0 4px
}

.ni {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--text2);
    cursor: pointer;
    transition: .12s;
    margin: 1px 0;
    white-space: nowrap;
    font-size: 13px;
    border-left: 3px solid transparent
}

.ni:hover {
    background: var(--surface2);
    color: var(--text)
}

.ni.on {
    background: var(--accent-bg);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 500
}

.ni svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px
}

/* Panels */
.pn {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden
}

.pn.on {
    display: flex
}

.pn-hdr {
    padding: 20px 24px 8px;
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap
}

.pn-hdr-left {
    flex: 1;
    min-width: 0
}

.pn-title {
    font-size: 22px;
    font-weight: 700
}

.pn-desc {
    font-size: 13px;
    color: var(--text2);
    margin-top: 2px
}

.pn-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px 24px
}

.alert-pill {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap
}

.alert-pill.ok {
    background: var(--accent-bg);
    color: var(--accent);
    border: 1px solid var(--accent-border)
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
    margin-bottom: 12px;
    box-shadow: var(--shadow)
}

.card-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 3px
}

.card-desc {
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 14px
}

.kv {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px
}

.kv:last-child {
    border-bottom: none
}

.kv-k {
    color: var(--text2);
    flex: 1
}

.kv-v {
    font-weight: 500;
    text-align: right
}

.badge {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600
}

.badge.g {
    background: #dcfce7;
    color: #15803d
}

.badge.r {
    background: #fee2e2;
    color: #dc2626
}

.badge.y {
    background: #fef3c7;
    color: #92400e
}

[data-theme=dark] .badge.g {
    background: #14532d;
    color: #4ade80
}

[data-theme=dark] .badge.r {
    background: #7f1d1d;
    color: #f87171
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px
}

@media(max-width:768px) {
    .two-col {
        grid-template-columns: 1fr
    }
}

.snap-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px
}

.snap-item {
    background: var(--surface2);
    border-radius: 8px;
    padding: 12px;
    text-align: center
}

.snap-val {
    font-size: 18px;
    font-weight: 700
}

.snap-lbl {
    font-size: 11px;
    color: var(--text2);
    margin-top: 2px
}

.snap-item.warn .snap-val {
    color: var(--accent)
}

.btn {
    padding: 7px 14px;
    border-radius: 7px;
    font-weight: 500;
    font-size: 13px;
    transition: .15s;
    display: inline-flex;
    align-items: center;
    gap: 5px
}

.btn-p {
    background: var(--accent);
    color: #fff
}

.btn-p:hover {
    background: var(--accent-hover)
}

.btn-s {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border)
}

.btn-s:hover {
    background: var(--surface2)
}

.btn-o {
    background: none;
    color: var(--accent);
    border: 1px solid var(--accent-border)
}

.btn-o:hover {
    background: var(--accent-bg)
}

.btn-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px
}

.input-row label {
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 3px;
    display: block
}

.input-row input {
    width: 100%
}

.tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 8px
}

.tbl th {
    text-align: left;
    font-weight: 500;
    color: var(--text2);
    padding: 6px 8px;
    border-bottom: 2px solid var(--border);
    font-size: 12px
}

.tbl td {
    padding: 8px;
    border-bottom: 1px solid var(--border)
}

.tbl tr:hover td {
    background: var(--surface2)
}

.empty {
    color: var(--text3);
    font-size: 13px;
    padding: 16px 0
}

/* Chat */
#chat-hdr {
    padding: 16px 20px 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0
}

#chat-hdr-left {
    flex: 1;
    min-width: 0
}

.ch-title {
    font-size: 18px;
    font-weight: 700
}

.ch-desc {
    font-size: 12px;
    color: var(--text2);
    margin-top: 1px
}

#chat-hdr-right {
    display: flex;
    align-items: center;
    gap: 6px
}

.ib {
    background: none;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text2);
    font-size: 14px;
    transition: .15s
}

.ib:hover {
    background: var(--surface2);
    color: var(--text)
}

.ib.on {
    background: var(--accent-bg);
    color: var(--accent);
    border-color: var(--accent-border)
}

#sess-sel {
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 12px;
    min-width: 130px
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500
}

.status-pill.ok {
    background: var(--accent-bg);
    color: var(--accent);
    border: 1px solid var(--accent-border)
}

.status-pill.con {
    background: #fef9c3;
    color: #854d0e;
    border: 1px solid #fde68a
}

#msgs {
    flex: 1;
    overflow-y: auto;
    padding: 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px
}

.m {
    display: flex;
    flex-direction: column;
    max-width: 78%;
    animation: fi .2s ease
}

.m.u {
    align-self: flex-end;
    align-items: flex-end
}

.m.a {
    align-self: flex-start;
    align-items: flex-start
}

.m.s {
    align-self: center
}

@keyframes fi {
    from {
        opacity: 0;
        transform: translateY(4px)
    }

    to {
        opacity: 1
    }
}

.mb {
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.55;
    word-break: break-word
}

.m.u .mb {
    background: var(--accent);
    color: #fff;
    border-radius: 12px 12px 3px 12px
}

.m.a .mb {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px 12px 12px 3px;
    box-shadow: var(--shadow)
}

.m.s .mb {
    background: var(--accent-bg);
    border: 1px solid var(--accent-border);
    color: var(--accent);
    font-size: 12px;
    border-radius: 20px;
    padding: 5px 14px
}

.m-time {
    font-size: 10px;
    color: var(--text3);
    margin-top: 2px;
    padding: 0 4px
}

.mb pre {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    overflow-x: auto;
    margin: 5px 0;
    font-size: 12px
}

.mb code {
    background: var(--surface2);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px
}

.mb p {
    margin: 0 0 5px
}

.mb p:last-child {
    margin: 0
}

.mb ul,
.mb ol {
    padding-left: 16px;
    margin: 3px 0
}

.mb strong {
    font-weight: 600
}

.tc {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 11px;
    font-size: 12px;
    margin: 3px 0;
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--text2)
}

.typing {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--text2);
    font-size: 13px;
    padding: 6px 0
}

.td span {
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text3);
    animation: bo .9s infinite;
    margin: 0 1px
}

.td span:nth-child(2) {
    animation-delay: .15s
}

.td span:nth-child(3) {
    animation-delay: .3s
}

@keyframes bo {

    0%,
    80%,
    100% {
        transform: translateY(0)
    }

    40% {
        transform: translateY(-5px)
    }
}

.m-img {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 5px;
    border: 1px solid var(--border);
    cursor: zoom-in;
    transition: transform .2s
}

.m-img:hover {
    transform: scale(1.02)
}

.tc.swarm {
    background: var(--accent-bg);
    border-color: var(--accent-border);
    color: var(--accent);
    font-weight: 600;
    display: inline-flex;
    animation: swarm-pulse 2s infinite
}

@keyframes swarm-pulse {
    0% {
        opacity: 1
    }

    50% {
        opacity: .7
    }

    100% {
        opacity: 1
    }
}

.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text3)
}

.welcome .big {
    font-size: 48px;
    opacity: .3
}

.welcome p {
    font-size: 14px;
    text-align: center;
    max-width: 280px;
    line-height: 1.5
}

.wg {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 10px;
    width: 100%;
    max-width: 500px
}

.wc {
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: .15s
}

.wc:hover {
    border-color: var(--accent-border);
    background: var(--accent-bg)
}

.wc-i {
    font-size: 20px;
    margin-bottom: 4px
}

.wc-t {
    font-weight: 600;
    font-size: 12px
}

.wc-d {
    font-size: 11px;
    color: var(--text2);
    margin-top: 2px;
    line-height: 1.3
}

#comp {
    padding: 10px 20px 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0
}

#comp-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 8px 8px 14px;
    transition: border .15s
}

#comp-box:focus-within {
    border-color: var(--accent)
}

#mi {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    resize: none;
    max-height: 100px;
    min-height: 22px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    padding: 2px 0
}

#mi::placeholder {
    color: var(--text3)
}

.cb {
    background: none;
    padding: 5px;
    border-radius: 5px;
    color: var(--text2);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: .15s
}

.cb:hover {
    background: var(--surface2)
}

#send {
    background: var(--accent);
    color: #fff;
    padding: 6px 12px;
    border-radius: 7px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    transition: .15s
}

#send:hover {
    background: var(--accent-hover)
}

#send:disabled {
    opacity: .4;
    cursor: not-allowed
}

.ns-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 13px;
    transition: .15s
}

.ns-btn:hover {
    background: var(--surface2)
}

/* Toggle */
.tog {
    position: relative;
    width: 36px;
    height: 20px;
    flex-shrink: 0
}

.tog input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute
}

.tog-s {
    position: absolute;
    inset: 0;
    border-radius: 20px;
    background: var(--border);
    cursor: pointer;
    transition: .2s
}

.tog input:checked+.tog-s {
    background: var(--accent)
}

.tog-s::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: #fff;
    transition: .2s
}

.tog input:checked+.tog-s::before {
    transform: translateX(16px)
}

/* Skills */
.sk {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    margin-bottom: 7px;
    display: flex;
    align-items: center;
    gap: 10px
}

.sk-icon {
    font-size: 18px;
    flex-shrink: 0
}

.sk-info {
    flex: 1;
    min-width: 0
}

.sk-name {
    font-weight: 600;
    font-size: 13px
}

.sk-desc {
    font-size: 12px;
    color: var(--text2);
    margin-top: 2px;
    line-height: 1.4
}

/* Config */
.cfg-ta {
    width: 100%;
    height: 280px;
    resize: vertical;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    border-radius: 8px;
    padding: 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text)
}

/* Agents UI */
.btn-sm {
    padding: 4px 10px;
    font-size: 12px
}

.two-col-agents {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px
}

@media(max-width:768px) {
    .two-col-agents {
        grid-template-columns: 1fr
    }
}

.ag-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    margin-top: 12px;
    background: var(--surface2)
}

.ag-list-item:hover {
    background: var(--surface)
}

.ag-list-item.active {
    border-color: var(--accent);
    border-width: 2px;
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--surface), 0 1px 4px rgba(0, 0, 0, .05)
}

.ag-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text);
    font-size: 16px;
    flex-shrink: 0
}

.ag-info {
    flex: 1;
    min-width: 0
}

.ag-avatar-lg {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--surface2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text);
    font-size: 22px;
    flex-shrink: 0;
    border: 1px solid var(--border)
}

.ag-tabs {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    overflow-x: auto
}

.ag-tab {
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 16px;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    transition: .15s;
    white-space: nowrap;
    cursor: pointer
}

.ag-tab:hover {
    background: var(--surface2)
}

.ag-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent)
}

.ag-tab-content {
    display: none
}

.ag-tab-content.active {
    display: block
}