* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: #f0f1f5;
    color: #1d1d1f;
    margin: 0;
}

/* ---------- Header bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.75rem;
    background: linear-gradient(90deg, #0071e3 0%, #00a3a3 55%, #7c3aed 100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.brand-mark {
    display: block;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}

.brand-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: white;
    letter-spacing: 0.02em;
}

.brand-sub {
    font-weight: 400;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
    margin-left: 0.35rem;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.18);
    color: white;
    border: none;
    border-radius: 50%;
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.32);
}

/* ---------- Layout ---------- */

main.page {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem;
}

.view[hidden] {
    display: none;
}

#mainView {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

/* #mainView's own `display: flex` (ID selector) outranks the class+attribute
   .view[hidden] rule above, so hidden was silently being ignored. An ID +
   attribute rule is the only thing with enough specificity to reliably win. */
#mainView[hidden],
#configView[hidden] {
    display: none;
}

.sidebar {
    flex: 0 0 190px;
    background: white;
    border-radius: 14px;
    padding: 1.1rem 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.sidebar h2 {
    font-size: 0.8rem;
    margin: 0 0 0.9rem 0;
    color: #86868b;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.persona-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.persona-btn {
    background: #f5f5f7;
    color: #1d1d1f;
    text-align: left;
    padding: 0.65rem 0.8rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-radius: 10px;
    border-left: 3px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.persona-btn:hover {
    background: #ececee;
}

.persona-btn.selected {
    background: color-mix(in srgb, var(--persona-color) 12%, white);
    border-left-color: var(--persona-color);
    color: #1d1d1f;
    font-weight: 600;
}

.persona-icon {
    font-size: 1.15rem;
    line-height: 1;
}

.container {
    flex: 1 1 auto;
    max-width: 720px;
}

.controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

button {
    font-size: 1rem;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: #0071e3;
    color: white;
    transition: filter 0.15s ease;
}

button:hover:not(:disabled) {
    filter: brightness(1.06);
}

button:disabled {
    background: #b0b0b5;
    cursor: not-allowed;
}

#stopBtn {
    background: #d70015;
}

#stopBtn:disabled {
    background: #b0b0b5;
}

.status {
    font-size: 0.9rem;
    color: #6e6e73;
}

.spinner {
    display: inline-block;
    width: 1.1rem;
    height: 1.1rem;
    border: 2px solid #d0d0d5;
    border-top-color: #0071e3;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.spinner[hidden] {
    display: none;
}

.spinner.listening {
    border-top-color: #0071e3;
}

.spinner.waiting {
    border-top-color: #34c759;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.panel {
    background: white;
    border-radius: 14px;
    padding: 1.1rem 1.3rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.panel h2 {
    font-size: 1rem;
    margin: 0 0 0.75rem 0;
    color: #6e6e73;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.panel-header h2 {
    margin: 0;
}

#stopTalkingBtn {
    background: #d70015;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    margin-bottom: 0.75rem;
}

.transcript {
    min-height: 120px;
    white-space: pre-wrap;
    line-height: 1.5;
}

.summary {
    line-height: 1.6;
}

.summary > *:first-child {
    margin-top: 0;
}

.summary > *:last-child {
    margin-bottom: 0;
}

.summary h1,
.summary h2,
.summary h3 {
    margin: 1.1em 0 0.4em 0;
    line-height: 1.3;
}

.summary h1 { font-size: 1.25rem; }
.summary h2 { font-size: 1.1rem; }
.summary h3 { font-size: 1rem; }

.summary p {
    margin: 0.6em 0;
}

.summary ul,
.summary ol {
    margin: 0.6em 0;
    padding-left: 1.4em;
}

.summary li {
    margin: 0.25em 0;
}

.summary code {
    background: #f0f0f2;
    border-radius: 4px;
    padding: 0.1em 0.35em;
    font-size: 0.9em;
}

.summary pre {
    background: #f0f0f2;
    border-radius: 8px;
    padding: 0.75em 1em;
    overflow-x: auto;
}

.summary pre code {
    background: none;
    padding: 0;
}

.summary blockquote {
    margin: 0.6em 0;
    padding-left: 0.9em;
    border-left: 3px solid #d0d0d5;
    color: #4a4a4e;
}

.summary a {
    color: #0071e3;
}

/* ---------- Config view ---------- */

.config-header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 1.5rem;
}

.config-header h2 {
    font-size: 1.3rem;
    margin: 0;
}

.config-header .icon-btn {
    background: white;
    color: #1d1d1f;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.config-header .icon-btn:hover {
    background: #f0f0f2;
}

.config-personas {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

.config-persona-card {
    background: white;
    color: #1d1d1f;
    border-radius: 14px;
    padding: 1.25rem 1.4rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border-top: 4px solid var(--persona-color);
    text-align: left;
    width: 100%;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.config-persona-card:hover {
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

.config-persona-card.selected {
    box-shadow: 0 0 0 2px var(--persona-color), 0 3px 10px rgba(0, 0, 0, 0.12);
    background: color-mix(in srgb, var(--persona-color) 6%, white);
}

.config-persona-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.config-persona-header h3 {
    margin: 0;
    font-size: 1.05rem;
}

.config-persona-header .persona-icon {
    font-size: 1.4rem;
}

.config-placeholder {
    color: #86868b;
    font-size: 0.9rem;
    margin: 0;
}

/* ---------- Knowledge base panel ---------- */

.knowledge-panel {
    background: white;
    border-radius: 14px;
    padding: 1.4rem 1.5rem;
    margin-top: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.knowledge-panel[hidden] {
    display: none;
}

.knowledge-panel h3 {
    margin: 0 0 1rem 0;
    font-size: 1.05rem;
}

.knowledge-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.knowledge-table th {
    text-align: left;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #86868b;
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid #ececee;
}

.knowledge-table td {
    padding: 0.65rem 0.6rem;
    border-bottom: 1px solid #f0f0f2;
    font-size: 0.9rem;
    vertical-align: top;
}

.knowledge-table td:first-child {
    white-space: nowrap;
    color: #6e6e73;
}

.knowledge-table td:nth-child(2) {
    font-weight: 600;
    white-space: nowrap;
}

.upload-area {
    border-top: 1px solid #ececee;
    padding-top: 1.1rem;
}

.drop-zone {
    border: 2px dashed #d0d0d5;
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    color: #6e6e73;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.drop-zone p {
    margin: 0;
    font-size: 0.9rem;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: #0071e3;
    background: #f5f9ff;
}

.selected-file-name {
    margin-top: 0.5rem !important;
    font-weight: 600;
    color: #1d1d1f !important;
}

.upload-controls {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.9rem;
}

.upload-controls input[type="text"] {
    flex: 1 1 auto;
    padding: 0.6rem 0.8rem;
    border: 1px solid #d0d0d5;
    border-radius: 8px;
    font-size: 0.9rem;
}

#uploadStatus {
    margin-top: 0.7rem !important;
}
