/* =============================================================================
   Conversation UI - three-panel layout, mobile-friendly
   ============================================================================= */

.conversation-layout {
    display: grid;
    grid-template-columns: 240px 1fr 320px;
    gap: 0;
    height: calc(100vh - 60px);
    margin: -2rem;          /* break out of main padding */
    background: var(--bg);
    overflow: hidden;
}

.threads-pane,
.state-pane {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.state-pane { border-right: none; border-left: 1px solid var(--border); }

.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.pane-header h3, .pane-header h2 { margin: 0; font-size: 0.95rem; }
.pane-header h2 { font-size: 1.05rem; }

/* Threads sidebar */
.thread-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}
.thread-item {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: background 0.1s;
}
.thread-item:hover { background: var(--bg); }
.thread-item.active { background: var(--bg); border-left: 3px solid var(--accent); padding-left: calc(1rem - 3px); }
.thread-title { font-weight: 500; font-size: 0.9rem; }
.thread-time { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.125rem; }

.new-thread {
    border-top: 1px solid var(--border);
    padding: 0.75rem 1rem;
}
.new-thread summary { cursor: pointer; font-size: 0.875rem; color: var(--accent); }
.new-thread form { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }

/* Messages pane */
.messages-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.message {
    margin-bottom: 1.5rem;
    max-width: 720px;
}
.message-user { margin-left: auto; }
.message-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    display: flex;
    gap: 0.5rem;
}
.message-user .message-meta { justify-content: flex-end; }
.message-role { font-weight: 600; }

.message-body {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    line-height: 1.5;
}
.message-user .message-body {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.message-body p { margin: 0 0 0.75rem 0; }
.message-body p:last-child { margin-bottom: 0; }
.message-body code {
    background: rgba(0,0,0,0.05);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 0.875em;
}

/* Proposal cards in message stream */
.message-proposals {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.proposal-card {
    background: #fff8e8;
    border: 1px solid #d6a55c;
    border-radius: 8px;
    padding: 0.75rem 1rem;
}
.proposal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.proposal-payload summary { cursor: pointer; font-size: 0.8rem; color: var(--text-muted); }
.proposal-payload pre {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem;
    font-size: 0.75rem;
    overflow-x: auto;
    margin-top: 0.5rem;
}
.proposal-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* Inline error on a proposal card after a failed approval. Status stays
   Pending so the card remains visible; the button label changes to Retry. */
.proposal-error {
    background: #fce7e7;
    border: 1px solid #c66;
    border-left: 4px solid #c66;
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #722;
}
.proposal-error strong { display: block; margin-bottom: 0.25rem; }
.proposal-error p { margin: 0; white-space: pre-wrap; }

/* Directive parse-failure warning. Same warm palette as proposal cards but
   with no actions — purely informational. */
.message-warning {
    background: #fff8e8;
    border: 1px solid #d6a55c;
    border-left: 4px solid #d6a55c;
    border-radius: 8px;
    padding: 0.625rem 0.875rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: #5c4515;
}
.message-warning strong { display: block; margin-bottom: 0.25rem; }
.message-warning p { margin: 0 0 0.25rem 0; }
.warning-details summary { cursor: pointer; font-size: 0.8rem; color: #806328; }
.warning-details ul { margin: 0.25rem 0 0 1.25rem; padding: 0; font-size: 0.8rem; }
.warning-details code { background: rgba(0,0,0,0.06); padding: 0 0.25rem; border-radius: 3px; }

/* Composer */
.composer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
/* font-size 16px keeps iOS Safari from zooming in on focus. */
.composer-input { resize: vertical; min-height: 60px; max-height: 200px; font-size: 16px; }
.composer-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

.composer-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.composer-attachments:empty {
    display: none;
}
.composer-attachment {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg);
    border: 1px solid var(--border);
    flex: 0 0 auto;
}
.composer-attachment img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.composer-attachment-uploading {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.composer-attachment-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.composer-attachment-remove:hover {
    background: rgba(0,0,0,0.8);
}

/* State pane */
.state-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}
.state-section h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.state-section p { margin: 0.25rem 0; font-size: 0.875rem; }

.decision-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
}
.decision-item summary { cursor: pointer; font-size: 0.8rem; }
.decision-item pre {
    background: var(--surface);
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    overflow-x: auto;
    margin-top: 0.5rem;
    max-height: 200px;
}

/* =============================================================================
   Mobile responsive
   ============================================================================= */

.panel-toggle, .panel-close { display: none; }

@@media (max-width: 900px) {
    .conversation-layout {
        grid-template-columns: 1fr;
        height: calc(100vh - 60px);
    }
    .threads-pane {
        position: fixed;
        left: -260px;
        top: 60px;
        bottom: 0;
        width: 240px;
        z-index: 10;
        transition: left 0.2s;
        border-right: 1px solid var(--border);
    }
    .state-pane {
        position: fixed;
        right: -340px;
        top: 60px;
        bottom: 0;
        width: 320px;
        z-index: 10;
        transition: right 0.2s;
        border-left: 1px solid var(--border);
    }
    body.panel-threads-open .threads-pane { left: 0; }
    body.panel-state-open .state-pane { right: 0; }

    .panel-toggle { display: inline-block; }
    .panel-close { display: inline-block; }

    .message { max-width: 100%; }

    /* 44×44 touch targets per Apple HIG — applied to controls Kristi taps on iPhone. */
    .composer .btn,
    .proposal-actions .btn { min-height: 44px; }
    .composer-attachment-remove { width: 28px; height: 28px; font-size: 18px; }
    .panel-toggle, .panel-close { min-height: 36px; }
}

/* =============================================================================
   Auth pages
   ============================================================================= */

.auth-card {
    max-width: 420px;
    margin: 4rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
}
.auth-card h1 { margin-top: 0; }
.auth-intro { color: var(--text-muted); margin-bottom: 1.5rem; }

/* =============================================================================
   Settings pages
   ============================================================================= */

.settings-intro {
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

.settings-list { display: flex; flex-direction: column; gap: 1rem; }

.setting-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
}
.setting-header { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }
.setting-header h3 { margin: 0; font-family: 'Menlo', 'Consolas', monospace; font-size: 0.95rem; }

.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
}
.badge-encrypted { background: #efe9d9; color: #8b6f1c; }
.badge-set { background: #d9e9d9; color: var(--success); }
.badge-unset { background: #f5e0e0; color: var(--error); }

.setting-description { color: var(--text-muted); font-size: 0.875rem; margin: 0 0 0.5rem 0; }
.setting-current { font-size: 0.875rem; margin-bottom: 0.75rem; }
.setting-form { display: flex; gap: 0.5rem; }
.setting-form .form-control { flex: 1; }

.create-user-block { margin-bottom: 1.5rem; }
.create-user-block summary { cursor: pointer; padding: 0.5rem 0; font-weight: 500; }
.create-user-block .form { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 1rem; margin-top: 0.5rem; }

.actions-cell { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.action-details summary { cursor: pointer; color: var(--accent); font-size: 0.875rem; }
.action-details .inline-form { margin-top: 0.5rem; }

/* Header additions */
.nav-spacer { flex: 1; }
.nav-user { color: var(--text-muted); font-size: 0.875rem; }
.link-button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0;
}
.link-button:hover { color: var(--accent); }

/* =============================================================================
   Locked-decision partials in the State sidebar
   ============================================================================= */

.decision-summary p { margin: 0 0 0.5rem 0; font-size: 0.875rem; }
.decision-summary p:last-child { margin-bottom: 0; }

.decision-list {
    margin: 0.25rem 0;
    padding-left: 1.25rem;
    font-size: 0.85rem;
}
.decision-list li { padding: 0.05rem 0; }

.decision-list-compact {
    list-style: none;
    margin: 0.25rem 0 0.5rem 0;
    padding: 0;
    font-size: 0.8rem;
}
.decision-list-compact li {
    display: flex;
    justify-content: space-between;
    padding: 0.125rem 0;
    border-bottom: 1px dotted var(--border);
}
.decision-list-compact li:last-child { border-bottom: none; }
.decision-count {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.decision-link a {
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
}
.decision-link a:hover { text-decoration: underline; }

.decision-empty { color: var(--text-muted); font-style: italic; font-size: 0.8rem; margin: 0.25rem 0; }

.decision-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    margin: 0.25rem 0;
}
.decision-table th,
.decision-table td {
    padding: 0.25rem 0.4rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.decision-table th { color: var(--text-muted); font-weight: 600; }
.decision-table td.num,
.decision-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* =============================================================================
   Streaming "Claude is thinking…" indicator
   ============================================================================= */

.thinking-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    height: 1.2em;
}
.thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    opacity: 0.4;
    animation: thinking-pulse 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.30s; }

@keyframes thinking-pulse {
    0%, 80%, 100% { opacity: 0.4; transform: scale(0.85); }
    40%           { opacity: 1;   transform: scale(1.0); }
}

/* =============================================================================
   Composer model selector — left of the Attach/Send buttons.
   ============================================================================= */

.composer-model {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-right: auto;       /* push the rest of the row to the right */
    font-size: 0.85rem;
    color: var(--text-muted);
}
.composer-model-label {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.7rem;
}
.composer-model-select {
    padding: 0.25rem 0.4rem;
    font-size: 0.85rem;
    height: auto;
    width: auto;
    min-width: 130px;
}
