*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --teal: #006d77;
    --teal-dark: #004d55;
    --teal-light: #e0f4f5;
    --green: #00a859;
    --gold: #c9a227;
    --gold-bg: #3d3520;
    --green-bg: #1a3d2e;
    --blue-bg: #1a2d4d;
    --red-bg: #3d1f28;
    --red: #e05a6a;
    --bg: #f4f7f7;
    --surface: #ffffff;
    --text: #1a2e2e;
    --text-muted: #5a7070;
    --border: #dce8e8;
    --radius: 14px;
    --header-gradient: url('../img/header-gradient.png');
    --shadow: 0 4px 24px rgba(0, 77, 85, 0.08);
}

body {
    font-family: "Alexandria", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.7;
    overflow-x: hidden;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

a {
    color: var(--teal);
    text-decoration: none;
}

/* Nav */
.topnav {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.04);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: inherit;
    flex-shrink: 0;
}

.brand-logo {
    height: 52px;
    width: auto;
    max-width: 240px;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.brand-text strong {
    font-size: 0.95rem;
    font-weight: 700;
}

.brand-text small {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 400;
}

.nav-links {
    display: flex;
    flex: 1;
    justify-content: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.topnav-side {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    margin-inline-start: auto;
}

.nav-user-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: var(--text-muted);
    border: 1px solid var(--border);
    background: var(--surface);
    transition: all 0.2s;
}

.nav-user-btn:hover,
.nav-user-btn.active {
    color: var(--teal);
    background: var(--teal-light);
    border-color: var(--teal-light);
}

.nav-user-icon {
    width: 20px;
    height: 20px;
    display: block;
}

.nav-link {
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--teal);
    background: var(--teal-light);
}

.nav-link.active {
    background: var(--teal-light);
    color: var(--teal-dark);
    font-weight: 600;
}

.legacy-link {
    font-size: 1.1rem;
    color: var(--text-muted);
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    flex-shrink: 0;
}

.legacy-link:hover {
    background: var(--teal-light);
    color: var(--teal);
}

.page-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 2rem;
}

.site-footer {
    text-align: center;
    padding: 1.25rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.site-footer a {
    color: var(--teal);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--teal);
    color: white;
}

.btn-primary:hover {
    background: var(--teal-dark);
}

.btn-outline {
    background: white;
    color: var(--teal);
    border-color: var(--teal);
}

.btn-outline:hover {
    background: var(--teal-light);
}

.btn-block {
    width: 100%;
}

/* Hero */
.hero {
    text-align: center;
    padding: 2.5rem 1rem 2rem;
    background: var(--surface);
    border-radius: calc(var(--radius) + 4px);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.page-hero.compact {
    text-align: center;
    padding: 2rem 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.page-hero h1,
.hero h1 {
    font-size: clamp(1.4rem, 4vw, 2rem);
    font-weight: 800;
    color: var(--teal-dark);
    margin: 0.75rem 0 0.5rem;
}

.hero-desc,
.page-hero p {
    color: var(--text-muted);
    max-width: 560px;
    margin: 0 auto 1.25rem;
    font-size: 0.92rem;
}

.pill-badge {
    display: inline-block;
    padding: 0.3rem 0.85rem;
    background: var(--teal-light);
    color: var(--teal-dark);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.hero-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    max-width: 520px;
    margin: 0 auto;
}

.stat-card {
    text-align: center;
}

.stat-card strong {
    display: block;
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--teal);
    line-height: 1.2;
}

.stat-card span {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Sections */
.section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.section-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.section-head h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--teal-dark);
}

.section-icon {
    font-size: 1.2rem;
}

/* Categories */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.85rem;
}

.category-card {
    border-radius: var(--radius);
    padding: 1.25rem 1rem;
    text-align: center;
    color: white;
    min-height: 130px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.category-card p {
    font-size: 0.72rem;
    opacity: 0.85;
    line-height: 1.5;
}

.cat-gold { background: linear-gradient(145deg, #4a4020, var(--gold-bg)); }
.cat-green { background: linear-gradient(145deg, #1f5038, var(--green-bg)); }
.cat-blue { background: linear-gradient(145deg, #1e3a6e, var(--blue-bg)); }
.cat-red { background: linear-gradient(145deg, #5a2030, var(--red-bg)); }

.cat-icon {
    font-size: 1.75rem;
}

.category-card h3 {
    font-size: 0.95rem;
    font-weight: 700;
}

/* Architecture */
.architecture-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.arch-layer {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.15rem;
    border-radius: var(--radius);
    background: linear-gradient(
        90deg,
        hsl(calc(175 - var(--i) * 8), 60%, calc(42% - var(--i) * 4%)),
        hsl(calc(175 - var(--i) * 8), 55%, calc(32% - var(--i) * 3%))
    );
    color: white;
    font-weight: 600;
    font-size: 0.88rem;
}

.arch-num {
    font-size: 0.82rem;
    opacity: 0.85;
    min-width: 2rem;
}

/* Compliance */
.compliance-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.compliance-card {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-weight: 500;
    border: 1px solid;
}

.compliance-card.deny {
    background: rgba(224, 90, 106, 0.08);
    border-color: rgba(224, 90, 106, 0.35);
    color: #9b2030;
}

.compliance-card.allow {
    background: rgba(0, 168, 89, 0.08);
    border-color: rgba(0, 168, 89, 0.35);
    color: var(--green);
}

.disclaimer-inline {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
}

/* Services page */
.service-category {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.category-header {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 1.25rem;
    background: var(--teal);
    color: white;
}

.category-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.cat-head-icon {
    font-size: 1.25rem;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
    padding: 1rem;
}

.tool-chip {
    display: block;
    padding: 0.55rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.78rem;
    color: var(--text);
    transition: all 0.2s;
}

.tool-chip::before {
    content: "• ";
    color: var(--teal);
    font-weight: 700;
}

.tool-chip:hover {
    border-color: var(--teal);
    background: var(--teal-light);
    color: var(--teal-dark);
}

/* Entities */
.alert-info {
    padding: 0.85rem 1.15rem;
    background: #fff8e6;
    border: 1px solid #f0d080;
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: #7a5c00;
    margin-bottom: 1.25rem;
}

.entities-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.entity-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.entity-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.15rem;
    background: var(--teal);
    color: white;
}

.entity-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.entity-header small {
    font-size: 0.72rem;
    opacity: 0.85;
}

.entity-body {
    padding: 1.15rem;
}

.entity-body p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
}

.entity-body h4 {
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--teal-dark);
}

.entity-body ul {
    list-style: none;
    margin-bottom: 1rem;
}

.entity-body li {
    font-size: 0.82rem;
    padding: 0.25rem 0;
    padding-right: 1.25rem;
    position: relative;
}

.entity-body li::before {
    content: "✓";
    position: absolute;
    right: 0;
    color: var(--teal);
    font-weight: 700;
}

.entity-link {
    font-size: 0.82rem;
    font-weight: 600;
}

/* Dashboard */
.dashboard-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

.dash-icon {
    width: 48px;
    height: 48px;
    background: var(--teal);
    color: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.dashboard-stats {
    max-width: none;
    margin-bottom: 1.25rem;
}

.dash-stat {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: start;
}

.dash-stat-icon {
    width: 44px;
    height: 44px;
    background: var(--teal-light);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
}

.dash-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.dash-card h2 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--teal-dark);
}

.dash-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.dash-card-head h2 {
    margin-bottom: 0;
}

.view-all-link {
    font-size: 0.82rem;
    font-weight: 600;
}

.dash-meta {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin: -0.5rem 0 1.25rem;
}

.engine-badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}

.engine-on {
    background: var(--green-light);
    color: var(--green-dark);
}

.engine-off {
    background: #fff3cd;
    color: #856404;
}

.conv-table-wrap {
    overflow-x: auto;
}

.conv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.conv-table th,
.conv-table td {
    padding: 0.65rem 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.conv-table th {
    font-weight: 700;
    color: var(--teal-dark);
    background: var(--bg);
}

.conv-table tr:hover td {
    background: var(--teal-light);
}

.table-link {
    font-weight: 600;
    font-size: 0.78rem;
}

.stage-pill {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: var(--teal-light);
    color: var(--teal-dark);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}

.back-link {
    margin-top: 1rem;
    font-size: 0.85rem;
}

.compact-stats {
    margin-bottom: 1.25rem;
}

.detail-messages {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.detail-msg {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.detail-msg-user {
    background: var(--teal-light);
    border-color: rgba(0, 109, 119, 0.2);
}

.detail-msg-bot {
    background: var(--bg);
}

.detail-msg-role {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.detail-msg-body {
    font-size: 0.88rem;
    line-height: 1.7;
}

.detail-msg time {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.chat-history .hist-title {
    display: block;
    font-weight: 600;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history .hist-meta {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.chat-history li.empty-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: default;
}

.chat-history li:not(.empty-hint):hover {
    background: var(--teal-light);
}


.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

.empty-state span {
    font-size: 2.5rem;
    opacity: 0.35;
    display: block;
    margin-bottom: 0.5rem;
}

.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.logout-form {
    margin: 0;
    width: 100%;
}

/* Chat layout */
.chat-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1rem;
    min-height: calc(100vh - 180px);
}

.chat-sidebar {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    height: fit-content;
}

.chat-sidebar-head {
    display: none;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--teal-dark);
}

.sidebar-close-btn {
    border: none;
    background: var(--bg);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.chat-history-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: white;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-sidebar-overlay {
    display: none;
}

body.sidebar-open {
    overflow: hidden;
}

.sidebar-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    margin: 1rem 0 0.5rem;
}

.chat-history {
    list-style: none;
}

.chat-history li {
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);
    cursor: pointer;
}

.chat-history li.active {
    background: var(--teal-light);
    color: var(--teal-dark);
    font-weight: 600;
}

.chat-panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-panel-head {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    background: #0a5c4d var(--header-gradient) center / cover no-repeat;
    color: white;
}

.chat-head-logo {
    height: 72px;
    width: auto;
    max-width: min(320px, 60vw);
    object-fit: contain;
    flex-shrink: 0;
}

.chat-head-text strong {
    display: block;
    font-size: 0.92rem;
}

.chat-head-text small {
    font-size: 0.72rem;
    opacity: 0.7;
}

.ai-disclaimer-banner {
    padding: 0.5rem 1rem;
    background: #fff8e6;
    border-bottom: 1px solid #f0d080;
    font-size: 0.76rem;
    color: #7a5c00;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 260px;
    max-height: 380px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message {
    flex-direction: row-reverse;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #0d0d0d;
    border: 2px solid var(--teal);
    overflow: hidden;
    font-size: 0.9rem;
}

.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 3px;
}

.user-message .avatar {
    background: var(--teal-light);
    border-color: var(--teal);
}

.bubble {
    max-width: 78%;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.bot-message .bubble {
    background: var(--bg);
    border: 1px solid var(--border);
}

.user-message .bubble {
    background: var(--teal);
    color: white;
}

.topic-badge {
    display: inline-block;
    background: var(--teal-light);
    color: var(--teal-dark);
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    margin-bottom: 0.4rem;
}

.topic-badge.out-of-scope {
    background: #fde8e8;
    color: #9b1c1c;
}

.bot-message .bubble a {
    color: var(--teal-dark);
    font-weight: 600;
    text-decoration: underline;
}

.stage-section {
    padding: 0.75rem 1.15rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.stage-section h4 {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.stage-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.stage-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.65rem 0.35rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: white;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text);
}

.stage-btn:hover {
    border-color: var(--teal);
}

.stage-btn.active {
    border-color: var(--teal);
    background: var(--teal-light);
    color: var(--teal-dark);
}

.stage-btn.stage-red.active {
    border-color: var(--red);
    background: rgba(224, 90, 106, 0.12);
    color: #9b2030;
}

.stage-btn.stage-gold.active {
    border-color: var(--gold);
    background: rgba(201, 162, 39, 0.12);
    color: #7a5c00;
}

.stage-icon {
    font-size: 1.25rem;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.65rem 1.15rem;
}

.suggestion-btn {
    background: white;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.8rem;
    font-family: inherit;
    font-size: 0.76rem;
    color: var(--teal-dark);
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    background: var(--teal-light);
    border-color: var(--teal);
}

.input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.85rem 1.15rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.input-area input[type="text"] {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
}

.input-area input:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--teal-light);
}

.input-area button {
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: var(--teal);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    order: -1;
}

.input-area button:hover {
    background: var(--teal-dark);
}

.input-area button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.typing .bubble {
    display: flex;
    gap: 4px;
    padding: 1rem;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--teal);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* Responsive */
@media (max-width: 900px) {
    .entities-grid,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .chat-layout {
        grid-template-columns: 1fr;
        min-height: calc(100dvh - 110px);
    }

    .page-main.page-chat {
        padding: 0;
        max-width: none;
    }

    .page-main.page-chat + .site-footer {
        display: none;
    }

    .chat-panel {
        border-radius: 0;
        min-height: calc(100dvh - 110px);
    }

    .chat-panel-head {
        padding: 0.65rem 0.85rem;
        gap: 0.65rem;
    }

    .chat-head-logo {
        height: 44px;
        max-width: min(200px, 45vw);
    }

    .chat-head-text strong {
        font-size: 0.82rem;
    }

    .chat-history-toggle {
        display: inline-flex;
    }

    .chat-sidebar-head {
        display: flex;
    }

    .chat-sidebar {
        display: block;
        position: fixed;
        top: 0;
        right: 0;
        width: min(300px, 88vw);
        height: 100dvh;
        z-index: 300;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        border-radius: 0;
        overflow-y: auto;
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    .chat-sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 299;
    }

    .chat-sidebar-overlay.open {
        display: block;
    }

    .messages {
        flex: 1;
        min-height: 0;
        max-height: none;
    }

    .stage-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .bubble {
        max-width: 88%;
    }

    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .topnav {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "brand side"
            "links links";
        align-items: center;
        gap: 0.45rem 0.65rem;
        padding: 0.65rem 0.85rem;
    }

    .brand {
        grid-area: brand;
        min-width: 0;
    }

    .topnav-side {
        grid-area: side;
        margin-inline-start: 0;
    }

    .nav-links {
        grid-area: links;
        flex: none;
        width: 100%;
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0.25rem;
        padding-bottom: 0.1rem;
    }

    .nav-links::-webkit-scrollbar {
        display: none;
    }

    .nav-link {
        white-space: nowrap;
        flex-shrink: 0;
        font-size: 0.8rem;
        padding: 0.4rem 0.7rem;
    }

    .brand-logo {
        height: 38px;
        max-width: 130px;
    }

    .brand-text strong {
        font-size: 0.82rem;
    }

    .brand-text small {
        font-size: 0.65rem;
    }

    .page-main {
        padding: 1rem 0.85rem 1.5rem;
    }

    .hero {
        padding: 1.75rem 0.85rem 1.5rem;
        border-radius: var(--radius);
    }

    .page-hero.compact {
        padding: 1.5rem 0.85rem;
    }

    .section {
        padding: 1.15rem;
    }

    .hero-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .hero-actions .btn {
        width: 100%;
    }

    .stats-row {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.65rem;
    }

    .stat-card strong {
        font-size: 1.35rem;
    }

    .categories-grid,
    .compliance-grid,
    .entities-grid {
        grid-template-columns: 1fr;
    }

    .tools-grid {
        grid-template-columns: 1fr;
    }

    .category-card {
        min-height: auto;
        padding: 1rem;
    }

    .arch-layer {
        font-size: 0.8rem;
        padding: 0.75rem 0.85rem;
        gap: 0.65rem;
    }

    .dash-card {
        padding: 1rem;
    }

    .dash-card-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }

    .conv-table {
        font-size: 0.75rem;
        min-width: 520px;
    }

    .suggestions {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-inline: 0.85rem;
    }

    .suggestions::-webkit-scrollbar {
        display: none;
    }

    .suggestion-btn {
        flex-shrink: 0;
        max-width: 85vw;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .input-area {
        padding: 0.65rem 0.85rem;
        padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
    }

    .input-area input[type="text"] {
        font-size: 16px;
    }

    .ai-disclaimer-banner {
        font-size: 0.72rem;
        padding: 0.45rem 0.85rem;
    }

    .stage-section {
        padding: 0.65rem 0.85rem;
    }

    .stage-btn {
        font-size: 0.7rem;
        padding: 0.55rem 0.25rem;
    }

    .site-footer {
        padding: 1rem 0.85rem;
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        font-size: 0.72rem;
    }
}

@media (max-width: 640px) {
    .brand-text small {
        display: none;
    }

    .stats-row,
    .dashboard-stats {
        grid-template-columns: 1fr 1fr;
    }

    .stage-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 400px) {
    .brand-text {
        display: none;
    }

    .stats-row,
    .dashboard-stats {
        grid-template-columns: 1fr;
    }

    .stage-grid {
        grid-template-columns: 1fr 1fr;
    }

    .chat-head-text small {
        display: none;
    }
}

/* Admin login */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50vh;
    padding: 1rem 0;
}

.login-card {
    width: min(420px, 100%);
    background: var(--surface);
    border-radius: calc(var(--radius) + 2px);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.login-card-head {
    padding: 1.5rem 1.5rem 1rem;
    background: #0a5c4d var(--header-gradient) center / cover no-repeat;
    color: white;
}

.login-card-head h1 {
    font-size: 1.35rem;
    font-weight: 800;
    margin-bottom: 0.35rem;
}

.login-card-head p {
    font-size: 0.85rem;
    opacity: 0.85;
}

.login-error {
    margin: 1rem 1.5rem 0;
    padding: 0.65rem 0.85rem;
    background: #fde8ea;
    color: #9b1c2e;
    border-radius: 10px;
    font-size: 0.85rem;
}

.login-form {
    padding: 1.25rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.login-field span {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

.login-field input,
.login-input {
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    width: 100%;
}

.login-field input:focus,
.login-input:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(0, 109, 119, 0.12);
}

.field-error {
    font-size: 0.78rem;
    color: #9b1c2e;
}

.field-hint,
.login-field ul {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
    padding-right: 1rem;
    list-style: disc;
}

.login-success {
    margin: 1rem 1.5rem 0;
    padding: 0.65rem 0.85rem;
    background: #e6f7ef;
    color: #0d6b3f;
    border-radius: 10px;
    font-size: 0.85rem;
}

.login-submit {
    margin-top: 0.25rem;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius);
    background: var(--teal);
    color: white;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
}

.login-submit:hover {
    background: var(--teal-dark);
}

.login-back {
    padding: 0 1.5rem 1.25rem;
    font-size: 0.82rem;
}

.login-back a {
    color: var(--teal);
    font-weight: 600;
}
