:root {
    --ink: #172033;
    --muted: #26282b;
    --line: #e5e9f0;
    --surface: #fff;
    --canvas: #f5f7fa;
    --primary: #2357d9;
    --primary-dark: #1946b8;
    --shadow: 0 10px 30px rgba(23, 32, 51, .07);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--canvas);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
    font: inherit;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 32px;
    padding: 0 max(24px, calc((100vw - 1180px)/2));
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.chat-only .app-header {
    position: static;
    justify-content: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    text-decoration: none;
    font-size: 15px;
}

.app-main {
    width: 100%;
}

.page-shell {
    width: min(1120px, calc(100% - 40px));
    margin: 0 auto;
    padding: 54px 0 70px;
}

.chat-shell {
    width: min(850px, calc(100% - 40px));
}

.page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.page-heading h1 {
    margin: 5px 0 8px;
    font-size: clamp(28px, 4vw, 40px);
    line-height: 1.1;
    letter-spacing: -1.2px;
}

.page-heading p {
    max-width: 650px;
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.compact-heading {
    align-items: center;
}

.chat-card {
    display: flex;
    flex-direction: column;
    height: min(650px, calc(100vh - 220px));
    min-height: 500px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.chat-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 13px;
    overflow-y: auto;
    padding: 24px;
    background: #fbfcfe;
}

.welcome-message {
    align-self: center;
    padding: 10px 14px;
    border: 1px solid #3a3a3a;
    border-radius: 9px;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
}

.welcome-message span {
    margin-right: 5px;
    color: var(--primary);
    font-weight: 800;
}

.message {
    max-width: 78%;
    padding: 12px 15px;
    border-radius: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.message.user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    border: 1px solid var(--line);
    background: #fff;
    border-bottom-left-radius: 4px;
}

.typing-indicator {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 16px;
    border-top: 1px solid var(--line);
    background: #fff;
}

.chat-input-area input {
    width: 100%;
    min-height: 44px;
    padding: 11px 14px;
    border: 1px solid #cfd6e2;
    border-radius: 10px;
    background: #fafbfc;
    color: var(--ink);
    outline: none;
}

.chat-input-area input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(35, 87, 217, .12);
}

.button-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 17px;
    border: 1px solid var(--primary);
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}

.button-primary:hover {
    background: var(--primary-dark);
}

button:disabled {
    cursor: not-allowed;
    opacity: .48;
}

@media (max-width:720px) {
    .app-header {
        height: auto;
        align-items: flex-start;
        padding: 14px 18px;
        flex-direction: column;
        gap: 10px;
    }

    .chat-only .app-header {
        align-items: center;
    }

    .page-shell {
        width: min(100% - 28px, 1120px);
        padding: 34px 0 50px;
    }

    .page-heading {
        flex-direction: column;
    }

    .compact-heading {
        align-items: flex-start;
    }

    .chat-card {
        height: calc(100vh - 260px);
        min-height: 480px;
    }

    .button-primary {
        width: 100%;
    }

    .message {
        max-width: 90%;
    }
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.app-nav a {
    padding: 9px 12px;
    border-radius: 8px;
    color: #536078;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}

.app-nav a:hover {
    background: #eef2f8;
    color: var(--ink);
}

.table-card,
.conversation-card {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.table-card {
    overflow: hidden;
}

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 17px 20px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

th {
    background: #fafbfc;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: .7px;
    text-transform: uppercase;
}

td {
    font-size: 14px;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.align-right {
    text-align: right;
}

.table-link {
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.empty-state {
    padding: 60px 24px;
    text-align: center;
}

.empty-state h2 {
    margin: 0 0 8px;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
}

.conversation-card {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 28px;
}

.button-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 17px;
    border: 1px solid #d2d8e2;
    border-radius: 9px;
    background: #fff;
    color: #37445a;
    font-weight: 700;
    font-size: 13px;
    text-decoration: none;
}

.message p {
    margin: 0;
}

.message>span {
    display: block;
    margin: 0 5px 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.message.user>span {
    color: #ffffff;
    text-align: right;
}

.form-card,
.table-card,
.chat-card,
.conversation-card {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.form-card {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 30px;
}

.form-card form {
    display: flex;
    flex-direction: column;
    gap: 26px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field label,
.scenario-bar label {
    font-size: 13px;
    font-weight: 700;
}

.field small {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.field input,
.field select,
.field textarea,
.scenario-bar select,
.chat-input-area input {
    width: 100%;
    border: 1px solid #cfd6e2;
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    outline: none;
}

.field input,
.field select,
.scenario-bar select {
    min-height: 44px;
    padding: 10px 12px;
}

.field textarea {
    min-height: 190px;
    padding: 13px;
    resize: vertical;
    line-height: 1.55;
}

.field textarea.source-text {
    min-height: 145px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.scenario-bar select:focus,
.chat-input-area input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(35, 87, 217, .12);
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.module-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 18px;
    min-height: 145px;
    padding: 26px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    text-decoration: none;
}

.module-card:hover {
    border-color: #aeb9ca;
}

.module-icon {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: #edf2ff;
    color: var(--primary);
    font-size: 23px;
    font-weight: 500;
}

.module-card h2 {
    margin: 0 0 6px;
    font-size: 17px;
}

.module-card p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.feedback-card h2 { margin:0 0 7px; font-size:20px; }