/* Reset + base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: #f6f7f8;
    color: #1a1a1a;
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

.screen { height: 100vh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ============ Login screen ============ */

#login-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a2332 0%, #2d3e50 100%);
}

.login-box {
    background: #fff;
    border-radius: 12px;
    padding: 40px;
    width: 360px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.login-box h1 {
    font-size: 22px;
    margin-bottom: 4px;
    color: #1a1a1a;
}

.login-box .subtitle {
    color: #777;
    font-size: 14px;
    margin-bottom: 24px;
}

#login-form { display: flex; flex-direction: column; gap: 12px; }

#password-input,
#message-input {
    border: 1px solid #d0d0d0;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}

#password-input:focus,
#message-input:focus { border-color: #2d6cdf; }

#login-form button,
#send-btn {
    background: #2d6cdf;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

#login-form button:hover:not(:disabled),
#send-btn:hover:not(:disabled) { background: #2156c0; }

#login-form button:disabled,
#send-btn:disabled { background: #aaa; cursor: not-allowed; }

.error {
    color: #d32f2f;
    font-size: 13px;
    min-height: 18px;
    text-align: center;
}

/* ============ Chat screen ============ */

#chat-screen { background: #f6f7f8; }

header {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

header h1 { font-size: 16px; font-weight: 600; }

.header-actions { display: flex; gap: 8px; }

.header-button {
    background: transparent;
    color: #555;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.header-button:hover { background: #f0f0f0; color: #1a1a1a; }

main#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 880px;
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 90%;
}

.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }
.message.system { align-self: center; align-items: center; max-width: 600px; }

.message-label {
    font-size: 12px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.6;
}

.message.user .message-bubble {
    background: #2d6cdf;
    color: white;
}

.message.system .message-bubble {
    background: transparent;
    color: #777;
    font-style: italic;
    padding: 12px;
    text-align: center;
    box-shadow: none;
}

.message-sources {
    font-size: 12px;
    color: #777;
    background: #fafafa;
    border: 1px solid #eaeaea;
    border-radius: 8px;
    padding: 8px 12px;
    margin-top: 2px;
    max-width: 100%;
}

.message-sources-header {
    font-weight: 500;
    margin-bottom: 4px;
    color: #555;
}

.message-sources ul { list-style: none; }

.message-sources li {
    padding: 2px 0;
    word-break: break-word;
}

.source-kind {
    display: inline-block;
    background: #e8eef9;
    color: #2156c0;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    margin-right: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.source-kind.email { background: #f0e8f9; color: #6a3aa0; }

/* ============ Teach the bot ============ */

.teach-button {
    align-self: flex-start;
    background: transparent;
    color: #777;
    border: 1px dashed #c8c8c8;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    margin-top: 2px;
}

.teach-button:hover {
    background: #fff;
    color: #2d6cdf;
    border-color: #2d6cdf;
    border-style: solid;
}

.teach-form {
    background: #fff8e8;
    border: 1px solid #f0d486;
    border-radius: 8px;
    padding: 12px;
    margin-top: 4px;
    max-width: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.teach-form-label {
    font-size: 12px;
    color: #6a5400;
    font-weight: 500;
}

.teach-form textarea {
    border: 1px solid #e0c87a;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 70px;
    background: #fff;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}

.teach-form textarea:focus { border-color: #b4901c; }

.teach-form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
}

.teach-form-error {
    color: #b3261e;
    font-size: 12px;
    margin-right: auto;
}

.teach-save,
.teach-cancel {
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.teach-save {
    background: #2d6cdf;
    color: white;
}

.teach-save:hover:not(:disabled) { background: #2156c0; }
.teach-save:disabled { background: #aaa; cursor: not-allowed; }

.teach-cancel {
    background: transparent;
    color: #6a5400;
    border: 1px solid transparent;
}

.teach-cancel:hover { background: rgba(0, 0, 0, 0.05); }

/* ============ Manage Teachings modal ============ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 25, 40, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-card {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 720px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eaeaea;
}

.modal-header h2 {
    font-size: 18px;
    margin: 0;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #888;
    padding: 0 6px;
    border-radius: 4px;
}

.modal-close:hover {
    color: #222;
    background: #f1f1f1;
}

.modal-subtitle {
    padding: 12px 20px;
    font-size: 13px;
    color: #555;
    background: #fafafa;
    border-bottom: 1px solid #eaeaea;
}

.modal-body {
    padding: 12px 20px 20px;
    overflow-y: auto;
    flex: 1;
}

.teaching-card {
    border: 1px solid #e6e6e6;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 12px;
    background: #fff;
}

.teaching-meta {
    font-size: 11px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}

.teaching-question {
    font-weight: 600;
    font-size: 14px;
    color: #1a1a1a;
    margin-bottom: 6px;
}

.teaching-lesson {
    font-size: 14px;
    color: #333;
    white-space: pre-wrap;
    margin-bottom: 10px;
    line-height: 1.5;
}

.teaching-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.teaching-delete {
    background: transparent;
    color: #b3261e;
    border: 1px solid #f0c5c2;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}

.teaching-delete:hover:not(:disabled) {
    background: #fdecea;
    color: #8a1d17;
}

.teaching-delete:disabled {
    color: #aaa;
    border-color: #ddd;
    cursor: not-allowed;
}

.teaching-confirm {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #b3261e;
}

.teaching-empty {
    text-align: center;
    color: #888;
    padding: 24px 12px;
    font-style: italic;
}

.teaching-loading {
    text-align: center;
    color: #888;
    padding: 24px 12px;
}

.teach-saved {
    align-self: flex-start;
    font-size: 12px;
    color: #1e7a3e;
    background: #e6f4ea;
    border: 1px solid #bcdcc4;
    border-radius: 6px;
    padding: 4px 10px;
    margin-top: 2px;
}

/* ============ Draft preview card (chat-triggered drafter) ============ */

.draft-card {
    background: #fff;
    border: 1px solid #d8d8d8;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    overflow: hidden;
    margin-top: 4px;
    max-width: 100%;
    width: 100%;
}

.draft-card-header {
    background: #f3f6fc;
    padding: 10px 14px;
    border-bottom: 1px solid #e1e6f1;
    font-size: 12px;
    color: #2156c0;
}

.draft-card-header-row {
    display: grid;
    grid-template-columns: 60px 1fr;
    gap: 4px 10px;
    align-items: baseline;
}

.draft-card-label {
    color: #6b7a99;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-size: 10.5px;
}

.draft-card-value {
    color: #1a2440;
    word-break: break-word;
    font-size: 13px;
}

.draft-card-body {
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    color: #1a1a1a;
    min-height: 1.5em;
}

.draft-card-status {
    padding: 6px 14px;
    font-size: 12px;
    color: #6b7a99;
    background: #fafbff;
    border-top: 1px dashed #e1e6f1;
}

.draft-card-footer {
    padding: 8px 14px;
    background: #f9faff;
    border-top: 1px solid #e1e6f1;
    font-size: 12px;
    color: #6b7a99;
}

.draft-card-footer code {
    background: #e8eef9;
    padding: 1px 6px;
    border-radius: 3px;
    color: #2156c0;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 11.5px;
}

/* Streaming cursor */
.streaming-cursor::after {
    content: "▌";
    color: #2d6cdf;
    animation: blink 1s infinite;
    margin-left: 1px;
}

@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

footer {
    background: white;
    border-top: 1px solid #e0e0e0;
    padding: 16px 24px;
    flex-shrink: 0;
}

#chat-form {
    display: flex;
    gap: 8px;
    max-width: 880px;
    margin: 0 auto;
    align-items: flex-end;
}

#message-input {
    resize: none;
    max-height: 200px;
    min-height: 48px;
    font-size: 15px;
    flex: 1;
}

#send-btn { padding: 12px 20px; align-self: stretch; }

.footer-hint {
    font-size: 11px;
    color: #999;
    text-align: center;
    margin-top: 8px;
    max-width: 880px;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 600px) {
    main#messages { padding: 12px; }
    .message { max-width: 95%; }
    header { padding: 10px 12px; }
    header h1 { font-size: 14px; }
    footer { padding: 10px 12px; }
}
