:root {
    color-scheme: light;
    --ink: #17202a;
    --muted: #607080;
    --line: #d7dde3;
    --panel: #ffffff;
    --page: #edf2f5;
    --accent: #1f6f8b;
    --accent-dark: #164d61;
    --danger: #a52828;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: linear-gradient(135deg, #edf2f5 0%, #dfe8ed 48%, #eef0e8 100%);
}

.login-wrap,
.shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.shell.wide {
    place-items: start center;
}

.login-panel,
.panel {
    width: min(100%, 460px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 32px;
    box-shadow: 0 18px 45px rgba(31, 55, 70, 0.14);
}

.panel {
    width: min(100%, 760px);
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1 {
    margin: 0 0 12px;
    font-size: clamp(32px, 5vw, 48px);
    line-height: 1.05;
}

.lead {
    margin: 0 0 28px;
    color: var(--muted);
    font-size: 18px;
    line-height: 1.5;
}

.top-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 28px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.tab {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    border-radius: 6px;
    padding: 0 12px;
    color: #304654;
    text-decoration: none;
    font-weight: 700;
}

.tab:hover {
    background: #eef3f6;
}

.tab.active {
    background: var(--accent);
    color: #fff;
}

form {
    display: grid;
    gap: 18px;
    margin-top: 22px;
}

label {
    display: grid;
    gap: 8px;
    color: #2d3a45;
    font-size: 14px;
    font-weight: 700;
}

input {
    width: 100%;
    border: 1px solid #bfc8d0;
    border-radius: 6px;
    padding: 12px 13px;
    font: inherit;
}

textarea {
    width: 100%;
    resize: vertical;
    border: 1px solid #bfc8d0;
    border-radius: 6px;
    padding: 12px 13px;
    font: inherit;
    line-height: 1.45;
}

input:focus,
textarea:focus {
    border-color: var(--accent);
    outline: 3px solid rgba(31, 111, 139, 0.16);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: 0;
    border-radius: 6px;
    padding: 0 18px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

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

.button.secondary {
    width: fit-content;
    margin-top: 28px;
    background: #2f3f4a;
}

.error {
    margin: 18px 0 0;
    border: 1px solid #efb5b5;
    border-radius: 6px;
    padding: 12px;
    color: var(--danger);
    background: #fff2f2;
}

.notice {
    margin: 18px 0 0;
    border: 1px solid #aed7bd;
    border-radius: 6px;
    padding: 12px;
    color: #1d6a38;
    background: #effaf2;
}

.sync-status {
    margin: -14px 0 22px;
    color: var(--muted);
    font-size: 14px;
}

.analysis-box {
    margin: 0 0 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #f8fafb;
}

.pulse-box {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 180px auto;
    gap: 20px;
    align-items: center;
    margin: 0 0 24px;
    border: 1px solid #bad7df;
    border-radius: 8px;
    padding: 20px;
    background: #f3fbfd;
}

.pulse-visual {
    margin: 0;
    display: grid;
    justify-items: center;
    gap: 4px;
}

.pulse-visual svg {
    width: 160px;
    max-width: 100%;
}

.pulse-visual rect {
    fill: #ffffff;
    stroke: #87b7c6;
    stroke-width: 4;
}

.pulse-visual path {
    fill: none;
    stroke: #1f6f8b;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.pulse-visual circle {
    fill: #1f6f8b;
}

.pulse-visual text {
    fill: #fff;
    font: 800 26px Arial, Helvetica, sans-serif;
}

.pulse-visual .spark {
    fill: #f2b84b;
    stroke: #c78113;
    stroke-width: 2;
}

.pulse-visual-alert circle,
.pulse-visual-shield circle {
    fill: #b42318;
}

.pulse-visual-coin circle {
    fill: #2f7d47;
}

.pulse-visual-megaphone circle {
    fill: #7b4db3;
}

.pulse-visual-calendar circle {
    fill: #4059ad;
}

.pulse-visual figcaption {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.pulse-box h2 {
    margin: 0 0 8px;
    font-size: 22px;
}

.pulse-box p {
    margin: 0;
    color: #31424f;
    line-height: 1.5;
}

.pulse-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(72px, 1fr));
    gap: 8px;
}

.pulse-grid span {
    display: grid;
    gap: 3px;
    min-width: 72px;
    border: 1px solid #cfe1e7;
    border-radius: 8px;
    padding: 10px;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.pulse-grid strong {
    color: var(--ink);
    font-size: 22px;
}

.analysis-box h2 {
    margin: 0 0 10px;
    font-size: 18px;
}

.analysis-box p {
    margin: 0;
    color: #31424f;
    line-height: 1.55;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 28px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    margin-top: 26px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: #394a56;
    background: #f3f6f8;
    font-size: 13px;
}

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

.unread td {
    font-weight: 700;
}

.email-panel {
    width: min(100%, 1120px);
}

.chatbot-panel {
    width: min(100%, 880px);
}

.knowledge-panel {
    width: min(100%, 960px);
}

.chat-form {
    margin-top: 0;
}

.chat-answer {
    margin-top: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #f8fafb;
}

.chat-answer p {
    margin: 12px 0 0;
    line-height: 1.55;
}

.chat-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #31424f;
}

.chat-meta span {
    color: var(--muted);
}

.knowledge-form {
    margin-top: 0;
}

.knowledge-list {
    display: grid;
    gap: 14px;
    margin-top: 28px;
}

.knowledge-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #f8fafb;
}

.knowledge-item h2 {
    margin: 0 0 4px;
    font-size: 20px;
}

.knowledge-item p {
    margin: 10px 0 0;
    color: #31424f;
    line-height: 1.55;
}

.knowledge-item .knowledge-date {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.empty-state {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    color: var(--muted);
    background: #f8fafb;
}

.settings-form {
    grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
    align-items: end;
}

.settings-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin: 0 0 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #f8fafb;
}

.settings-card h2 {
    margin: 0 0 6px;
    font-size: 20px;
}

.settings-card p {
    margin: 0;
    color: var(--muted);
}

.toggle-form {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    border-radius: 999px;
    padding: 0 12px;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}

.status-pill.active {
    background: #2f7d47;
}

.status-pill.inactive {
    background: #8a3442;
}

.toolbar-form {
    display: block;
    margin: 0 0 6px;
}

.inline-form {
    display: inline;
    margin: 0;
}

.link-button {
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--danger);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

.email-link {
    color: var(--accent-dark);
    text-decoration: none;
}

.email-link:hover {
    text-decoration: underline;
}

.ai-flags {
    min-width: 58px;
    white-space: nowrap;
}

.ai-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    line-height: 1;
}

.ai-icon.important {
    background: #b42318;
}

.ai-icon.action {
    background: #1f6f8b;
}

.status-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: #f8fafb;
}

.label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 640px) {
    .login-panel,
    .panel {
        padding: 24px;
    }

    .status-grid {
        grid-template-columns: 1fr;
    }

    .settings-form {
        grid-template-columns: 1fr;
    }

    .settings-card,
    .toggle-form {
        align-items: stretch;
        flex-direction: column;
    }

    .pulse-box {
        grid-template-columns: 1fr;
    }

    .pulse-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .knowledge-item {
        grid-template-columns: 1fr;
    }
}
