:root {
    color-scheme: light;
    --page: #f6f6f7;
    --surface: #ffffff;
    --surface-subdued: #f1f2f3;
    --border: #d2d5d8;
    --text: #202223;
    --muted: #616a75;
    --primary: #008060;
    --primary-hover: #006e52;
    --danger: #d72c0d;
    --warning-bg: #fff5ea;
    --warning: #8a4b08;
    --info-bg: #eef7ff;
    --info: #005bd3;
    --shadow: 0 1px 0 rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--page); color: var(--text); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { font-size: 14px; line-height: 1.45; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell { width: min(1240px, calc(100% - 36px)); margin: 0 auto; padding: 28px 0 64px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 22px; }
.topbar h1 { font-size: 28px; line-height: 1.15; margin: 3px 0 4px; letter-spacing: -.02em; }
.eyebrow { font-size: 11px; letter-spacing: .12em; font-weight: 750; color: var(--muted); }
.muted { color: var(--muted); margin: 0; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 11px 14px 12px; color: var(--muted); font-weight: 650; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
.button { border: 1px solid var(--border); border-radius: 8px; padding: 9px 14px; min-height: 38px; font-weight: 650; background: var(--surface); color: var(--text); box-shadow: 0 1px 0 rgba(0,0,0,.04); }
.button:hover { background: #f9fafb; }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { background: var(--surface); }
.button-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button-danger-text { color: var(--danger); border-color: transparent; background: transparent; box-shadow: none; padding-left: 0; }
.button-danger-text:hover { text-decoration: underline; background: transparent; }
.full-width { width: 100%; margin-top: 18px; }
.notice { border-radius: 10px; padding: 13px 16px; margin-bottom: 18px; border: 1px solid transparent; }
.notice-info { background: var(--info-bg); color: #003a78; border-color: #b4d4f7; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 18px; }
.metric-card, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.metric-card { padding: 18px; }
.metric-card span { display: block; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.metric-card strong { font-size: 30px; letter-spacing: -.03em; }
.two-column-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.card { padding: 20px; }
.card-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; padding-bottom: 16px; }
.card-header h2, .modal-header h2 { margin: 0 0 4px; font-size: 18px; }
.card-header p, .modal-header p { margin: 0; color: var(--muted); }
.card-header-actions { align-items: center; }
.status-row { display: flex; justify-content: space-between; gap: 20px; align-items: center; border-top: 1px solid #eceef0; padding: 13px 0; }
.status { display: inline-flex; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; }
.status-success { background: #e3f1df; color: #1e4620; }
.status-warning { background: var(--warning-bg); color: var(--warning); }
.status-neutral { background: #edf0f2; color: #4a535d; }
.status-danger { background: #fff0ed; color: #a21b00; }
.setup-list { padding: 0; margin: 0; list-style: none; }
.setup-list li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid #eceef0; }
.setup-list li > span { flex: 0 0 28px; height: 28px; border-radius: 50%; background: #eef7f4; color: var(--primary); display: grid; place-items: center; font-weight: 800; }
.setup-list strong, .setup-list small { display: block; }
.setup-list small { color: var(--muted); margin-top: 2px; }
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.data-table th { color: var(--muted); font-size: 12px; letter-spacing: .02em; text-align: left; padding: 10px 12px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: #fafbfb; }
.data-table td { padding: 13px 12px; border-bottom: 1px solid #eceef0; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .title-cell strong, .data-table .title-cell small { display: block; }
.data-table .title-cell small { color: var(--muted); max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.align-right { text-align: right !important; }
.row-actions { display: inline-flex; gap: 7px; justify-content: flex-end; }
.link-button { border: 0; background: transparent; color: var(--info); padding: 4px 5px; font-weight: 650; }
.link-button.danger { color: var(--danger); }
.empty-state { text-align: center; color: var(--muted); padding: 34px 20px; border-top: 1px solid var(--border); }
.settings-layout { display: grid; gap: 18px; max-width: 920px; }
.field { display: grid; gap: 7px; margin-bottom: 16px; font-weight: 620; }
.field small { color: var(--muted); font-weight: 400; }
input, textarea, select { width: 100%; border: 1px solid #aeb4b9; border-radius: 8px; background: #fff; color: var(--text); padding: 9px 11px; outline: none; }
input { min-height: 40px; }
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus { border-color: var(--info); box-shadow: 0 0 0 1px var(--info); }
input[readonly] { background: var(--surface-subdued); color: var(--muted); }
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.color-field { display: grid; grid-template-columns: 52px 1fr; gap: 9px; }
.color-field input[type=color] { padding: 4px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; border-top: 1px solid #eceef0; border-bottom: 1px solid #eceef0; padding: 14px 0; margin-bottom: 17px; }
.toggle-row.compact { border: 0; margin: 0; padding: 22px 0 0; align-items: flex-start; }
.toggle-row span strong, .toggle-row span small { display: block; }
.toggle-row span small { color: var(--muted); margin-top: 2px; }
.toggle-row input[type=checkbox] { appearance: none; width: 42px; min-width: 42px; height: 24px; min-height: 24px; padding: 0; border: 0; border-radius: 999px; background: #8c9196; position: relative; transition: .15s; }
.toggle-row input[type=checkbox]::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.toggle-row input[type=checkbox]:checked { background: var(--primary); }
.toggle-row input[type=checkbox]:checked::after { transform: translateX(18px); }
.field-group { border: 0; padding: 0; margin: 0; }
.field-group legend { font-weight: 700; margin-bottom: 8px; }
.check-row { display: inline-flex; align-items: center; gap: 8px; margin-right: 18px; margin-bottom: 8px; }
.check-row input { width: 18px; height: 18px; min-height: 18px; accent-color: var(--primary); }
.sticky-actions { position: sticky; bottom: 14px; display: flex; justify-content: flex-end; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--border); background: rgba(255,255,255,.96); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12); backdrop-filter: blur(8px); }
.modal { border: 0; padding: 0; border-radius: 14px; width: min(720px, calc(100vw - 30px)); max-height: calc(100vh - 30px); box-shadow: 0 24px 70px rgba(0,0,0,.28); }
.modal-wide { width: min(860px, calc(100vw - 30px)); }
.modal::backdrop { background: rgba(32,34,35,.52); }
.modal-card { padding: 22px; margin: 0; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.icon-button { border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px; border-radius: 8px; font-size: 28px; line-height: 1; }
.icon-button:hover { background: var(--surface-subdued); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.conversation-messages { display: grid; gap: 10px; min-height: 160px; max-height: 56vh; overflow-y: auto; padding: 14px; background: var(--surface-subdued); border-radius: 10px; }
.message { max-width: 80%; padding: 10px 12px; border-radius: 12px; background: #fff; border: 1px solid var(--border); }
.message.visitor { justify-self: end; background: #e8f5f0; border-color: #b7ddcf; }
.message.system { justify-self: center; max-width: 95%; background: var(--warning-bg); }
.message small { display: block; color: var(--muted); margin-top: 5px; }
.loading-overlay { position: fixed; inset: 0; background: rgba(246,246,247,.9); display: flex; align-items: center; justify-content: center; gap: 12px; z-index: 1000; font-weight: 650; }
.loading-overlay.is-hidden { display: none; }
.spinner { width: 24px; height: 24px; border: 3px solid #d8dcdf; border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 1100; background: #202223; color: #fff; border-radius: 9px; padding: 11px 15px; box-shadow: 0 8px 28px rgba(0,0,0,.25); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .18s; max-width: min(420px, calc(100vw - 44px)); }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: #8e1f0b; }
@media (max-width: 840px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .two-column-grid, .form-grid.two { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; }
    .topbar-actions { justify-content: flex-start; }
}
@media (max-width: 520px) {
    .app-shell { width: min(100% - 20px, 1240px); padding-top: 18px; }
    .metric-grid { grid-template-columns: 1fr; }
    .card { padding: 16px; }
    .topbar-actions { width: 100%; }
    .topbar-actions .button { flex: 1; }
}
