/* Brain PWA — Styles
   imPower brand: Navy #004987, Blue #0082CA, Green #93D500
*/

:root {
    --navy: #004987;
    --blue: #0082CA;
    --green: #93D500;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --danger: #ef4444;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    color: var(--text);
    background: var(--bg);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

/* ─── Header ──────────────────────────────────────────────── */

#header {
    background: var(--navy);
    color: white;
    padding: 12px 16px 0;
    flex-shrink: 0;
}

#header h1 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 10px;
}

#mode-tabs {
    display: flex;
    gap: 0;
}

.tab {
    flex: 1;
    padding: 10px 0;
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab.active {
    color: white;
    border-bottom-color: var(--green);
}

/* ─── Modes ───────────────────────────────────────────────── */

.mode {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.mode.active {
    display: flex;
}

/* ─── Capture Bar ─────────────────────────────────────────── */

#capture-bar {
    background: var(--card-bg);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#capture-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#capture-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
}

#capture-input:focus {
    outline: none;
    border-color: var(--blue);
}

#voice-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

#voice-btn.listening {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

#capture-controls {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

#category-select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--card-bg);
    color: var(--text);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

#capture-send {
    padding: 8px 20px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

#capture-send:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ─── Notes Filter ────────────────────────────────────────── */

#notes-filter {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    overflow-x: auto;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.filter-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--card-bg);
    color: var(--text-light);
    font-size: 13px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn.active {
    background: var(--navy);
    color: white;
    border-color: var(--navy);
}

/* ─── Notes List ──────────────────────────────────────────── */

#notes-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px 16px;
    -webkit-overflow-scrolling: touch;
}

.note-card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.note-card.completed {
    opacity: 0.5;
}

.note-card.completed .note-content {
    text-decoration: line-through;
}

.note-checkbox {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
    transition: all 0.2s;
}

.note-checkbox.checked {
    background: var(--green);
    border-color: var(--green);
}

.note-checkbox.checked::after {
    content: "";
    width: 8px;
    height: 5px;
    border-left: 2px solid white;
    border-bottom: 2px solid white;
    transform: rotate(-45deg);
    margin-top: -2px;
}

.note-body {
    flex: 1;
    min-width: 0;
}

.note-content {
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.note-meta {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-light);
}

.note-tag {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.note-tag.todo { background: #dbeafe; color: #1d4ed8; }
.note-tag.idea { background: #fef3c7; color: #92400e; }
.note-tag.shopping { background: #d1fae5; color: #065f46; }
.note-tag.health { background: #fce7f3; color: #9d174d; }
.note-tag.reference { background: #e0e7ff; color: #3730a3; }
.note-tag.packing { background: #f3e8ff; color: #6b21a8; }
.note-tag.log { background: #f1f5f9; color: #475569; }
.note-tag.capture { background: #f1f5f9; color: #475569; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
    font-size: 15px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

/* ─── Chat Mode ───────────────────────────────────────────── */

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.system-message {
    text-align: center;
    color: var(--text-light);
    font-size: 14px;
    padding: 20px;
}

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    margin-bottom: 8px;
    font-size: 15px;
    line-height: 1.45;
    word-wrap: break-word;
}

.chat-bubble.user {
    background: var(--blue);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
    background: var(--card-bg);
    border: 1px solid var(--border);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.chat-bubble.assistant .sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-light);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    max-width: 60px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    margin-bottom: 8px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-light);
    border-radius: 50%;
    animation: typing 1.4s infinite both;
}

.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(-4px); opacity: 1; }
}

#chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
}

#chat-input:focus {
    outline: none;
    border-color: var(--blue);
}

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

#chat-send:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ─── Health Mode ─────────────────────────────────────────── */

#health-mode {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#health-quick {
    padding: 16px;
}

#health-quick h2,
#dexcom-upload h2,
#health-notes h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
}

#health-shortcuts {
    display: flex;
    gap: 8px;
}

.health-btn {
    flex: 1;
    padding: 14px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card-bg);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.health-btn:active {
    background: var(--bg);
}

#health-input-area {
    margin-top: 12px;
}

#health-template-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#health-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    margin-bottom: 8px;
}

#health-input:focus {
    outline: none;
    border-color: var(--blue);
}

#health-send {
    padding: 8px 20px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

#health-cancel {
    padding: 8px 16px;
    background: none;
    color: var(--text-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    margin-left: 8px;
}

#dexcom-upload {
    padding: 0 16px 16px;
}

#dexcom-upload p {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 10px;
}

#dexcom-label {
    display: inline-block;
    padding: 10px 20px;
    background: var(--card-bg);
    border: 1px dashed var(--border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
}

#dexcom-label:active {
    background: var(--bg);
}

#dexcom-status {
    margin-top: 8px;
    font-size: 14px;
}

#dexcom-status.success { color: #059669; }
#dexcom-status.error { color: var(--danger); }

#health-notes {
    padding: 0 16px 16px;
}

#health-notes-list {
    /* reuses .note-card styles from main notes */
}

/* ─── Toast ───────────────────────────────────────────────── */

#toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--navy);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1000;
    transition: opacity 0.3s;
    pointer-events: none;
}

#toast.hidden {
    opacity: 0;
}

/* ─── Scrollbar ───────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 0;
}

/* ─── Edit Modal ─────────────────────────────────────────── */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 {
    font-size: 18px;
    margin-bottom: 12px;
    color: var(--navy);
}

.modal-content textarea,
.modal-content select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    margin-bottom: 8px;
    background: white;
    color: var(--text);
}

.modal-content textarea:focus,
.modal-content select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(0, 130, 202, 0.15);
}

.modal-content .form-row {
    display: flex;
    gap: 8px;
}

.modal-content .form-row select {
    flex: 1;
}

.note-edit-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 12px;
}

.modal-content .form-actions {
    display: flex;
    gap: 8px;
}

.modal-content .form-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

#edit-save {
    background: var(--green);
    color: var(--navy);
}

#edit-save:hover {
    filter: brightness(0.9);
}

#edit-cancel {
    background: var(--bg);
    color: var(--text-light);
}

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

button.danger:hover {
    filter: brightness(0.9);
}

.note-body {
    cursor: pointer;
}

/* Done toggle — visually distinct from category filters */
.filter-btn.toggle-done {
    margin-left: auto;
    border: 1px solid var(--border);
}

.filter-btn.toggle-done.active {
    background: var(--navy);
    color: white;
    border-color: var(--navy);
}

/* ─── Standalone mode padding ─────────────────────────────── */

@media (display-mode: standalone) {
    #header {
        padding-top: calc(var(--safe-top) + 12px);
    }
}
