:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --surface-muted: #f0f1ef;
    --text: #171918;
    --muted: #686d69;
    --border: #dcdedb;
    --accent: #245d4b;
    --accent-hover: #194637;
    --danger: #a03636;
    --danger-bg: #fff3f2;
    --success: #276749;
    --success-bg: #f0faf4;
    --radius: 10px;
    --shadow: 0 16px 45px rgba(22, 28, 25, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.55; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
button, input, textarea, select { font: inherit; }
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 16px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent); color: #fff; font-weight: 650; line-height: 1.2; text-decoration: none; cursor: pointer; transition: background .15s ease, border-color .15s ease; }
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
button:disabled, .button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary, .button.secondary { background: transparent; color: var(--text); border-color: var(--border); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-muted); color: var(--text); }
button.danger, .button.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
button.small, .button.small { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.brand { font-size: 19px; font-weight: 760; letter-spacing: -.03em; text-decoration: none; }
.brand span { color: var(--muted); font-size: 12px; letter-spacing: .05em; text-transform: uppercase; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 12px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid rgba(36, 93, 75, .28); outline-offset: 2px; }

.site-header, .site-footer { width: min(1180px, calc(100% - 48px)); margin: 0 auto; }
.site-header { height: 84px; display: flex; align-items: center; justify-content: space-between; }
.site-header nav, .app-bar nav { display: flex; align-items: center; gap: 20px; }
.landing { min-height: 100vh; display: flex; flex-direction: column; }
.landing-main { flex: 1; width: min(1180px, calc(100% - 48px)); margin: 0 auto; display: grid; grid-template-columns: 1.55fr .8fr; gap: 72px; align-items: center; padding: 48px 0 72px; }
.hero h1 { margin: 0; max-width: 750px; font-size: clamp(56px, 7vw, 94px); line-height: .95; letter-spacing: -.065em; }
.hero-copy { max-width: 540px; margin: 28px 0; color: var(--muted); font-size: 20px; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.offer { border-left: 1px solid var(--border); padding: 18px 0 18px 48px; }
.offer-kicker { margin: 0 0 2px; color: var(--muted); }
.price { margin: 0 0 22px; display: flex; align-items: baseline; gap: 5px; }
.price strong { font-size: 42px; letter-spacing: -.05em; }
.price span { color: var(--muted); }
.plain-list { padding: 0; margin: 0 0 20px; list-style: none; }
.plain-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.plain-list.compact { width: min(300px, 100%); margin-inline: auto; text-align: left; }
.site-footer { min-height: 66px; padding: 15px 0; border-top: 1px solid var(--border); display: flex; align-items: flex-start; gap: 24px; color: var(--muted); font-size: 13px; }
.site-footer details { max-width: 360px; }
.site-footer summary { cursor: pointer; }
.site-footer p { color: var(--text); }

.auth-page { min-height: 100vh; }
.auth-shell { width: min(440px, calc(100% - 32px)); margin: 0 auto; padding: 42px 0 64px; }
.auth-shell > .brand { display: block; margin-bottom: 42px; text-align: center; }
.auth-card { padding: 32px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 8px; font-size: 30px; letter-spacing: -.035em; }
.auth-card form, .panel form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 650; }
input, textarea, select { width: 100%; min-height: 42px; border: 1px solid #cbd0cc; border-radius: 7px; background: #fff; color: var(--text); padding: 9px 11px; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: 3px solid rgba(36, 93, 75, .12); }
label small { color: var(--muted); font-weight: 400; }
label.checkbox { display: flex; flex-direction: row; align-items: flex-start; gap: 9px; font-weight: 450; }
label.checkbox input { width: 17px; min-height: 17px; margin-top: 2px; }
.form-footer { margin: 24px 0 0; text-align: center; color: var(--muted); }
.alert { margin: 18px 0; padding: 11px 14px; border: 1px solid; border-radius: 8px; }
.alert p { margin: 2px 0; }
.alert.error { background: var(--danger-bg); border-color: #e8b8b4; color: #782828; }
.alert.success { background: var(--success-bg); border-color: #b9deca; color: var(--success); }
.narrow { width: min(620px, calc(100% - 32px)); margin: 15vh auto; }

.app-bar { height: 64px; padding: 0 max(24px, calc((100vw - 1240px) / 2)); border-bottom: 1px solid var(--border); background: var(--surface); display: flex; align-items: center; justify-content: space-between; }
.app-bar nav form, .sidebar-footer form { display: contents; }
.link-button { display: inline; min-height: 0; padding: 0; border: 0; border-radius: 0; background: transparent; color: inherit; font-weight: 450; }
.link-button:hover { background: transparent; color: var(--accent); }
.account-shell, .admin-shell { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 46px 0 80px; }
.page-heading, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.page-heading { margin-bottom: 28px; }
.page-heading h1, .section-heading h2 { margin: 0; letter-spacing: -.035em; }
.page-heading h1 { font-size: 38px; }
.panel { padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.panel h2 { margin: 0 0 18px; font-size: 20px; letter-spacing: -.02em; }
.panel h3 { margin: 0 0 14px; font-size: 16px; }
.account-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.account-grid .wide { grid-column: 1 / -1; }
.big-value { margin: 0; font-size: 27px; font-weight: 730; }
.stats-list { margin: 0; }
.stats-list div { display: flex; justify-content: space-between; gap: 20px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.stats-list dt { color: var(--muted); }
.stats-list dd { margin: 0; font-weight: 650; text-align: right; }
.key-reveal { margin: 18px 0; padding: 16px; border: 1px solid #d1b45b; border-radius: 8px; background: #fffbea; }
.key-reveal code { display: block; margin-top: 8px; overflow-wrap: anywhere; font-size: 14px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
td a { text-decoration: none; }
.status-badge { display: inline-flex; align-items: center; width: fit-content; padding: 3px 8px; border-radius: 999px; background: var(--surface-muted); color: var(--muted); font-size: 11px; font-weight: 750; text-transform: capitalize; }
.status-badge.active { background: #e9f6ee; color: #25603d; }
.status-badge.suspended { background: #fff5d9; color: #795a00; }
.status-badge.deleted { background: #f6eaea; color: #7b3232; }
.status-badge.ok { background: #e9f6ee; color: #25603d; }
.status-badge.busy { background: #fff5d9; color: #795a00; }
.status-badge.offline { background: #f6eaea; color: #7b3232; }

.chat-app { height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); overflow: hidden; background: var(--surface); }
.chat-sidebar { min-width: 0; padding: 20px 14px 14px; border-right: 1px solid var(--border); background: var(--bg); display: flex; flex-direction: column; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 0 7px 20px; }
.full { width: 100%; }
.sidebar-label { margin: 22px 8px 8px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.conversation-list { flex: 1; min-height: 0; overflow-y: auto; }
.conversation-item { width: 100%; min-height: 0; display: block; padding: 9px 10px; border: 0; background: transparent; color: var(--text); font-size: 13px; font-weight: 500; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-item:hover, .conversation-item.active { background: #e7e9e6; color: var(--text); }
.conversation-item.active { font-weight: 680; }
.sidebar-empty { padding: 10px; color: var(--muted); font-size: 12px; }
.sidebar-footer { padding: 12px 8px 4px; border-top: 1px solid var(--border); display: grid; gap: 9px; font-size: 13px; }
.chat-main { min-width: 0; display: grid; grid-template-rows: 64px minmax(0, 1fr) auto auto; }
.chat-header { min-width: 0; padding: 0 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 16px; }
.chat-product { font-size: 14px; letter-spacing: -.01em; }
.chat-actions { margin-left: auto; display: flex; gap: 12px; }
.text-action { min-height: 0; padding: 4px; border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.text-action:hover { background: transparent; color: var(--text); }
.danger-text:hover { color: var(--danger); }
.messages { min-height: 0; overflow-y: auto; padding: 32px max(24px, calc((100% - 780px) / 2)); }
.empty-state { margin: 18vh auto 0; text-align: center; }
.empty-state h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -.035em; }
.empty-state p:last-child { color: var(--muted); }
.message { margin: 0 auto 28px; }
.message-role { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.message.user .message-content { width: fit-content; max-width: 86%; margin-left: auto; padding: 11px 14px; border-radius: 12px 12px 3px 12px; background: var(--surface-muted); }
.message.user .message-role { text-align: right; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; }
.message-content pre { margin: 12px 0; padding: 14px; overflow-x: auto; border: 1px solid #303532; border-radius: 7px; background: #202421; color: #f3f5f3; white-space: pre; font-size: 13px; line-height: 1.5; }
.message.thinking .message-content { color: var(--muted); }
.message-error .message-content { color: var(--danger); }
.composer { width: min(820px, calc(100% - 40px)); margin: 0 auto; padding: 7px; border: 1px solid #bfc4c0; border-radius: 13px; background: #fff; box-shadow: 0 6px 24px rgba(25, 31, 28, .08); display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { min-height: 44px; max-height: 180px; padding: 10px; border: 0; outline: 0; resize: none; }
.composer textarea:focus { border: 0; outline: 0; }
.composer button { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 9px; font-size: 21px; }
.composer-note { height: 29px; margin: 0; padding-top: 4px; color: var(--muted); font-size: 11px; text-align: center; }
.lock-screen { margin: auto; padding: 34px; text-align: center; }
.lock-screen h1 { margin: 0 0 8px; font-size: 32px; letter-spacing: -.04em; }
.history-hidden { display: none; }
.icon-button { width: 36px; height: 36px; min-height: 36px; padding: 0; background: transparent; border-color: var(--border); color: var(--text); font-size: 19px; }
.icon-button:hover { background: var(--surface-muted); color: var(--text); border-color: var(--border); }
.mobile-only { display: none; }

.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; overflow: hidden; margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--border); }
.stat-grid div { padding: 17px; background: var(--surface); }
.stat-grid span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.stat-grid strong { display: block; margin-top: 5px; font-size: 24px; }
.stats-note { margin: -7px 0 14px; color: var(--muted); font-size: 12px; text-align: right; }
.admin-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .7fr); gap: 16px; margin-bottom: 16px; }
.search-form { display: flex !important; grid-template-columns: 1fr auto; flex-direction: row; gap: 8px !important; }
.search-form input { width: 220px; }
.pagination { display: flex; justify-content: center; gap: 20px; margin-top: 18px; color: var(--muted); }
.user-detail { margin-bottom: 16px; }
.detail-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 22px; }
.subpanel { min-width: 0; padding: 18px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.button-stack { display: grid; gap: 8px; }
.button-stack.inline { margin-top: 12px; }
.button-stack form { display: flex; }
.button-stack button { width: 100%; }
.split-tables { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; margin-top: 26px; }
.admin-shell > .panel { margin-bottom: 16px; }
.ai-status .section-heading { align-items: center; }
.ai-health-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin: 0; }
.ai-health-grid div { min-width: 0; }
.ai-health-grid dt { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.ai-health-grid dd { margin: 3px 0 0; font-size: 18px; font-weight: 700; }

@media (max-width: 980px) {
    .landing-main { grid-template-columns: 1fr .7fr; gap: 32px; }
    .hero h1 { font-size: clamp(54px, 10vw, 78px); }
    .stat-grid { grid-template-columns: repeat(3, 1fr); }
    .admin-layout { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ai-health-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
    .site-header, .site-footer, .landing-main, .account-shell, .admin-shell { width: min(100% - 28px, 100%); }
    .site-header { height: 68px; }
    .site-header nav { gap: 12px; }
    .landing-main { display: block; padding: 54px 0; }
    .hero h1 { font-size: 54px; }
    .hero-copy { font-size: 18px; }
    .offer { margin-top: 58px; padding: 24px 0 0; border-left: 0; border-top: 1px solid var(--border); }
    .site-footer { flex-wrap: wrap; }
    .app-bar { padding: 0 14px; }
    .app-bar nav { gap: 12px; font-size: 13px; }
    .account-shell, .admin-shell { padding-top: 30px; }
    .account-grid, .split-tables { grid-template-columns: 1fr; }
    .account-grid .wide { grid-column: auto; }
    .panel { padding: 18px; }
    .chat-app { grid-template-columns: 1fr; }
    .chat-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(300px, 88vw); transform: translateX(-102%); transition: transform .18s ease; box-shadow: var(--shadow); }
    .chat-sidebar.open { transform: translateX(0); }
    .mobile-only { display: inline-flex; }
    .chat-header { padding: 0 12px; gap: 9px; }
    .chat-actions { gap: 3px; }
    .messages { padding: 24px 16px; }
    .composer { width: calc(100% - 20px); }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .section-heading { display: block; }
    .search-form { margin-top: 14px; }
    .search-form input { width: 100%; }
    .detail-grid { grid-template-columns: 1fr; }
    .ai-health-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
