/* ── Reset & base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f6f8; color: #1a1a2e; line-height: 1.6; min-height: 100vh; }

/* ── Login page ──────────────────────────────────── */
.login-wrapper {
    display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}
.login-card {
    background: #fff; border-radius: 12px; padding: 3rem 2.5rem; width: 100%; max-width: 440px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card h1 { font-size: 1.5rem; color: #1a1a2e; margin-bottom: 0.25rem; }
.login-card .subtitle { color: #666; font-size: 0.95rem; margin-bottom: 2rem; }
.login-card label { display: block; font-weight: 600; font-size: 0.85rem; color: #444; margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.05em; }
.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%; padding: 0.75rem 1rem; border: 2px solid #e0e0e0; border-radius: 8px; font-size: 1.1rem;
    font-family: 'Courier New', monospace; letter-spacing: 0.15em; text-transform: uppercase; transition: border-color 0.2s;
}
.login-card input:focus { outline: none; border-color: #0f3460; }
.login-card .btn {
    width: 100%; padding: 0.85rem; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600;
    cursor: pointer; margin-top: 1.5rem; transition: background 0.2s;
    background: #0f3460; color: #fff;
}
.login-card .btn:hover { background: #1a1a2e; }
.error-msg { background: #fef2f2; color: #b91c1c; padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; border-left: 4px solid #b91c1c; }

/* ── Chat interface ──────────────────────────────── */
.chat-wrapper { display: flex; flex-direction: column; height: 100vh; background: #fff; }
.chat-header {
    padding: 1rem 1.5rem; background: #1a1a2e; color: #fff; display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.chat-header h1 { font-size: 1.1rem; font-weight: 600; }
.chat-header .meta { font-size: 0.8rem; color: #94a3b8; }
.chat-header .cost-badge {
    background: rgba(255,255,255,0.1); padding: 0.3rem 0.75rem; border-radius: 20px; font-size: 0.8rem; color: #94a3b8;
}

.chat-messages {
    flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem;
}
.message { max-width: 80%; padding: 1rem 1.25rem; border-radius: 12px; line-height: 1.7; font-size: 0.95rem; white-space: pre-wrap; word-wrap: break-word; }
.message.assistant { background: #f0f4f8; color: #1a1a2e; align-self: flex-start; border-bottom-left-radius: 4px; }
.message.user { background: #0f3460; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.message.system { background: #fef9c3; color: #854d0e; align-self: center; max-width: 90%; text-align: center; font-size: 0.85rem; }

.typing-indicator { align-self: flex-start; padding: 1rem 1.25rem; background: #f0f4f8; border-radius: 12px; display: none; }
.typing-indicator span {
    display: inline-block; width: 8px; height: 8px; background: #94a3b8; border-radius: 50%;
    animation: typing 1.4s infinite; margin: 0 2px;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

.chat-input-area {
    padding: 1rem 1.5rem; border-top: 1px solid #e5e7eb; background: #fff; flex-shrink: 0;
}
.chat-input-row { display: flex; gap: 0.75rem; align-items: flex-end; }
.chat-input-row textarea {
    flex: 1; padding: 0.75rem 1rem; border: 2px solid #e0e0e0; border-radius: 10px; font-size: 0.95rem;
    font-family: inherit; resize: none; min-height: 48px; max-height: 150px; line-height: 1.5; transition: border-color 0.2s;
}
.chat-input-row textarea:focus { outline: none; border-color: #0f3460; }
.chat-input-row button {
    padding: 0.75rem 1.5rem; border: none; border-radius: 10px; font-size: 0.9rem; font-weight: 600;
    cursor: pointer; white-space: nowrap; transition: background 0.2s;
}
.btn-send { background: #0f3460; color: #fff; }
.btn-send:hover { background: #1a1a2e; }
.btn-send:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-end { background: #dc2626; color: #fff; }
.btn-end:hover { background: #b91c1c; }

.chat-footer { padding: 0.5rem 1.5rem; text-align: center; font-size: 0.75rem; color: #94a3b8; }

/* ── Transcript ──────────────────────────────────── */
.transcript-wrapper { max-width: 900px; margin: 0 auto; padding: 2rem 1.5rem; }
.transcript-header { margin-bottom: 2rem; }
.transcript-header h1 { font-size: 1.5rem; color: #1a1a2e; margin-bottom: 0.25rem; }
.transcript-header .meta-row { display: flex; gap: 2rem; flex-wrap: wrap; color: #666; font-size: 0.9rem; margin-top: 0.5rem; }
.transcript-actions { display: flex; gap: 0.75rem; margin: 1.5rem 0; }
.transcript-actions .btn {
    padding: 0.6rem 1.25rem; border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 600;
    cursor: pointer; text-decoration: none; transition: background 0.2s;
}
.btn-primary { background: #0f3460; color: #fff; }
.btn-primary:hover { background: #1a1a2e; }
.btn-secondary { background: #e5e7eb; color: #444; }
.btn-secondary:hover { background: #d1d5db; }

.transcript-messages { display: flex; flex-direction: column; gap: 1.25rem; }
.transcript-msg { padding: 1.25rem; border-radius: 10px; }
.transcript-msg.assistant { background: #f0f4f8; border-left: 4px solid #0f3460; }
.transcript-msg.user { background: #f8fafc; border-left: 4px solid #e87722; }
.transcript-msg .role { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.transcript-msg .role.assistant-role { color: #0f3460; }
.transcript-msg .role.user-role { color: #e87722; }
.transcript-msg .content { white-space: pre-wrap; word-wrap: break-word; line-height: 1.7; font-size: 0.95rem; }

/* ── Admin ───────────────────────────────────────── */
.admin-wrapper { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2rem; }
.admin-header h1 { font-size: 1.5rem; color: #1a1a2e; }

.card { background: #fff; border-radius: 10px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.card h2 { font-size: 1.15rem; color: #1a1a2e; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 2px solid #f0f4f8; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { display: flex; flex-direction: column; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { font-weight: 600; font-size: 0.8rem; color: #444; margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.04em; }
.form-group input, .form-group select, .form-group textarea {
    padding: 0.6rem 0.8rem; border: 2px solid #e0e0e0; border-radius: 8px; font-size: 0.9rem; font-family: inherit;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: #0f3460; }
.form-group textarea { resize: vertical; min-height: 100px; }

.created-code {
    background: #ecfdf5; border: 2px solid #10b981; border-radius: 10px; padding: 1rem 1.5rem; margin-bottom: 1.5rem;
    display: flex; align-items: center; justify-content: space-between;
}
.created-code .code { font-family: 'Courier New', monospace; font-size: 1.4rem; font-weight: 700; color: #065f46; letter-spacing: 0.1em; }
.created-code .hint { font-size: 0.85rem; color: #047857; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { text-align: left; padding: 0.6rem 0.75rem; background: #f0f4f8; font-weight: 600; color: #444; white-space: nowrap; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
td { padding: 0.6rem 0.75rem; border-top: 1px solid #f0f4f8; white-space: nowrap; }
tr:hover td { background: #fafbfc; }
.badge {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600;
}
.badge-green { background: #ecfdf5; color: #065f46; }
.badge-grey { background: #f3f4f6; color: #6b7280; }
.badge-red { background: #fef2f2; color: #991b1b; }
.badge-blue { background: #eff6ff; color: #1d4ed8; }
.badge-amber { background: #fffbeb; color: #92400e; }

.btn-sm {
    padding: 0.3rem 0.7rem; border: none; border-radius: 6px; font-size: 0.8rem; cursor: pointer;
    font-weight: 500; transition: background 0.2s;
}
.btn-danger { background: #fef2f2; color: #dc2626; }
.btn-danger:hover { background: #fee2e2; }
.btn-link { background: none; color: #0f3460; text-decoration: underline; border: none; cursor: pointer; font-size: 0.85rem; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .message { max-width: 92%; }
    .chat-header { flex-wrap: wrap; gap: 0.5rem; }
    .login-card { padding: 2rem 1.5rem; }
}
