/* NoEnemy PWA — Mobile-First Dark Theme */

:root {
    --bg: #0f0f14;
    --surface: #1a1a24;
    --surface-hover: #222233;
    --primary: #6c5ce7;
    --primary-dim: #4a3fb5;
    --secondary: #00b894;
    --text: #e8e8ed;
    --text-muted: #8888a0;
    --text-dim: #555570;
    --error: #e74c3c;
    --warning: #f39c12;
    --user-bubble: #2d1b69;
    --mediator-bubble: #1b3a2d;
    --border: #2a2a3a;
    --radius: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   Header
   ============================================================ */

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 56px;
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.3px;
}

.header-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

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

/* ============================================================
   Navigation Tabs
   ============================================================ */

.nav-tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.nav-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    text-decoration: none;
    gap: 8px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dim);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-hover);
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-small {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-icon {
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    border-radius: 50%;
}

.btn-icon:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.btn-block {
    width: 100%;
}

/* ============================================================
   Forms
   ============================================================ */

.form-group {
    margin-bottom: 16px;
}

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

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: var(--primary);
}

.form-input::placeholder {
    color: var(--text-dim);
}

.form-error {
    color: var(--error);
    font-size: 13px;
    margin-top: 6px;
}

/* ============================================================
   Auth Screens
   ============================================================ */

.auth-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
}

.auth-logo {
    font-size: 32px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 8px;
    letter-spacing: -1px;
}

.auth-tagline {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 32px;
    text-align: center;
}

.auth-form {
    width: 100%;
    max-width: 360px;
}

.auth-switch {
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

/* ============================================================
   Onboarding
   ============================================================ */

.onboard-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    overflow-y: auto;
}

.onboard-title {
    font-size: 22px;
    font-weight: 700;
    margin: 24px 0 8px;
}

.onboard-text {
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    margin-bottom: 32px;
    max-width: 360px;
    line-height: 1.6;
}

.onboard-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.onboard-card:hover {
    border-color: var(--primary);
}

.onboard-card h3 {
    font-size: 16px;
    margin-bottom: 6px;
}

.onboard-card p {
    color: var(--text-muted);
    font-size: 13px;
}

.invite-code {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    font-family: monospace;
    font-size: 18px;
    color: var(--primary);
    margin: 16px 0;
    word-break: break-all;
    user-select: all;
}

.consent-box {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin: 16px 0;
}

.consent-box h3 {
    font-size: 16px;
    margin-bottom: 12px;
}

.consent-box ul {
    list-style: disc;
    padding-left: 20px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.8;
    margin-bottom: 16px;
}

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

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.channel-tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.channel-tab {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.channel-tab.active {
    color: var(--secondary);
    border-bottom-color: var(--secondary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-user {
    align-self: flex-end;
    background: var(--user-bubble);
    border-bottom-right-radius: 4px;
}

.message-mediator {
    align-self: flex-start;
    background: var(--mediator-bubble);
    border-bottom-left-radius: 4px;
}

.message-partner {
    align-self: flex-start;
    background: #1b2a3a;
    border-bottom-left-radius: 4px;
    border-left: 3px solid #3a7bd5;
}

.message-meta {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
}

.message-system {
    align-self: center;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    border-radius: var(--radius);
    max-width: 90%;
}

.message-crisis {
    align-self: center;
    background: #3a1b1b;
    border: 1px solid var(--error);
    padding: 16px;
    border-radius: var(--radius);
    max-width: 90%;
    font-size: 14px;
    line-height: 1.6;
}

.message-warning {
    align-self: center;
    background: #3a2d1b;
    border: 1px solid var(--warning);
    color: var(--warning);
    font-size: 13px;
    text-align: center;
    border-radius: var(--radius);
    max-width: 90%;
    padding: 10px 16px;
}

.typing-indicator {
    align-self: flex-start;
    background: var(--mediator-bubble);
    padding: 12px 20px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    display: none;
}

.typing-indicator.visible {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.chat-input-area {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 10px 18px;
    color: var(--text);
    font-size: 16px;
    outline: none;
    resize: none;
    max-height: 120px;
    min-height: 44px;
    line-height: 1.4;
    font-family: inherit;
}

.chat-input:focus {
    border-color: var(--primary);
}

.chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-send:hover {
    background: var(--primary-dim);
}

.chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============================================================
   Dashboard
   ============================================================ */

.dashboard-screen {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.dash-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.dash-card h3 {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.meter-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.meter-label {
    width: 120px;
    font-size: 13px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.meter-track {
    flex: 1;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.meter-fill.conflict { background: var(--error); }
.meter-fill.trust { background: var(--secondary); }
.meter-fill.communication { background: var(--primary); }

.meter-value {
    width: 40px;
    text-align: right;
    font-size: 13px;
    color: var(--text-dim);
}

.insight-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.insight-item:last-child {
    border-bottom: none;
}

.insight-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    margin-right: 8px;
    font-weight: 600;
}

.insight-tag.conflict { background: #3a1b1b; color: var(--error); }
.insight-tag.resolution { background: #1b3a2d; color: var(--secondary); }
.insight-tag.pattern { background: #2d1b69; color: var(--primary); }
.insight-tag.goal { background: #3a2d1b; color: var(--warning); }

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-box {
    text-align: center;
    padding: 12px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.dash-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

/* ============================================================
   Empty States & Loading
   ============================================================ */

.empty-state {
    text-align: center;
    padding: 40px 24px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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

.settings-screen {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section h3 {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.settings-item:hover {
    background: var(--surface-hover);
}

/* ============================================================
   Toast Notifications
   ============================================================ */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.visible {
    opacity: 1;
}

.toast.error {
    border-color: var(--error);
    color: var(--error);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (min-width: 600px) {
    .auth-screen, .onboard-screen {
        padding: 48px;
    }

    .message {
        max-width: 65%;
    }

    .chat-input-area {
        padding: 16px 24px;
    }

    .dashboard-screen, .settings-screen {
        max-width: 600px;
        margin: 0 auto;
    }
}

/* Safe area insets for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .chat-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}
