/**
 * style.css — Journal app styles
 * Mobile-first responsive design optimized for iPhone.
 */

:root {
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --text: #1d1d1f;
    --text-secondary: #86868b;
    --accent: #007aff;
    --accent-hover: #0056cc;
    --border: #e5e5e7;
    --danger: #ff3b30;
    --success: #34c759;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --max-width: 680px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* ── Header / Nav ── */
.header {
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 0.5px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 12px 16px;
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.header h1 a {
    color: var(--text);
    text-decoration: none;
}

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

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    background: rgba(0,122,255,0.1);
    color: var(--accent);
}
.btn-secondary:hover { background: rgba(0,122,255,0.18); }

.btn-danger {
    background: rgba(255,59,48,0.1);
    color: var(--danger);
}
.btn-danger:hover { background: rgba(255,59,48,0.18); }

.btn-ghost {
    background: transparent;
    color: var(--accent);
    padding: 8px 10px;
}

.btn-icon {
    padding: 8px;
    min-width: 36px;
    justify-content: center;
}

.btn-fab {
    position: fixed;
    bottom: max(24px, env(safe-area-inset-bottom, 24px));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    text-decoration: none;
    border: none;
    cursor: pointer;
}
.btn-fab:hover { background: var(--accent-hover); transform: scale(1.05); }

/* ── Container ── */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 16px;
}

/* ── Timeline / Entry List ── */
.timeline-date {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 20px 0 8px;
}

.entry-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    overflow: hidden;
    transition: box-shadow 0.15s ease;
}
.entry-card:hover { box-shadow: var(--shadow-lg); }

.entry-card a {
    text-decoration: none;
    color: inherit;
    display: block;
}

.entry-card-body {
    padding: 16px;
}

.entry-card-time {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.entry-card-preview {
    font-size: 15px;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.entry-card-photos {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.entry-card-photos::-webkit-scrollbar { display: none; }

.entry-card-photos img {
    width: 100%;
    max-height: 240px;
    object-fit: cover;
    scroll-snap-align: start;
    flex-shrink: 0;
}

.entry-card-photos.multi img {
    width: 50%;
    max-height: 180px;
}

.entry-card-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 0 16px 12px;
}

.tag {
    display: inline-block;
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    background: rgba(0,122,255,0.08);
    padding: 3px 10px;
    border-radius: 20px;
}

/* ── Month Buttons ── */
.month-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}
.month-btn {
    font-size: 13px;
    padding: 4px 10px;
    position: relative;
}
.month-count {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 4px;
}

/* ── Compact Entry List ── */
.entry-list {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.month-anchor {
    scroll-margin-top: 80px;
}
.entry-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--border);
    min-height: 44px;
    box-sizing: border-box;
}
.entry-row:last-child {
    border-bottom: none;
}
.entry-row:hover, .entry-row:active {
    background: rgba(0,0,0,0.03);
}
.entry-row-date {
    font-size: 13px;
    color: var(--text-secondary);
    width: 52px;
    flex-shrink: 0;
    flex-grow: 0;
}
.entry-row-title {
    font-size: 15px;
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.entry-row-title em {
    color: var(--text-secondary);
    font-style: italic;
}
.entry-row-photos {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
    flex-grow: 0;
}

.photo-count {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 0 16px 12px;
}

/* ── Compose / Edit Form ── */
.compose-form {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group input[type="time"],
.form-group input[type="datetime-local"],
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px; /* prevents iOS zoom */
    font-family: inherit;
    color: var(--text);
    background: #fff;
    -webkit-appearance: none;
}

.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    line-height: 1.6;
    resize: vertical;
    min-height: 200px;
    background: #fff;
    -webkit-appearance: none;
}

.form-group textarea:focus,
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
}

.form-row {
    display: flex;
    gap: 12px;
}
.form-row .form-group { flex: 1; }

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: 8px;
}

/* ── Photo Upload ── */
.photo-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}
.photo-upload-area:hover,
.photo-upload-area.dragover {
    border-color: var(--accent);
    background: rgba(0,122,255,0.04);
}

.photo-upload-area input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.photo-upload-icon {
    font-size: 36px;
    margin-bottom: 8px;
    opacity: 0.4;
}

.photo-upload-text {
    font-size: 15px;
    color: var(--text-secondary);
}

.photo-upload-hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
    opacity: 0.7;
}

/* ── Photo Preview Grid (compose) ── */
.photo-previews {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-top: 12px;
}

.photo-preview {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.photo-preview img {
    width: 100%;
    display: block;
    object-fit: contain;
}

#compose-blocks {
    display: flex;
    flex-direction: column;
    gap: 0;
}
#compose-blocks .compose-text {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: inherit;
    resize: vertical;
    background: var(--card-bg);
    color: var(--text);
    min-height: 60px;
}
#compose-blocks .compose-text:focus {
    outline: none;
    border-color: var(--accent);
}
#compose-blocks .photo-preview {
    margin: 8px 0;
}

.photo-preview .remove-photo {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.photo-preview .uploading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

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

/* ── Single Entry View ── */
.entry-header {
    padding: 20px 0;
}

.entry-date {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.entry-time {
    font-size: 15px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.entry-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.entry-photos {
    display: flex;
    flex-direction: column;
}

.entry-photos img {
    width: 100%;
    display: block;
    cursor: pointer;
}

.entry-text {
    padding: 20px;
    font-size: 16px;
    line-height: 1.7;
}

.entry-text p {
    margin-bottom: 12px;
}
.entry-text p:last-child { margin-bottom: 0; }

.entry-meta {
    display: flex;
    gap: 12px;
    padding: 16px 0;
    justify-content: space-between;
    align-items: center;
}

.entry-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* ── Lightbox ── */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.lightbox.active { display: flex; }

.lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 12px));
    right: 12px;
    color: #fff;
    font-size: 32px;
    background: none;
    border: none;
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Search ── */
.search-bar {
    padding: 8px 0 4px;
}

.search-bar input {
    width: 100%;
    padding: 10px 14px 10px 36px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 16px;
    font-family: inherit;
    background: var(--card-bg);
    color: var(--text);
    -webkit-appearance: none;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 14px;
    pointer-events: none;
}

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

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

.empty-state h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

/* ── Toast Messages ── */
.toast {
    position: fixed;
    bottom: max(90px, calc(env(safe-area-inset-bottom, 20px) + 70px));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: #fff;
    padding: 12px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 150;
    pointer-events: none;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Confirm Dialog ── */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.confirm-overlay.active { display: flex; }

.confirm-dialog {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 320px;
    width: 100%;
    text-align: center;
}

.confirm-dialog h3 {
    font-size: 17px;
    margin-bottom: 8px;
}

.confirm-dialog p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ── Responsive ── */
@media (max-width: 480px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    .photo-previews {
        gap: 20px;
    }
}

/* ── User font size for text areas ── */
.form-group textarea,
.entry-text {
    font-size: var(--user-font-size, 16px);
}

/* ── Font size controls ── */
.font-size-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.font-size-controls button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.font-size-controls button:hover { border-color: var(--accent); color: var(--accent); }

.font-size-controls span {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 35px;
    text-align: center;
}

/* ── Journal Switcher ── */
.journal-switcher {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
    scrollbar-width: none;
}
.journal-switcher::-webkit-scrollbar { display: none; }

.journal-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border: 1.5px solid var(--border);
    color: var(--text-secondary);
    background: transparent;
    transition: all 0.15s ease;
}
.journal-pill:hover { border-color: var(--accent); color: var(--accent); }
.journal-pill.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.journal-pill .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.journal-manage {
    padding: 4px 10px;
    font-size: 18px;
}

/* ── Settings Panel ── */
.settings-panel {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.settings-panel h2 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }

.setting-row label {
    font-size: 15px;
    font-weight: 500;
}

.setting-row select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
}

/* ── Export Panel ── */
.export-panel {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.export-panel h2 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* ── Journal Management ── */
.journal-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.journal-card-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.journal-card-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.journal-card-title {
    font-size: 16px;
    font-weight: 600;
}

.journal-card-desc {
    font-size: 13px;
    color: var(--text-secondary);
}

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

/* ── Calendar View ── */
.cal-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
}
.cal-nav-label {
    font-size: 17px;
    font-weight: 600;
}
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px;
}
.cal-dow {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    padding-bottom: 8px;
}
.cal-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: inherit;
    position: relative;
    background: var(--bg);
    transition: background 0.15s ease;
}
.cal-cell.cal-empty {
    background: transparent;
}
.cal-cell.cal-has-entry {
    background: rgba(0, 122, 255, 0.15);
    color: var(--accent);
    font-weight: 600;
}
a.cal-cell.cal-has-entry:hover {
    background: rgba(0, 122, 255, 0.25);
}
.cal-cell.cal-today {
    box-shadow: inset 0 0 0 2px var(--accent);
}
.cal-day {
    font-size: 14px;
    line-height: 1;
}
.cal-count {
    font-size: 9px;
    color: var(--accent);
    margin-top: 2px;
}
.cal-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    padding: 16px 0;
    font-size: 13px;
    color: var(--text-secondary);
}
.cal-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}
.cal-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 4px;
}
.cal-legend-has {
    background: rgba(0, 122, 255, 0.15);
}
.cal-legend-none {
    background: var(--bg);
    border: 1px solid var(--border);
}
/* Photo indicator: a small dot in the corner of a date that has a photo. */
.cal-photo-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #34c759;
    box-shadow: 0 0 0 2px var(--bg);
}
.cal-legend-photo {
    background: #34c759;
    border-radius: 50%;
}

/* ── Dark mode: forced on ── */
html.dark-mode {
    --bg: #000000;
    --card-bg: #1c1c1e;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --border: #38383a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

html.dark-mode .header {
    background: rgba(28,28,30,0.85);
}

html.dark-mode .form-group input[type="text"],
html.dark-mode .form-group input[type="date"],
html.dark-mode .form-group input[type="time"],
html.dark-mode .form-group input[type="datetime-local"],
html.dark-mode .form-group select,
html.dark-mode .form-group textarea {
    background: #2c2c2e;
    border-color: var(--border);
}

html.dark-mode .search-bar input {
    background: var(--card-bg);
}

html.dark-mode .setting-row select {
    background: #2c2c2e;
}

/* ── Dark mode: forced off (always light) ── */
html.light-mode {
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --text: #1d1d1f;
    --text-secondary: #86868b;
    --border: #e5e5e7;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

/* ── Dark mode: auto (system preference) ── */
@media (prefers-color-scheme: dark) {
    html:not(.light-mode) {
        --bg: #000000;
        --card-bg: #1c1c1e;
        --text: #f5f5f7;
        --text-secondary: #98989d;
        --border: #38383a;
        --shadow: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
    }

    html:not(.light-mode) .header {
        background: rgba(28,28,30,0.85);
    }

    html:not(.light-mode) .form-group input[type="text"],
    html:not(.light-mode) .form-group input[type="date"],
    html:not(.light-mode) .form-group input[type="time"],
    html:not(.light-mode) .form-group input[type="datetime-local"],
    html:not(.light-mode) .form-group select,
    html:not(.light-mode) .form-group textarea {
        background: #2c2c2e;
        border-color: var(--border);
    }

    html:not(.light-mode) .search-bar input {
        background: var(--card-bg);
    }
}
