/* ══════════════════════════════════════════════════════════════════
   CSS VARIABLES
   ══════════════════════════════════════════════════════════════════ */
:root {
    --bg: #ffffff;
    --text: #1a1a1a;
    --text-muted: #888;
    --border: #e0e0e0;
    --today-bg: #fffbe6;
    --hover-bg: #f8f8f8;
    --weekend-color: #999;

    --cell-height: 80px;
    --header-height: 36px;
    --year-col-width: 28px;
    --month-col-width: 28px;
}

/* ══════════════════════════════════════════════════════════════════
   RESET & BASE
   ══════════════════════════════════════════════════════════════════ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* ══════════════════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════════════════ */
.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: margin-left 0.3s ease, margin-right 0.3s ease;
}

/* ══════════════════════════════════════════════════════════════════
   STICKY HEADER
   ══════════════════════════════════════════════════════════════════ */
.header {
    display: grid;
    /* Logo | Arrow | 7 day columns */
    grid-template-columns: var(--year-col-width) var(--month-col-width) repeat(7, 1fr);
    height: var(--header-height);
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

/* Logo cell - fill entirely */
.header-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 0;
    overflow: hidden;
}

.logo-img {
    height: 100%;
    width: 100%;
    object-fit: contain;
}

/* Arrow button cell - fill entirely */
.header-arrow {
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    border-right: 1px solid var(--border);
    background: var(--bg);
}

/* Inline scroll button - fills cell */
.scroll-btn-inline {
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.15s ease, color 0.15s ease;
}

.scroll-btn-inline.visible {
    opacity: 1;
}

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

.header-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text);
    border-right: 1px solid var(--border);
}

.header-cell:last-child {
    border-right: none;
}

/* ══════════════════════════════════════════════════════════════════
   SCROLLABLE CALENDAR BODY
   ══════════════════════════════════════════════════════════════════ */
.calendar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.calendar {
    display: grid;
    grid-template-columns: var(--year-col-width) var(--month-col-width) repeat(7, 1fr);
    grid-auto-rows: var(--cell-height);
}

/* ══════════════════════════════════════════════════════════════════
   YEAR LABEL CELLS (spanning full year, JS-positioned text)
   ══════════════════════════════════════════════════════════════════ */
.year-cell {
    position: relative;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    border-right: none;
    background: var(--bg);
    color: var(--text);
    overflow: visible;
}

/* Inner span - positioned by JavaScript on scroll */
.year-cell span {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

/* ══════════════════════════════════════════════════════════════════
   MONTH LABEL CELLS (spanning full month)
   ══════════════════════════════════════════════════════════════════ */
.month-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    border-right: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}

/* ══════════════════════════════════════════════════════════════════
   DAY CELLS
   ══════════════════════════════════════════════════════════════════ */
.day {
    position: relative;
    min-height: var(--cell-height);
    padding: 6px 8px;
    border-right: 1px dashed var(--border);
    border-bottom: 1px dashed var(--border);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    /* Align content to the right */
    transition: background 0.15s ease;
}

.day:hover {
    background: var(--hover-bg);
}

.day::before {
    content: '+';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: 300;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

.day:hover::before {
    opacity: 0.4;
}

.day.today {
    background: var(--today-bg);
}

.day.today .date-num {
    font-weight: 700;
    color: #c99700;
}

/* Month boundary borders - thicker lines */
.day.bt {
    border-top: 2px solid var(--border);
}

.day.bb {
    border-bottom: 1px solid var(--border);
}

.day.bl {
    border-left: 1px solid var(--border);
}

.day.br {
    border-right: 1px solid var(--border);
}

/* Date number - TOP RIGHT */
.date-num {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    text-align: right;
}

.day.weekend .date-num {
    color: var(--weekend-color);
}

/* Day Category Icons */
.day-items {
    position: absolute;
    bottom: 4px;
    left: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-width: calc(100% - 8px);
}

.day-item-icon {
    font-size: 14px;
    line-height: 1;
}

.day-item-more {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 700;
    line-height: 14px;
    display: flex;
    align-items: center;
}

/* ══════════════════════════════════════════════════════════════════
   SCROLL TO TODAY BUTTON
   ══════════════════════════════════════════════════════════════════ */
/* Old floating scroll button - kept for fallback but hidden */
.scroll-btn {
    display: none;
}

/* ══════════════════════════════════════════════════════════════════
   LOADING STATE
   ══════════════════════════════════════════════════════════════════ */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: var(--text-muted);
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root {
        --cell-height: 60px;
        --year-col-width: 22px;
        --month-col-width: 22px;
        --header-height: 32px;
    }

    .month-cell,
    .year-cell {
        font-size: 8px;
    }

    .date-num {
        font-size: 11px;
    }

    .scroll-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
        bottom: 16px;
        right: 16px;
    }

    .header-cell {
        font-size: 9px;
    }
}

/* ══════════════════════════════════════════════════════════════════
   IFRAME EMBEDDING OPTIMIZATION
   ══════════════════════════════════════════════════════════════════ */
@media (max-height: 500px) {
    :root {
        --cell-height: 50px;
        --header-height: 28px;
    }
}

/* ══════════════════════════════════════════════════════════════════
   LEFT SIDEBAR NAVIGATION
   ══════════════════════════════════════════════════════════════════ */
.sidebar-nav {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 48px;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    gap: 8px;
    z-index: 500;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.sidebar-nav.active {
    transform: translateX(0);
}

.nav-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.15s ease;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

.nav-btn.active {
    background: var(--primary);
}

.nav-spacer {
    flex: 1;
}

.nav-donate {
    color: #ff6b6b;
}

/* Shift app when sidebar is open */
body.sidebar-open .app {
    margin-left: 48px;
}

/* Shift app when right panel is open */
body.panel-open .app {
    margin-right: 320px;
}

/* ══════════════════════════════════════════════════════════════════
   RIGHT PANEL (POST-IT + AI CHAT)
   ══════════════════════════════════════════════════════════════════ */
.panel-toggle {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 60px;
    border: none;
    border-radius: 8px 0 0 8px;
    background: #1a1a2e;
    color: white;
    font-size: 14px;
    cursor: pointer;
    z-index: 400;
    transition: right 0.3s ease, background 0.2s ease;
}

.panel-toggle:hover {
    background: var(--primary);
}

.panel-toggle.open {
    right: 320px;
}

.panel-toggle.open::after {
    content: '›';
}

.right-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    background: #fafafa;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 300;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.right-panel.open {
    transform: translateX(0);
}

.panel-section {
    display: flex;
    flex-direction: column;
    padding: 12px;
}

.panel-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Post-it section - top 1/3 */
.panel-postit {
    flex: 1;
    max-height: 33%;
    border-bottom: 1px solid var(--border);
}

.postit-area {
    flex: 1;
    border: none;
    background: #fff9c4;
    border-radius: 4px;
    padding: 10px;
    font-family: inherit;
    font-size: 13px;
    resize: none;
    outline: none;
}

/* AI Chat section - bottom 2/3 */
.panel-chat {
    flex: 2;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0;
}

.chat-msg {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    max-width: 85%;
}

.chat-msg.user {
    background: transparent;
    color: var(--text);
    align-self: flex-end;
    border: 1.5px solid var(--text);
}

.chat-msg.assistant {
    background: #e8e8e8;
    color: var(--text);
    align-self: flex-start;
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    outline: none;
}

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

.chat-send {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.chat-send:hover {
    transform: scale(1.1);
}

/* ══════════════════════════════════════════════════════════════════
   DAY POPUP OVERLAY WITH CATEGORY WHEEL
   ══════════════════════════════════════════════════════════════════ */
.day-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.day-popup-overlay.active {
    display: flex;
}

.day-popup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.day-popup-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: popIn 0.25s ease;
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.popup-date {
    background: white;
    padding: 20px 40px;
    border-radius: 12px;
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* Category wheel - circular layout */
.category-wheel {
    position: relative;
    width: 280px;
    height: 280px;
}

.category-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 70px;
    height: 70px;
    margin-left: -35px;
    margin-top: -35px;
    border: none;
    border-radius: 50%;
    background: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    /* Position in circle using CSS custom property --i (0-5) */
    transform: rotate(calc(var(--i) * 60deg)) translateY(-100px) rotate(calc(var(--i) * -60deg));
}

.category-btn span {
    font-size: 9px;
    font-weight: 600;
    color: var(--text);
    margin-top: 2px;
    text-transform: uppercase;
}

.category-btn:hover {
    transform: rotate(calc(var(--i) * 60deg)) translateY(-100px) rotate(calc(var(--i) * -60deg)) scale(1.15);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* Category colors on hover */
.category-btn[data-category="journal"]:hover {
    background: #e1bee7;
}

.category-btn[data-category="study"]:hover {
    background: #bbdefb;
}

.category-btn[data-category="sport"]:hover {
    background: #c8e6c9;
}

.category-btn[data-category="food"]:hover {
    background: #ffe0b2;
}

.category-btn[data-category="admin"]:hover {
    background: #cfd8dc;
}

.category-btn[data-category="social"]:hover {
    background: #f8bbd9;
}

/* ══════════════════════════════════════════════════════════════════
   SUB-OPTIONS PANEL
   ══════════════════════════════════════════════════════════════════ */
.sub-options {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    animation: fadeIn 0.2s ease;
}

.sub-options.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.back-btn {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    border: none;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.back-btn:hover {
    background: white;
}

.sub-options-title {
    font-size: 14px;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
}

.sub-options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.sub-option-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 90px;
    height: 80px;
    border: none;
    border-radius: 12px;
    background: white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sub-option-btn span {
    font-size: 10px;
    font-weight: 600;
    color: var(--text);
    margin-top: 4px;
}

.sub-option-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* Sub-option colors by category */
.sub-option-btn[data-category="journal"]:hover {
    background: #e1bee7;
}

.sub-option-btn[data-category="study"]:hover {
    background: #bbdefb;
}

.sub-option-btn[data-category="sport"]:hover {
    background: #c8e6c9;
}

.sub-option-btn[data-category="food"]:hover {
    background: #ffe0b2;
}

.sub-option-btn[data-category="admin"]:hover {
    background: #cfd8dc;
}

/* ══════════════════════════════════════════════════════════════════
   SOCIAL COMPOSER
   ══════════════════════════════════════════════════════════════════ */
.social-composer {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: white;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 300px;
    animation: fadeIn 0.2s ease;
}

.social-composer.active {
    display: flex;
}

.composer-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}

.composer-input,
.composer-tags {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}

.composer-input:focus,
.composer-tags:focus {
    border-color: var(--primary);
}

.composer-tags {
    color: var(--primary);
}

.composer-submit {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.composer-submit:hover {
    transform: scale(1.02);
}

/* Hide category wheel when sub-options active */
.category-wheel.hidden {
    display: none;
}

/* ══════════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ══════════════════════════════════════════════════════════════════ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 2000;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 1.7s forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* ══════════════════════════════════════════════════════════════════
   STATS VIEW
   ══════════════════════════════════════════════════════════════════ */
.stats-view {
    display: none;
    flex-direction: column;
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.stats-view.active {
    display: flex;
}

.stats-header {
    margin-bottom: 24px;
}

.stats-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
}

.stats-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin: 4px 0 0 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.stats-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.stats-card-wide {
    grid-column: span 2;
}

.stats-card h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 16px 0;
}

/* Category bars */
.category-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.category-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.category-bar-label {
    width: 70px;
    font-size: 12px;
    font-weight: 500;
}

.category-bar-track {
    flex: 1;
    height: 8px;
    background: #eee;
    border-radius: 4px;
    overflow: hidden;
}

.category-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.category-bar-count {
    width: 30px;
    font-size: 12px;
    font-weight: 600;
    text-align: right;
}

/* Activity heatmap */
.activity-heatmap {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.heatmap-cell {
    aspect-ratio: 1;
    border-radius: 3px;
    background: #eee;
}

.heatmap-cell[data-count="1"] {
    background: #c8e6c9;
}

.heatmap-cell[data-count="2"] {
    background: #81c784;
}

.heatmap-cell[data-count="3"] {
    background: #4caf50;
}

.heatmap-cell[data-count="4"] {
    background: #388e3c;
}

.heatmap-cell[data-count="5+"] {
    background: #1b5e20;
}

/* Recent activities list */
.recent-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.recent-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: #f8f8f8;
    border-radius: 8px;
    font-size: 13px;
}

.recent-item-icon {
    font-size: 20px;
}

.recent-item-text {
    flex: 1;
}

.recent-item-date {
    color: var(--text-muted);
    font-size: 11px;
}

/* Hide calendar when viewing stats */
.calendar-scroll.hidden {
    display: none;
}

.header.hidden {
    display: none;
}