/* frontend-user/css/notes.css */

/* ===== ROOT VARIABLES (MedHub Unified) ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-dark: #cbd5e1;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --header-height: clamp(60px, 10vh, 80px);
}

body.dark-theme {
    --bg-primary: #0b1120;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border: #334155;
    --border-dark: #475569;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== HEADER ===== */
.notes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1.5rem;
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.hamburger {
    font-size: 1.6rem;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-secondary);
    transition: color 0.2s;
}
.hamburger:hover {
    color: var(--primary);
}

.page-title {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-right a,
.header-right button {
    background: none;
    border: none;
    font-size: 0.9rem;
    padding: 0.4rem 0.6rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    font-weight: 500;
    cursor: pointer;
}

.header-right a:hover,
.header-right button:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* ===== HISTORY PANEL ===== */
.history-panel {
    position: fixed;
    top: 0;
    left: -320px;
    width: 300px;
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transition: left 0.3s ease;
    z-index: 1000;
    padding: 1.5rem;
    overflow-y: auto;
}

.history-panel.open {
    left: 0;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.history-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.close-history {
    font-size: 1.6rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem;
}
.close-history:hover {
    color: var(--text-primary);
}

.history-item {
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:hover {
    background: var(--border);
}

.history-item .date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}

.history-item .title {
    font-weight: 500;
}

/* ===== DASHBOARD ===== */
#dashboard-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* ===== TOOLBAR ===== */
.notes-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.filter-tabs {
    display: flex;
    gap: 0.5rem;
}

.filter-tab {
    padding: 0.4rem 1rem;
    border-radius: 30px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    min-height: 36px;
}

.filter-tab:hover {
    background: var(--bg-secondary);
}

.filter-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

#searchNotes {
    padding: 0.4rem 1rem;
    border-radius: 30px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    width: 200px;
    font-family: inherit;
    font-size: 0.85rem;
    min-height: 36px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#searchNotes:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ===== NOTE GRID – FLEXBOX WRAP (Foolproof, no overlaps, zero lost cards) ===== */
.note-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;               /* Handles both horizontal & vertical gaps */
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    align-content: flex-start;  /* Ensures cards pack to the top of the container */
}

/* ===== NOTE CARD – Maintains aspect ratio & height perfectly ===== */
.note-card {
    flex: 1 1 200px;            /* Base width 200px, grows/shrinks to fit available space */
    min-width: 150px;           /* Prevents cards from being crushed on small screens */
    max-width: 100%;            /* Ensures a card never exceeds its parent width */

    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.2s;
    aspect-ratio: 1 / 1.45;     /* Keeps the ratio you love */
    min-height: 140px;
    max-height: 320px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    position: relative;
    overflow: hidden;
    contain: layout style paint;
}

.note-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--primary-light);
}

.note-card:active {
    transform: scale(0.97);
}

/* Title – single line with ellipsis */
.card-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    color: var(--text-primary);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-title .lock-icon {
    font-size: 0.8rem;
    margin-right: 0.3rem;
}

.card-title .card-menu {
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.3rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all 0.2s;
    min-width: 36px;
    text-align: center;
    flex-shrink: 0;
    margin-top: -0.2rem;
    line-height: 1;
}

.card-title .card-menu:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Body – clamped and wraps safely */
.card-body {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    overflow: hidden;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

/* Date – pinned to bottom */
.card-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 0.6rem;
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
    flex-shrink: 0;
}

/* ===== FAB ===== */
.fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    border: none;
    cursor: pointer;
    z-index: 100;
    transition: all 0.2s;
}

.fab:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

/* ===== EDITOR VIEW ===== */
#editor-view {
    display: none;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
}

.edit-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.edit-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.back-btn {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
}
.back-btn:hover {
    color: var(--text-primary);
}

.edit-header-right {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.tool-icon {
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
    min-width: 36px;
    text-align: center;
}

.tool-icon:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.save-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.4rem 1.2rem;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 36px;
}

.save-btn:hover {
    background: var(--primary-dark);
}

.edit-body {
    flex: 1;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#noteTitle {
    background: transparent;
    border: none;
    font-size: 1.6rem;
    font-weight: 600;
    outline: none;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
    width: 100%;
}

#noteTitle::placeholder {
    color: var(--text-muted);
}

.date-line {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

/* ===== QUILL EDITOR ===== */
#noteContent {
    flex: 1;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.ql-toolbar.ql-snow {
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    border-radius: var(--radius) var(--radius) 0 0;
}

.ql-container.ql-snow {
    border: 1px solid var(--border);
    border-top: none;
    background: var(--bg-card);
    border-radius: 0 0 var(--radius) var(--radius);
    font-size: 1rem;
}

.ql-editor {
    min-height: 200px;
    color: var(--text-primary);
}

/* ===== CONTEXT MENU ===== */
#note-context-menu,
#editor-context-menu {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 0.25rem 0;
    min-width: 160px;
    max-width: 220px;
    overflow: hidden;
}

.context-item {
    padding: 0.5rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: background 0.15s;
}

.context-item:hover {
    background: var(--bg-secondary);
}

/* ===== SHARE MODAL ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1.5rem;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 460px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalSlideUp 0.25s ease;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    color: var(--text-secondary);
}

#share-link-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: monospace;
}

#share-qr-code {
    display: inline-block;
    background: white;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

#share-qr-code canvas {
    display: block;
    width: 120px;
    height: 120px;
}

/* ===== BUTTONS FOR DYNAMIC PROMPTS ===== */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.4rem 1.2rem;
    border-radius: 30px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover {
    background: var(--primary-dark);
}
.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 0.4rem 1.2rem;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--border-dark);
}

/* ===== DARK THEME – Quill overrides ===== */
body.dark-theme .ql-toolbar.ql-snow {
    background: var(--bg-secondary);
    border-color: var(--border);
}
body.dark-theme .ql-container.ql-snow {
    background: var(--bg-card);
    border-color: var(--border);
}
body.dark-theme .ql-stroke {
    stroke: var(--text-primary);
}
body.dark-theme .ql-fill {
    fill: var(--text-primary);
}
body.dark-theme .ql-picker {
    color: var(--text-primary);
}
body.dark-theme .ql-picker-options {
    background: var(--bg-card);
    border-color: var(--border);
}
body.dark-theme .ql-snow .ql-picker-label {
    color: var(--text-primary);
}
body.dark-theme .ql-snow .ql-picker-label:hover,
body.dark-theme .ql-snow .ql-picker-item:hover {
    background: var(--bg-secondary);
}
body.dark-theme .ql-snow .ql-tooltip {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border);
}

/* ===== ACCESSIBILITY – Keyboard focus ===== */
.hamburger:focus-visible,
.back-btn:focus-visible,
.filter-tab:focus-visible,
.tool-icon:focus-visible,
.card-menu:focus-visible,
.context-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ===== UTILITY ===== */
.no-data {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem;
    font-style: italic;
    width: 100%;
}

.history-empty,
.history-error {
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 0.5rem 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
    .notes-header {
        padding: 0.5rem 1rem;
    }
    .page-title {
        font-size: 1.1rem;
    }
    .header-right a,
    .header-right button {
        font-size: 0.8rem;
        padding: 0.3rem 0.4rem;
    }
    .notes-toolbar {
        padding: 0.5rem 1rem;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .filter-tabs {
        justify-content: center;
    }
    #searchNotes {
        width: 100%;
    }
    .note-grid {
        gap: 0.75rem;
        padding: 0.75rem;
    }
    .note-card {
        flex: 1 1 150px;        /* Shrinks base width on mobile */
        min-width: 120px;
        padding: 0.75rem;
        min-height: 120px;
        max-height: 240px;
    }
    .card-title {
        font-size: 0.9rem;
    }
    .card-body {
        font-size: 0.8rem;
        -webkit-line-clamp: 3;
    }
    .fab {
        bottom: 1.25rem;
        right: 1.25rem;
        width: 48px;
        height: 48px;
        font-size: 1.6rem;
    }
    .edit-header {
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .edit-header-right {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    .edit-body {
        padding: 1rem;
    }
    #noteTitle {
        font-size: 1.3rem;
    }
    .modal {
        padding: 1rem;
        margin: 0.5rem;
    }
}

/* Smartwatch / ultra-small screens */
@media (max-width: 380px) {
    .note-card {
        flex: 1 1 100%;         /* Forces a single column on very tiny screens */
        min-width: 100%;
        min-height: 160px;
        max-height: 240px;
    }
}

@media (min-width: 641px) and (max-width: 1023px) {
    .note-card {
        flex: 1 1 220px;
        min-height: 160px;
    }
}

@media (min-width: 1024px) {
    .note-grid {
        gap: 1.5rem;
        padding: 1.5rem;
    }
    .note-card {
        flex: 1 1 260px;
        padding: 1.5rem;
        min-height: 200px;
    }
    .card-body {
        -webkit-line-clamp: 5;
    }
}