:root {
    --navy: #10243e;
    --navy-light: #183654;
    --orange: #f28a16;
    --orange-dark: #d87000;
    --bg: #f3f6f9;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #657184;
    --border: #dce3ea;
    --success: #16794c;
    --danger: #b42318;
    --warning: #a15c00;
    --radius: 14px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select { font: inherit; }
a { color: inherit; }
h1, h2 { color: var(--navy); margin-top: 0; }
h1 { font-size: 1.8rem; margin-bottom: .35rem; }
h2 { font-size: 1.15rem; }
p { color: var(--muted); }

.app-shell { display: grid; grid-template-columns: 255px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 16px; background: var(--navy); color: white; display: flex; flex-direction: column; }
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; padding: 0 8px 24px; }
.brand span:last-child { display: flex; flex-direction: column; }
.brand small { opacity: .7; margin-top: 2px; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; background: var(--orange); color: white; display: inline-grid; place-items: center; font-weight: 800; }
.brand-logo { width: 52px; height: 44px; border-radius: 10px; background: white; display: grid; place-items: center; padding: 5px; flex: 0 0 auto; }
.brand-logo img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.sidebar nav { display: grid; gap: 4px; overflow-y: auto; }
.sidebar nav a { text-decoration: none; color: #d5dfeb; padding: 11px 13px; border-radius: 9px; }
.sidebar nav a:hover, .sidebar nav a.active { color: white; background: var(--navy-light); }
.sidebar nav a.active { box-shadow: inset 3px 0 var(--orange); }
.sidebar-user { margin-top: auto; padding: 16px 10px 4px; border-top: 1px solid rgba(255,255,255,.13); display: flex; flex-direction: column; gap: 4px; }
.sidebar-user span { font-size: .82rem; color: #afbdca; }
.sidebar-user form { margin-top: 9px; }
.link-button { border: 0; padding: 0; background: none; color: #ffd4a4; cursor: pointer; }

.content { min-width: 0; padding: 34px clamp(20px, 4vw, 56px); }
.page-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 24px; }
.page-heading p { margin: 0; }
.card, .stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16,36,62,.05); }
.card { padding: 24px; margin-bottom: 24px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { padding: 20px; display: flex; flex-direction: column; gap: 7px; }
.stat-card span { color: var(--muted); font-size: .9rem; }
.stat-card strong { color: var(--navy); font-size: 2rem; }
.status-badge { display: inline-block; width: fit-content; padding: 5px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.status-active { background: #e7f6ee; color: var(--success); }
.status-disabled { background: #fbe9e7; color: var(--danger); }
.status-paused { background: #fff0db; color: var(--warning); }
.check-list { display: grid; gap: 16px; }
.check-list > div { display: flex; align-items: center; gap: 12px; }
.check-list span:last-child { display: flex; flex-direction: column; }
.check-list small, table small { display: block; color: var(--muted); margin-top: 3px; }
.check { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; }
.check.ok { background: #e7f6ee; color: var(--success); }
.check.pending { background: #fff0db; color: var(--warning); }

.stack-form { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
label { color: var(--navy); font-size: .9rem; font-weight: 650; display: grid; gap: 7px; }
input, select { width: 100%; border: 1px solid #cbd5df; border-radius: 9px; padding: 11px 12px; background: white; color: var(--text); outline: none; }
input[type="checkbox"], input[type="color"] { width: auto; }
input[type="color"] { min-width: 70px; min-height: 44px; padding: 4px; }
input:focus, select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(242,138,22,.15); }
.form-actions { grid-column: 1 / -1; }
.button { border: 1px solid #bcc8d4; background: white; color: var(--navy); padding: 10px 15px; border-radius: 9px; cursor: pointer; font-weight: 700; }
.button:hover { border-color: var(--orange); }
.button-primary { border-color: var(--orange); background: var(--orange); color: white; }
.button-primary:hover { background: var(--orange-dark); }
.button-small { padding: 7px 10px; font-size: .82rem; }

.table-card { padding: 0; overflow: hidden; }
.table-card > h2 { padding: 22px 24px 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; text-align: left; border-top: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; background: #f8fafc; }
td { font-size: .9rem; }
.actions form { display: inline; }
.muted { color: var(--muted); }

.alert { padding: 13px 16px; border-radius: 10px; margin-bottom: 18px; border: 1px solid transparent; }
.alert-success { color: var(--success); background: #e7f6ee; border-color: #bfe7d1; }
.alert-error { color: var(--danger); background: #fbe9e7; border-color: #f2c6c1; }
.alert-warning { color: var(--warning); background: #fff0db; border-color: #f2d09b; }
.alert-info { color: #175cd3; background: #eaf2ff; border-color: #bfd4ff; }

.login-shell { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top right, #244a70, var(--navy) 55%); }
.login-content { width: min(100%, 430px); }
.login-card { background: white; border-radius: 18px; padding: 34px; box-shadow: 0 28px 80px rgba(0,0,0,.25); }
.login-card h1, .login-card > p { text-align: center; }
.login-card > p { margin-top: 0; margin-bottom: 28px; }
.login-brand { display: grid; place-items: center; margin-bottom: 14px; }
.login-brand .brand-mark { width: 56px; height: 56px; font-size: 1.1rem; }
.narrow-card { max-width: 640px; }
.empty-state { padding: 70px 24px; text-align: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar form { display: flex; gap: 8px; align-items: center; }
.button-danger { color: var(--danger); border-color: #e8b7b2; }
.button-secondary { background: var(--navy); border-color: var(--navy); color: white; }
.button-ghost { background: transparent; }
.field-full { grid-column: 1 / -1; }
textarea { width: 100%; min-height: 130px; resize: vertical; border: 1px solid #cbd5df; border-radius: 9px; padding: 11px 12px; font: inherit; color: var(--text); background: white; }
textarea:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px rgba(242,138,22,.15); }
.textarea-large { min-height: 360px; }
.conversation-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; }
.message-list { display: flex; flex-direction: column; gap: 12px; max-height: 62vh; overflow-y: auto; padding: 6px; }
.message { width: min(82%, 720px); border-radius: 14px; padding: 11px 14px; }
.message-inbound { align-self: flex-start; background: #f0f3f6; }
.message-outbound { align-self: flex-end; background: #e7f6ee; }
.message-system { align-self: center; background: #fff0db; }
.message-meta { display: flex; justify-content: space-between; gap: 20px; color: var(--muted); font-size: .74rem; margin-top: 6px; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.tabs a { text-decoration: none; padding: 9px 13px; border-radius: 9px; background: white; border: 1px solid var(--border); }
.tabs a.active { color: white; background: var(--navy); border-color: var(--navy); }
.logo-preview { display: block; max-width: 360px; max-height: 140px; object-fit: contain; padding: 12px; border: 1px dashed var(--border); border-radius: 10px; background: white; margin: 12px 0; }
.code-value { padding: 10px 12px; background: #eef2f6; border-radius: 8px; overflow-wrap: anywhere; font-family: ui-monospace, monospace; }
.article-content { white-space: pre-wrap; line-height: 1.65; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 999px; background: #edf2f7; color: var(--muted); font-size: .78rem; }
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.pagination a { text-decoration: none; padding: 7px 11px; border: 1px solid var(--border); border-radius: 8px; background: white; }
.link-rows { display: grid; gap: 12px; margin-bottom: 14px; }
.link-row { display: grid; grid-template-columns: minmax(180px, .8fr) minmax(260px, 1.5fr) auto; gap: 12px; align-items: end; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: #f8fafc; }
.link-remove { margin-bottom: 1px; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .sidebar nav { grid-template-columns: repeat(3, 1fr); }
    .sidebar-user { margin-top: 18px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
    .content { padding: 22px 14px; }
    .sidebar nav { grid-template-columns: repeat(2, 1fr); }
    .stat-grid, .form-grid { grid-template-columns: 1fr; }
    .conversation-layout { grid-template-columns: 1fr; }
    .link-row { grid-template-columns: 1fr; }
    .page-heading { flex-direction: column; }
    .card { padding: 18px; }
}
