:root {
    --bg: #eef3f5;
    --surface: rgba(255, 255, 255, .78);
    --surface-strong: rgba(255, 255, 255, .94);
    --text: #14201d;
    --muted: #63716c;
    --line: rgba(20, 32, 29, .1);
    --brand: #18a05f;
    --brand-2: #0a7d61;
    --danger: #d94b60;
    --warning: #c98c21;
    --info: #2778b8;
    --shadow: 0 24px 70px rgba(19, 42, 34, .13);
}

[data-theme="dark"] {
    --bg: #101615;
    --surface: rgba(24, 34, 32, .74);
    --surface-strong: rgba(29, 42, 39, .94);
    --text: #eff8f3;
    --muted: #a0b0aa;
    --line: rgba(239, 248, 243, .12);
    --shadow: 0 24px 70px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(24, 160, 95, .14), transparent 32rem),
        linear-gradient(135deg, var(--bg), #f8faf9 48%, var(--bg));
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
[data-theme="dark"] body, body[data-theme="dark"] {
    background:
        radial-gradient(circle at top left, rgba(24, 160, 95, .18), transparent 32rem),
        linear-gradient(135deg, #101615, #17211e 52%, #0f1716);
}
a { color: var(--brand-2); text-decoration: none; }
.glass-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}
.app-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 22px; min-height: 100vh; padding: 18px; }
.sidebar { position: sticky; top: 18px; height: calc(100vh - 36px); border-radius: 22px; padding: 18px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); margin-bottom: 28px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand-mark { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 14px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: white; font-weight: 800; }
.nav-list { display: grid; gap: 7px; }
.nav-list a { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 12px 14px; border-radius: 14px; transition: .2s ease; }
.nav-list a:hover, .nav-list a.active { background: rgba(24, 160, 95, .12); color: var(--text); transform: translateX(3px); }
.nav-list svg, .icon-btn svg, .btn svg { width: 18px; height: 18px; }
.sidebar-footer { margin-top: auto; display: flex; gap: 10px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface-strong); color: var(--text); width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; }
.main-content { min-width: 0; display: grid; gap: 18px; align-content: start; }
.topbar { border-radius: 22px; padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.topbar h1 { font-size: 26px; margin: 0; letter-spacing: 0; }
.eyebrow { color: var(--brand-2); font-size: 12px; text-transform: uppercase; font-weight: 800; }
.user-chip { display: inline-flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-strong); border: 1px solid var(--line); border-radius: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(6, minmax(150px, 1fr)); gap: 16px; }
.stat-grid.compact { grid-template-columns: repeat(3, minmax(180px, 1fr)); }
.stat-card { position: relative; overflow: hidden; min-height: 128px; padding: 18px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); animation: liftIn .35s ease both; }
.stat-card svg { color: var(--brand); margin-bottom: 18px; }
.stat-card span { display: block; color: var(--muted); font-size: 13px; }
.stat-card strong { font-size: clamp(24px, 3vw, 34px); letter-spacing: 0; }
.stat-card.danger svg { color: var(--danger); }
.stat-card.warning svg { color: var(--warning); }
.content-grid, .sender-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(360px, .65fr); gap: 18px; }
.panel { border-radius: 22px; padding: 20px; min-width: 0; }
.narrow-panel { max-width: 980px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-head h2 { font-size: 18px; margin: 0; letter-spacing: 0; }
.panel-head span, .muted { color: var(--muted); }
.premium-table { color: var(--text); margin: 0; vertical-align: middle; }
.premium-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; border-color: var(--line); }
.premium-table td { border-color: var(--line); padding: 14px 10px; }
.badge-soft { display: inline-flex; padding: 6px 10px; border-radius: 999px; background: rgba(24, 160, 95, .12); color: var(--brand-2); font-size: 12px; font-weight: 700; text-transform: capitalize; }
.premium-form, .stack-form { display: grid; gap: 16px; }
.premium-form label, .stack-form label { display: grid; gap: 8px; color: var(--muted); font-weight: 700; font-size: 13px; }
.form-control, .form-select {
    background-color: var(--surface-strong);
    color: var(--text);
    border-color: var(--line);
    border-radius: 14px;
    min-height: 46px;
}
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(24, 160, 95, .15); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.action-row, .button-row, .drop-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn { border-radius: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; font-weight: 750; }
.btn-success { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border: 0; }
.search-form { min-width: 260px; }
.template-preview, .template-body, .report-box, .cron-box {
    background: var(--surface-strong);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    white-space: pre-wrap;
}
.monofield, .template-preview { font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.premium-progress { height: 28px; background: var(--surface-strong); border-radius: 999px; }
.mini-stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.mini-stat-row div { background: var(--surface-strong); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.mini-stat-row span { display: block; color: var(--muted); font-size: 12px; }
.mini-stat-row strong { font-size: 26px; }
.real-logs, .log-list { display: grid; gap: 8px; max-height: 330px; overflow: auto; }
.real-logs div, .log-list div { padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-strong); font-size: 13px; }
.log-list time { color: var(--muted); margin-right: 8px; }
.log-list span { color: var(--brand-2); font-weight: 800; margin-right: 8px; }
.response-cell { max-width: 520px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.download-list { display: grid; gap: 12px; }
.download-list a { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 16px; padding: 14px; background: var(--surface-strong); color: var(--text); }
.check-list { display: grid; gap: 10px; }
.check-list div { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-strong); color: var(--text); }
.check-list svg { width: 18px; height: 18px; color: var(--brand); flex: 0 0 auto; }
.webhook-grid { display: grid; gap: 12px; }
.webhook-grid div { display: grid; gap: 7px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-strong); }
.webhook-grid span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.webhook-grid code { white-space: normal; overflow-wrap: anywhere; color: var(--text); }
.chat-shell { display: grid; grid-template-columns: 360px minmax(0, 1fr); min-height: calc(100vh - 136px); border-radius: 22px; overflow: hidden; }
.chat-list { border-right: 1px solid var(--line); padding: 18px; display: grid; grid-template-rows: auto auto auto minmax(0, 1fr); gap: 14px; min-height: 0; }
.chat-list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chat-list-head h2, .chat-header h2 { font-size: 18px; margin: 0; letter-spacing: 0; }
.chat-list-head span, .chat-header span { color: var(--muted); font-size: 13px; }
.new-chat-form { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgba(24, 160, 95, .06); }
.contact-list { display: grid; gap: 10px; align-content: start; overflow: auto; padding-right: 3px; }
.contact-item {
    position: relative;
    display: grid;
    gap: 4px;
    width: 100%;
    text-align: left;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 13px 42px 13px 13px;
    background: var(--surface-strong);
    color: var(--text);
    transition: .18s ease;
}
.contact-item:hover, .contact-item.active { border-color: rgba(24, 160, 95, .45); transform: translateY(-1px); }
.contact-item span, .contact-item small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-item em { position: absolute; right: 12px; top: 12px; min-width: 24px; height: 24px; display: grid; place-items: center; border-radius: 999px; background: var(--brand); color: white; font-size: 12px; font-style: normal; }
.chat-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.chat-header { padding: 18px 20px; border-bottom: 1px solid var(--line); background: rgba(24, 160, 95, .06); }
.contact-details { display: grid; grid-template-columns: minmax(160px, .8fr) minmax(170px, .8fr) minmax(220px, 1fr) 48px; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.contact-details .form-control { min-height: 40px; }
.chat-messages { padding: 20px; overflow: auto; display: flex; flex-direction: column; gap: 12px; min-height: 360px; }
.chat-empty { margin: auto; display: grid; place-items: center; gap: 10px; color: var(--muted); text-align: center; max-width: 320px; }
.chat-empty svg { width: 46px; height: 46px; color: var(--brand); }
.message-row { display: flex; }
.message-row.outbound { justify-content: flex-end; }
.message-bubble { max-width: min(620px, 78%); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; background: var(--surface-strong); box-shadow: 0 12px 28px rgba(20, 32, 29, .08); }
.message-row.outbound .message-bubble { background: linear-gradient(135deg, rgba(24, 160, 95, .95), rgba(10, 125, 97, .95)); color: white; border-color: transparent; }
.message-bubble p { margin: 0 0 7px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-bubble time { display: block; font-size: 11px; color: var(--muted); }
.message-row.outbound .message-bubble time { color: rgba(255,255,255,.78); }
.chat-composer { display: grid; grid-template-columns: minmax(0, 1fr) 52px; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line); background: rgba(24, 160, 95, .04); }
.chat-composer textarea { resize: none; }
.empty-chat { padding: 12px; }
.auth-bg { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.auth-shell { width: min(460px, 100%); }
.auth-card { border-radius: 24px; padding: 32px; }
.auth-card h1 { margin: 18px 0 8px; font-size: 30px; letter-spacing: 0; }
.auth-card p { color: var(--muted); }
.toast-wrap { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 1100; }
.app-toast { background: var(--surface-strong); border: 1px solid var(--line); color: var(--text); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 14px; min-width: 260px; animation: liftIn .2s ease both; }

@keyframes liftIn {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 1180px) {
    .stat-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .content-grid, .sender-grid { grid-template-columns: 1fr; }
}
@media (max-width: 991px) {
    .app-shell { grid-template-columns: 1fr; padding: 12px; }
    .sidebar { position: fixed; inset: 12px auto 12px 12px; width: 280px; z-index: 1000; transform: translateX(-115%); transition: .25s ease; }
    .sidebar.open { transform: translateX(0); }
    .chat-shell { grid-template-columns: 1fr; }
    .chat-list { border-right: 0; border-bottom: 1px solid var(--line); max-height: 360px; }
}
@media (max-width: 680px) {
    .topbar { align-items: flex-start; }
    .topbar h1 { font-size: 22px; }
    .user-chip { display: none; }
    .stat-grid, .stat-grid.compact, .form-grid, .mini-stat-row { grid-template-columns: 1fr; }
    .panel-head { align-items: flex-start; flex-direction: column; }
    .search-form { min-width: 100%; }
    .action-row, .button-row, .drop-row { align-items: stretch; }
    .action-row > *, .button-row > *, .drop-row > * { width: 100%; }
    .chat-shell { min-height: calc(100vh - 112px); }
    .chat-list { max-height: 310px; }
    .contact-details { grid-template-columns: 1fr; padding: 12px; }
    .chat-messages { min-height: 320px; padding: 14px; }
    .message-bubble { max-width: 92%; }
    .chat-composer { grid-template-columns: 1fr; padding: 12px; }
    .chat-composer .btn { width: 100%; }
}
