:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --sidebar: #111827;
    --sidebar-muted: #9ca3af;
    --text: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #047857;
    --danger: #b91c1c;
    --radius: 16px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; color: var(--text); background: var(--bg); }
body { min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4, p { margin-top: 0; }
pre { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 260px; background: var(--sidebar); color: #fff; display: flex; flex-direction: column; justify-content: space-between; padding: 24px 18px; transition: width .2s ease, transform .2s ease; }
.sidebar.collapsed { width: 82px; }
.sidebar.collapsed .brand strong, .sidebar.collapsed .brand small, .sidebar.collapsed .nav a, .sidebar.collapsed .sidebar-footer { font-size: 0; }
.sidebar.collapsed .nav a::first-letter { font-size: 14px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; color: #fff; }
.brand-icon { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, #3b82f6, #0ea5e9); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: white; flex-shrink: 0; }
.brand small { display: block; color: var(--sidebar-muted); }
.nav { display: grid; gap: 8px; }
.nav a { color: #fff; padding: 12px 14px; border-radius: 12px; transition: background .15s ease; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.12); text-decoration: none; }
.sidebar-footer { margin-top: 20px; }
.shell-main { flex: 1; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 22px 28px 8px; }
.topbar-left { display: flex; align-items: flex-start; gap: 14px; }
.sidebar-toggle { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); cursor: pointer; }
.user-pill { display: grid; padding: 10px 14px; border: 1px solid var(--line); background: #fff; border-radius: 14px; box-shadow: var(--shadow); }
.user-pill small { color: var(--muted); }
.content { padding: 12px 28px 28px; }
.muted { color: var(--muted); }
.small-note { color: var(--muted); font-size: 0.92rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 20px; }
.card-grid { display: grid; gap: 20px; margin-bottom: 20px; }
.card-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 16px; }
.stats-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 20px; }
.stat-card { background: #fff; padding: 20px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }
.stat-card span { display: block; color: var(--muted); margin-bottom: 10px; }
.stat-card strong { font-size: 1.9rem; }
.grid.two { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { display: grid; gap: 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack-form { display: grid; gap: 14px; }
label { display: grid; gap: 7px; font-weight: 600; font-size: 0.95rem; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; font: inherit; color: var(--text); }
textarea { min-height: 120px; resize: vertical; }
.checkbox { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.checkbox input { width: auto; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.button { display: inline-flex; align-items: center; justify-content: center; padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
.button:hover { background: #f8fafc; text-decoration: none; }
.button-primary { background: var(--primary); color: white; border-color: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-outline { background: transparent; }
.button-block { width: 100%; }
.button-small { padding: 8px 12px; font-size: 0.9rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; border-bottom: 1px solid var(--line); padding: 12px 10px; vertical-align: top; }
.table th { color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.badge { display: inline-flex; padding: 6px 10px; border-radius: 999px; background: #eff6ff; color: #1d4ed8; font-size: 0.82rem; text-transform: capitalize; }
.badge-danger { background: #fef2f2; color: var(--danger); }
.alert { padding: 14px 16px; border-radius: 12px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: #ecfdf5; color: var(--success); border-color: #a7f3d0; }
.alert-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.alert-info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-wrap { width: 100%; max-width: 480px; }
.auth-panel { background: #fff; border-radius: 24px; border: 1px solid var(--line); box-shadow: var(--shadow); padding: 28px; }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.auth-brand small { display: block; color: var(--muted); }
.auth-links { margin-top: 16px; text-align: center; }
.tight-list { margin: 0; padding-left: 20px; display: grid; gap: 10px; }
.code-block { padding: 14px; border-radius: 12px; background: #0f172a; color: #e2e8f0; overflow: auto; }
.thread-list { display: grid; gap: 10px; }
.thread-item { display: block; padding: 14px; border-radius: 14px; border: 1px solid var(--line); color: var(--text); background: #fff; }
.thread-item.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.thread-item-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.inbox-grid { grid-template-columns: 380px minmax(0, 1fr); }
.message-thread { display: grid; gap: 12px; max-height: 500px; overflow: auto; padding-right: 4px; }
.message-bubble { padding: 14px; border-radius: 16px; border: 1px solid var(--line); background: #fafafa; }
.message-bubble.outbound { background: #eff6ff; }
.message-bubble header { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.message-subject { font-weight: 700; margin-bottom: 8px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.empty-state { min-height: 220px; display: grid; place-items: center; text-align: center; }
.small-note a { word-break: break-all; }
@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .card-grid.two, .inbox-grid { grid-template-columns: 1fr; }
    .grid.two, .grid.three { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
    .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); width: 260px !important; }
    .sidebar.mobile-open { transform: translateX(0); }
    .topbar, .content { padding-left: 18px; padding-right: 18px; }
    .stats-grid { grid-template-columns: 1fr; }
}

.table small { display:block; margin-top:4px; }
.code-block { max-height: 320px; }


.sidebar-footer .button {
    color: #ffffff;
    border-color: rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.04);
}
.sidebar-footer .button:hover {
    background: rgba(255,255,255,0.10);
}
.logout-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.logout-link .button-icon {
    font-size: 1rem;
    line-height: 1;
}
.sidebar.collapsed .logout-link .button-text {
    display: none;
}
.sidebar.collapsed .logout-link {
    padding-left: 0;
    padding-right: 0;
}
.table-tools {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}
.table-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}
.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.inline-form select {
    width: auto;
    min-width: 92px;
}
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 18px;
}
.pagination .button[aria-current="page"] {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.table-select-cell {
    width: 44px;
}
.table-select-cell input {
    width: 16px;
    height: 16px;
}
