:root {
    --background: #03070d;
    --background-secondary: #07111d;

    --panel: rgba(8, 24, 42, 0.94);
    --panel-light: rgba(15, 41, 68, 0.94);
    --panel-hover: rgba(22, 58, 94, 0.95);

    --accent: #37b9ff;
    --accent-bright: #8de8ff;
    --accent-dark: #147fca;

    --text-primary: #f4fbff;
    --text-secondary: #a9c8dc;
    --text-muted: #668398;

    --success: #40f59b;
    --warning: #ffd664;
    --danger: #ff5967;

    --white-line: rgba(255, 255, 255, 0.78);
    --soft-white-line: rgba(255, 255, 255, 0.22);

    --border: rgba(55, 185, 255, 0.58);
    --border-bright: rgba(141, 232, 255, 0.92);

    --glow-small: 0 0 8px rgba(55, 185, 255, 0.35);
    --glow-medium: 0 0 18px rgba(55, 185, 255, 0.42);
    --glow-large: 0 0 32px rgba(55, 185, 255, 0.28);

    --navbar-height: clamp(54px, 7vh, 72px);
    --chat-row-height: clamp(82px, 11vh, 104px);
    --chat-button-size: clamp(72px, 9vh, 88px);
}

/* =========================================================
   RESET AND VIEWPORT
   ========================================================= */

* {
    box-sizing: border-box;
}

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

body {
    display: grid;
    grid-template-rows:
        var(--navbar-height)
        minmax(0, 1fr)
        var(--chat-row-height);

    color: var(--text-primary);

    font-family:
        Arial,
        Helvetica,
        sans-serif;

    background:
        radial-gradient(
            circle at 50% 0%,
            rgba(23, 117, 185, 0.17),
            transparent 42%
        ),
        linear-gradient(
            180deg,
            var(--background-secondary),
            var(--background)
        );
}

button,
input {
    font: inherit;
}

button {
    color: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

/* =========================================================
   HEADER AND NAVBAR
   ========================================================= */

header {
    position: relative;
    z-index: 1000;

    min-width: 0;
    min-height: 0;
}

.navbar {
    display: flex;
    align-items: stretch;
    justify-content: space-between;

    width: 100%;
    height: 100%;
    min-height: 0;

    padding: 0 clamp(6px, 1vw, 20px);

    background: rgba(3, 11, 20, 0.98);

    border-bottom: 1px solid var(--border);

    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.5),
        0 0 18px rgba(55, 185, 255, 0.13);

    backdrop-filter: blur(12px);
}

/* =========================================================
   NAVIGATION
   ========================================================= */

.nav-left {
    display: flex;
    align-items: stretch;

    min-width: 0;
    height: 100%;

    overflow-x: auto;
    overflow-y: hidden;

    scrollbar-width: none;
}

.nav-left::-webkit-scrollbar {
    display: none;
}

.nav-item {
    position: relative;

    display: flex;
    align-items: stretch;

    min-height: 0;

    flex-shrink: 0;

    color: var(--text-secondary);

    transition:
        color 0.2s ease,
        background 0.2s ease,
        box-shadow 0.2s ease;
}

.nav-item + .nav-item {
    border-left: 1px solid var(--white-line);
}

.nav-item:last-child {
    border-right: 1px solid var(--white-line);
}

.nav-item a {
    display: flex;
    align-items: center;
    justify-content: center;

    height: 100%;
    min-height: 0;

    padding: 0 clamp(6px, 0.82vw, 17px);

    font-size: clamp(0.54rem, 0.68vw, 0.76rem);
    font-weight: 700;
    letter-spacing: clamp(0.03em, 0.06vw, 0.08em);
    text-transform: uppercase;
    white-space: nowrap;
}

.nav-item::after {
    content: "";

    position: absolute;
    bottom: 0;
    left: 50%;

    width: 0;
    height: 2px;

    background: var(--accent-bright);

    box-shadow:
        0 0 7px rgba(141, 232, 255, 0.9),
        0 0 14px rgba(55, 185, 255, 0.6);

    transform: translateX(-50%);

    transition: width 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
    color: var(--text-primary);

    background: rgba(55, 185, 255, 0.11);

    box-shadow:
        inset 0 0 20px rgba(55, 185, 255, 0.08);
}

.nav-item:hover::after,
.nav-item.active::after {
    width: calc(100% - 24px);
}

/* =========================================================
   NAV ACTIONS
   ========================================================= */

.nav-actions {
    display: flex;
    align-items: stretch;

    flex-shrink: 0;

    height: 100%;

    background: rgba(3, 11, 20, 0.98);
}

.nav-icon-button {
    position: relative;

    display: flex;
    align-items: center;
    justify-content: center;

    width: clamp(42px, 3.4vw, 58px);
    height: 100%;
    min-height: 0;
    padding: 0;

    color: var(--accent-bright);
    background: transparent;

    border: 0;
    border-left: 1px solid var(--white-line);

    font-size: clamp(1rem, 1.35vw, 1.45rem);

    cursor: pointer;
    user-select: none;

    transition:
        color 0.2s ease,
        background 0.2s ease,
        text-shadow 0.2s ease;
}

.settings {
    position: relative;

    display: flex;
    align-items: stretch;

    height: 100%;
}

.settings .nav-icon-button {
    border-right: 1px solid var(--white-line);
}

.nav-icon-button:hover {
    color: #ffffff;
    background: rgba(55, 185, 255, 0.08);

    text-shadow:
        0 0 8px rgba(141, 232, 255, 0.9),
        0 0 16px rgba(55, 185, 255, 0.65);
}

/* No rotating gear */

.settings-button,
.settings-button:hover {
    transform: none;
    box-shadow: none;
}

.mail-badge {
    position: absolute;
    top: clamp(5px, 1vh, 11px);
    right: 5px;

    display: flex;
    align-items: center;
    justify-content: center;

    min-width: 17px;
    height: 17px;
    padding: 0 4px;

    color: #ffffff;
    background: var(--danger);

    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 999px;

    font-size: 0.61rem;
    font-weight: 700;
    line-height: 1;

    box-shadow:
        0 0 8px rgba(255, 89, 103, 0.8);
}

/* =========================================================
   ACCOUNT MENU
   ========================================================= */

.account-menu {
    display: none;

    position: absolute;
    top: calc(100% + 8px);
    right: 0;

    z-index: 1200;

    width: 180px;
    margin: 0;
    padding: 6px;

    list-style: none;

    background:
        linear-gradient(
            180deg,
            rgba(16, 42, 70, 0.99),
            rgba(5, 17, 30, 0.99)
        );

    border: 1px solid var(--border-bright);

    box-shadow:
        0 14px 32px rgba(0, 0, 0, 0.62),
        var(--glow-medium);
}

.account-menu.open {
    display: block;
}

.account-menu::before {
    content: "";

    position: absolute;
    top: -6px;
    right: 20px;

    width: 10px;
    height: 10px;

    background: rgba(16, 42, 70, 0.99);

    border-top: 1px solid var(--border-bright);
    border-left: 1px solid var(--border-bright);

    transform: rotate(45deg);
}

.account-menu li + li {
    margin-top: 4px;
}

.account-menu a,
.account-menu button {
    display: block;

    width: 100%;
    padding: 12px 14px;

    color: var(--text-secondary);
    background: transparent;

    border: 1px solid transparent;

    text-align: left;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;

    cursor: pointer;

    transition:
        color 0.2s ease,
        background 0.2s ease,
        border-color 0.2s ease,
        padding-left 0.2s ease;
}

.account-menu a:hover,
.account-menu button:hover {
    padding-left: 20px;

    color: var(--accent-bright);
    background: rgba(55, 185, 255, 0.12);

    border-color: rgba(55, 185, 255, 0.4);
}

/* =========================================================
   DASHBOARD
   ========================================================= */

.dashboard {
    display: grid;
    grid-template-columns:
        minmax(250px, 0.82fr)
        minmax(410px, 1.6fr);

    gap: clamp(8px, 1.15vw, 22px);

    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;

    margin: 0;
    padding: clamp(8px, 1.25vw, 22px);

    overflow: hidden;
}

.dashboard-column {
    display: grid;

    gap: clamp(7px, 1vh, 16px);

    min-width: 0;
    min-height: 0;
}

.profile-column {
    grid-template-rows:
        minmax(0, 1.3fr)
        minmax(0, 0.7fr)
        minmax(0, 0.8fr)
        minmax(0, 1fr);
}

.quest-column {
    grid-template-rows:
        minmax(0, 1.2fr)
        minmax(0, 1fr);
}

/* =========================================================
   PANELS
   ========================================================= */

.system-panel {
    position: relative;

    min-width: 0;
    min-height: 0;

    padding: clamp(10px, 1.1vw, 22px);

    overflow: hidden;

    background:
        linear-gradient(
            135deg,
            rgba(15, 41, 68, 0.93),
            rgba(5, 18, 32, 0.96)
        );

    border: 1px solid var(--border);

    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.38),
        inset 0 0 24px rgba(55, 185, 255, 0.035),
        var(--glow-small);
}

.system-panel::before,
.system-panel::after {
    content: "";

    position: absolute;

    width: 14px;
    height: 14px;

    pointer-events: none;
}

.system-panel::before {
    top: -1px;
    left: -1px;

    border-top: 2px solid var(--accent-bright);
    border-left: 2px solid var(--accent-bright);
}

.system-panel::after {
    right: -1px;
    bottom: -1px;

    border-right: 2px solid var(--accent-bright);
    border-bottom: 2px solid var(--accent-bright);
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    margin-bottom: clamp(6px, 0.8vh, 14px);
    padding-bottom: clamp(5px, 0.65vh, 10px);

    border-bottom: 1px solid rgba(141, 232, 255, 0.24);
}

.panel-label {
    color: var(--accent-bright);

    font-size: clamp(0.55rem, 0.67vw, 0.75rem);
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.panel-value,
.quest-reset {
    color: var(--text-secondary);

    font-size: clamp(0.54rem, 0.62vw, 0.72rem);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* =========================================================
   LEVEL
   ========================================================= */

.level-content {
    display: flex;
    align-items: center;

    height: calc(100% - 30px);
    min-height: 0;

    gap: clamp(12px, 1.4vw, 22px);
}

.level-circle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    width: clamp(72px, 7.6vw, 122px);
    height: clamp(72px, 7.6vw, 122px);

    flex-shrink: 0;

    background:
        radial-gradient(
            circle,
            rgba(55, 185, 255, 0.2),
            rgba(5, 18, 32, 0.8) 68%
        );

    border: 2px solid var(--accent-bright);
    border-radius: 50%;

    box-shadow:
        inset 0 0 24px rgba(55, 185, 255, 0.15),
        0 0 22px rgba(55, 185, 255, 0.32);
}

.level-number {
    color: #ffffff;

    font-size: clamp(1.8rem, 2.8vw, 3rem);
    font-weight: 700;
    line-height: 1;

    text-shadow:
        0 0 12px rgba(141, 232, 255, 0.75);
}

.level-word {
    margin-top: 5px;

    color: var(--accent-bright);

    font-size: clamp(0.46rem, 0.55vw, 0.62rem);
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.eyebrow {
    margin: 0 0 4px;

    color: var(--text-secondary);

    font-size: clamp(0.52rem, 0.6vw, 0.68rem);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.level-details h1 {
    margin: 0 0 clamp(4px, 0.6vh, 10px);

    font-size: clamp(1.05rem, 1.7vw, 1.9rem);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.muted-text,
.panel-note,
.reason-text {
    margin: 0;

    color: var(--text-secondary);

    font-size: clamp(0.6rem, 0.72vw, 0.86rem);
    line-height: 1.4;
}

/* =========================================================
   EXPERIENCE
   ========================================================= */

.experience-bar,
.goal-progress {
    overflow: hidden;

    background: rgba(2, 10, 18, 0.88);

    border: 1px solid rgba(141, 232, 255, 0.25);

    box-shadow:
        inset 0 0 10px rgba(0, 0, 0, 0.6);
}

.experience-bar {
    height: clamp(8px, 1.2vh, 13px);
    margin-bottom: clamp(5px, 0.7vh, 11px);
}

.experience-fill {
    width: 24%;
    height: 100%;

    background:
        linear-gradient(
            90deg,
            var(--accent-dark),
            var(--accent-bright)
        );

    box-shadow:
        0 0 14px rgba(55, 185, 255, 0.8);
}

/* =========================================================
   BUTTONS
   ========================================================= */

.text-button,
.panel-action {
    color: var(--accent-bright);
    background: rgba(55, 185, 255, 0.08);

    border: 1px solid rgba(141, 232, 255, 0.48);

    font-size: clamp(0.54rem, 0.62vw, 0.7rem);
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;

    cursor: pointer;

    transition:
        color 0.2s ease,
        background 0.2s ease,
        box-shadow 0.2s ease;
}

.text-button {
    margin-top: clamp(6px, 0.8vh, 14px);
    padding: clamp(5px, 0.65vh, 8px) 11px;
}

.panel-action {
    padding: clamp(5px, 0.6vh, 8px) 10px;
}

.text-button:hover,
.panel-action:hover {
    color: #ffffff;
    background: rgba(55, 185, 255, 0.18);

    box-shadow: var(--glow-small);
}

/* =========================================================
   PERSONALIZATION
   ========================================================= */

.personalization-list {
    display: grid;
    grid-template-rows: repeat(4, minmax(0, 1fr));

    height: calc(100% - 30px);
    min-height: 0;
}

.personalization-row {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;
    min-height: 0;

    color: var(--text-secondary);

    border-bottom: 1px solid rgba(255, 255, 255, 0.09);

    font-size: clamp(0.58rem, 0.7vw, 0.82rem);
}

.personalization-row:last-child {
    border-bottom: 0;
}

.personalization-row strong {
    color: var(--accent-bright);

    font-size: clamp(0.54rem, 0.64vw, 0.74rem);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* =========================================================
   GOALS
   ========================================================= */

.goal-list {
    display: grid;
    grid-template-rows: repeat(3, minmax(0, 1fr));

    gap: clamp(5px, 0.7vh, 11px);

    height: calc(100% - 34px);
    min-height: 0;
}

.goal-card {
    display: grid;
    grid-template-columns:
        auto
        minmax(0, 1fr)
        auto;

    align-items: center;

    gap: clamp(7px, 0.9vw, 16px);

    min-height: 0;
    padding: clamp(7px, 0.8vh, 14px);

    overflow: hidden;

    background: rgba(5, 20, 35, 0.72);

    border: 1px solid rgba(141, 232, 255, 0.23);

    transition:
        background 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.goal-card:hover {
    background: rgba(15, 43, 70, 0.78);

    border-color: rgba(141, 232, 255, 0.52);

    box-shadow:
        inset 0 0 20px rgba(55, 185, 255, 0.07);
}

.goal-number {
    display: flex;
    align-items: center;
    justify-content: center;

    width: clamp(28px, 2.8vw, 44px);
    height: clamp(28px, 2.8vw, 44px);

    color: var(--accent-bright);
    background: rgba(55, 185, 255, 0.08);

    border: 1px solid var(--border);

    font-size: clamp(0.56rem, 0.66vw, 0.78rem);
    font-weight: 800;
    letter-spacing: 0.05em;

    box-shadow: var(--glow-small);
}

.goal-content {
    min-width: 0;
}

.goal-content h2 {
    margin: 0 0 clamp(2px, 0.35vh, 5px);

    overflow: hidden;

    font-size: clamp(0.64rem, 0.8vw, 0.94rem);
    font-weight: 600;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.goal-content p {
    margin: 0 0 clamp(4px, 0.5vh, 8px);

    color: var(--text-secondary);

    font-size: clamp(0.54rem, 0.65vw, 0.76rem);
    line-height: 1.25;
}

.goal-progress {
    height: clamp(4px, 0.7vh, 7px);
}

.goal-progress-fill {
    height: 100%;

    background:
        linear-gradient(
            90deg,
            var(--accent-dark),
            var(--accent-bright)
        );

    box-shadow:
        0 0 10px rgba(55, 185, 255, 0.7);
}

.goal-progress-one {
    width: 45%;
}

.goal-progress-two {
    width: 30%;
}

.goal-progress-three {
    width: 70%;
}

.goal-percent {
    color: var(--accent-bright);

    font-size: clamp(0.55rem, 0.67vw, 0.77rem);
    font-weight: 800;
}

/* =========================================================
   DAILY QUESTS
   ========================================================= */

.quest-list {
    display: grid;
    grid-template-rows: repeat(4, minmax(0, 1fr));

    gap: clamp(4px, 0.6vh, 9px);

    height: calc(100% - 34px);
    min-height: 0;
}

.quest-item {
    position: relative;

    display: grid;
    grid-template-columns:
        auto
        minmax(0, 1fr)
        auto;

    align-items: center;

    gap: clamp(7px, 0.8vw, 13px);

    min-height: 0;
    padding: clamp(6px, 0.7vh, 12px);

    overflow: hidden;

    background: rgba(5, 20, 35, 0.72);

    border: 1px solid rgba(141, 232, 255, 0.22);

    cursor: pointer;

    transition:
        background 0.2s ease,
        border-color 0.2s ease,
        opacity 0.2s ease;
}

.quest-item:hover {
    background: rgba(15, 43, 70, 0.78);

    border-color: rgba(141, 232, 255, 0.48);
}

.quest-item input {
    position: absolute;

    width: 1px;
    height: 1px;

    opacity: 0;
    pointer-events: none;
}

.custom-checkbox {
    position: relative;

    width: clamp(17px, 1.7vw, 23px);
    height: clamp(17px, 1.7vw, 23px);

    background: rgba(2, 11, 20, 0.85);

    border: 1px solid var(--border-bright);

    box-shadow:
        inset 0 0 9px rgba(55, 185, 255, 0.1);
}

.quest-item input:checked + .custom-checkbox {
    background: rgba(64, 245, 155, 0.18);

    border-color: var(--success);

    box-shadow:
        0 0 10px rgba(64, 245, 155, 0.45);
}

.quest-item input:checked + .custom-checkbox::after {
    content: "✓";

    position: absolute;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    color: var(--success);

    font-size: 0.78rem;
    font-weight: 900;
}

.quest-item:has(input:checked) {
    opacity: 0.62;
}

.quest-item:has(input:checked) .quest-copy strong {
    text-decoration: line-through;
}

.quest-copy {
    display: flex;
    flex-direction: column;

    min-width: 0;

    gap: clamp(1px, 0.2vh, 4px);
}

.quest-copy strong {
    overflow: hidden;

    font-size: clamp(0.59rem, 0.72vw, 0.84rem);
    font-weight: 600;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quest-copy small {
    overflow: hidden;

    color: var(--text-secondary);

    font-size: clamp(0.5rem, 0.61vw, 0.71rem);
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quest-xp {
    color: var(--success);

    font-size: clamp(0.52rem, 0.61vw, 0.7rem);
    font-weight: 800;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

/* =========================================================
   CHAT RAIL
   ========================================================= */

.chat-rail {
    position: relative;
    z-index: 1050;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: 100%;
    min-height: 0;

    pointer-events: none;
}

.chat-line {
    position: absolute;
    top: 50%;
    right: 0;
    left: 0;

    height: 2px;

    background: var(--white-line);

    box-shadow:
        0 0 7px rgba(255, 255, 255, 0.3),
        0 0 12px rgba(55, 185, 255, 0.22);

    transform: translateY(-50%);
}

.chat-button {
    position: relative;
    z-index: 2;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    width: var(--chat-button-size);
    height: var(--chat-button-size);
    padding: 0;

    color: var(--accent-bright);

    background:
        radial-gradient(
            circle,
            rgba(23, 85, 129, 0.98),
            rgba(3, 15, 27, 1) 72%
        );

    border: 2px solid #ffffff;
    border-radius: 50%;

    box-shadow:
        inset 0 0 24px rgba(55, 185, 255, 0.2),
        0 0 18px rgba(55, 185, 255, 0.5),
        0 0 0 7px rgba(3, 7, 13, 0.95);

    cursor: pointer;
    pointer-events: auto;

    transition:
        color 0.2s ease,
        border-color 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.chat-button:hover,
.chat-button.active {
    color: #ffffff;
    border-color: var(--accent-bright);

    transform: scale(1.04);

    box-shadow:
        inset 0 0 30px rgba(55, 185, 255, 0.28),
        0 0 26px rgba(55, 185, 255, 0.7),
        0 0 0 7px rgba(3, 7, 13, 0.95);
}

.chat-icon {
    font-size: clamp(0.9rem, 1.3vh, 1.15rem);
    line-height: 1;

    transform: rotate(180deg);
}

.chat-button-label {
    margin-top: clamp(3px, 0.6vh, 6px);

    font-size: clamp(0.46rem, 0.58vh, 0.58rem);
    font-weight: 800;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

/* =========================================================
   CHAT PANEL
   ========================================================= */

.chat-panel {
    position: fixed;
    right: clamp(10px, 1.4vw, 24px);
    bottom: calc(var(--chat-row-height) + 12px);

    z-index: 1100;

    display: flex;
    flex-direction: column;

    width: min(420px, calc(100% - 24px));
    height: min(470px, calc(100vh - var(--navbar-height) - var(--chat-row-height) - 28px));

    background:
        linear-gradient(
            145deg,
            rgba(15, 41, 68, 0.99),
            rgba(3, 14, 25, 0.99)
        );

    border: 1px solid var(--border-bright);

    box-shadow:
        0 20px 48px rgba(0, 0, 0, 0.65),
        var(--glow-medium);

    opacity: 0;
    visibility: hidden;

    transform: translateY(20px) scale(0.97);

    transition:
        opacity 0.22s ease,
        visibility 0.22s ease,
        transform 0.22s ease;
}

.chat-panel.open {
    opacity: 1;
    visibility: visible;

    transform: translateY(0) scale(1);
}

.chat-panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: 14px;
    padding: 16px;

    border-bottom: 1px solid rgba(141, 232, 255, 0.25);
}

.chat-panel-heading p {
    margin: 6px 0 0;

    color: var(--text-secondary);

    font-size: 0.76rem;
    line-height: 1.4;
}

.chat-close-button {
    width: 32px;
    height: 32px;

    flex-shrink: 0;

    color: var(--text-secondary);
    background: transparent;

    border: 1px solid rgba(141, 232, 255, 0.3);

    font-size: 1.35rem;
    line-height: 1;

    cursor: pointer;
}

.chat-close-button:hover {
    color: #ffffff;
    background: rgba(55, 185, 255, 0.12);
}

.chat-messages {
    flex: 1;

    min-height: 0;
    padding: 16px;

    overflow-y: auto;
}

.system-message,
.user-message {
    width: fit-content;
    max-width: 84%;

    padding: 11px 13px;

    font-size: 0.82rem;
    line-height: 1.45;
}

.system-message {
    color: var(--text-primary);
    background: rgba(55, 185, 255, 0.1);

    border-left: 2px solid var(--accent-bright);
}

.user-message {
    margin: 11px 0 0 auto;

    color: #ffffff;
    background: rgba(55, 185, 255, 0.22);

    border-right: 2px solid var(--accent-bright);
}

.chat-input-row {
    display: grid;
    grid-template-columns: 1fr auto;

    gap: 9px;
    padding: 13px;

    border-top: 1px solid rgba(141, 232, 255, 0.25);
}

.chat-input-row input {
    min-width: 0;
    padding: 10px 11px;

    color: #ffffff;
    background: rgba(2, 11, 20, 0.88);

    border: 1px solid rgba(141, 232, 255, 0.35);
    outline: none;
}

.chat-input-row input:focus {
    border-color: var(--accent-bright);

    box-shadow:
        0 0 10px rgba(55, 185, 255, 0.25);
}

.chat-input-row button {
    padding: 0 15px;

    color: var(--accent-bright);
    background: rgba(55, 185, 255, 0.11);

    border: 1px solid var(--border-bright);

    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;

    cursor: pointer;
}

.chat-input-row button:hover {
    color: #ffffff;
    background: rgba(55, 185, 255, 0.22);
}

/* =========================================================
   LOW-HEIGHT SCREEN ADJUSTMENTS
   ========================================================= */

@media (max-height: 760px) {
    :root {
        --navbar-height: 54px;
        --chat-row-height: 76px;
        --chat-button-size: 66px;
    }

    .dashboard {
        gap: 7px;
        padding: 7px;
    }

    .dashboard-column {
        gap: 6px;
    }

    .system-panel {
        padding: 9px;
    }

    .panel-heading {
        margin-bottom: 5px;
        padding-bottom: 5px;
    }

    .goal-content p,
    .quest-copy small,
    .muted-text {
        font-size: 0.56rem;
    }
}

/* =========================================================
   NARROW SCREEN ADJUSTMENTS
   ========================================================= */

@media (max-width: 900px) {
    .dashboard {
        grid-template-columns:
            minmax(220px, 0.78fr)
            minmax(360px, 1.45fr);
    }

    .goal-content p {
        display: none;
    }
}

@media (max-width: 700px) {
    .dashboard {
        grid-template-columns:
            minmax(190px, 0.72fr)
            minmax(310px, 1.35fr);
    }

    .level-content {
        gap: 8px;
    }

    .level-details .muted-text {
        display: none;
    }

    .quest-copy small {
        display: none;
    }

    .goal-number {
        display: none;
    }

    .goal-card {
        grid-template-columns:
            minmax(0, 1fr)
            auto;
    }
}
/* =========================================================
   UPDATED THREE-ZONE DASHBOARD LAYOUT
   ========================================================= */

.dashboard {
    grid-template-columns:
        minmax(240px, 0.82fr)
        minmax(360px, 1.25fr)
        minmax(340px, 1.05fr);
    gap: clamp(14px, 1.4vw, 26px);
    padding: clamp(12px, 1.4vw, 24px);
}

.dashboard-left,
.dashboard-middle,
.dashboard-right {
    display: grid;
    min-width: 0;
    min-height: 0;
    gap: clamp(14px, 1.25vw, 24px);
}

.dashboard-left {
    grid-template-rows: minmax(150px, 0.92fr) minmax(100px, 0.56fr) minmax(130px, 0.74fr);
}

.dashboard-middle {
    grid-template-rows: minmax(290px, 1.3fr) minmax(190px, 0.9fr);
}

.dashboard-right {
    grid-template-rows: minmax(0, 3fr) minmax(0, 1fr);
}

.level-panel,
.experience-panel,
.reason-panel,
.goals-panel,
.personalization-panel,
.daily-quests-panel {
    height: 100%;
}

.compact-level-content {
    gap: clamp(10px, 1vw, 18px);
}

.compact-level-content .level-circle {
    width: clamp(62px, 5.5vw, 88px);
    height: clamp(62px, 5.5vw, 88px);
}

.compact-level-content .level-number {
    font-size: clamp(1.4rem, 2vw, 2.15rem);
}

.compact-level-content .level-details h1 {
    font-size: clamp(0.95rem, 1.25vw, 1.35rem);
}

.personalization-layout {
    display: grid;
    grid-template-columns: minmax(110px, 0.72fr) minmax(0, 1.35fr);
    gap: clamp(12px, 1vw, 18px);
    height: calc(100% - 34px);
    min-height: 0;
}

.image-stub {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    min-height: 0;
    color: var(--accent-bright);
    background:
        linear-gradient(135deg, rgba(55, 185, 255, 0.08), rgba(2, 11, 20, 0.72));
    border: 1px dashed rgba(141, 232, 255, 0.58);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    font-size: clamp(0.54rem, 0.63vw, 0.72rem);
    font-weight: 800;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.image-stub:hover {
    background: rgba(55, 185, 255, 0.14);
    border-color: var(--accent-bright);
    box-shadow: inset 0 0 20px rgba(55, 185, 255, 0.08), var(--glow-small);
}

.image-stub-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(42px, 4vw, 58px);
    height: clamp(42px, 4vw, 58px);
    border: 1px solid var(--border-bright);
    border-radius: 50%;
    font-size: clamp(1.3rem, 1.7vw, 1.9rem);
    line-height: 1;
    box-shadow: var(--glow-small);
}

.personalization-panel .personalization-list {
    height: 100%;
}

.daily-quests-panel .quest-list {
    gap: clamp(10px, 1.05vh, 18px);
}

.daily-quests-panel .quest-item {
    padding: clamp(10px, 1vw, 18px);
}

@media (max-width: 1100px) {
    .dashboard {
        grid-template-columns:
            minmax(210px, 0.8fr)
            minmax(315px, 1.2fr)
            minmax(300px, 1fr);
        gap: 10px;
        padding: 10px;
    }

    .dashboard-left,
    .dashboard-middle,
    .dashboard-right {
        gap: 10px;
    }

    .personalization-layout {
        grid-template-columns: 96px minmax(0, 1fr);
    }
}

@media (max-width: 820px) {
    .dashboard {
        grid-template-columns:
            minmax(190px, 0.76fr)
            minmax(270px, 1.08fr)
            minmax(250px, 0.98fr);
    }

    .goal-content p,
    .quest-copy small,
    .level-details .muted-text {
        display: none;
    }
}

/* =========================================================
   TRACKER PAGES — EXERCISE / FOOD / SLEEP
   Full shared replacement section
   ========================================================= */

.tracker-page {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: clamp(10px, 1.2vw, 20px);
    overflow: hidden;
}

.tracker-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(330px, 0.95fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
        "log chart"
        "log goals";
    gap: clamp(12px, 1.2vw, 22px);
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

.tracker-log-panel {
    grid-area: log;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tracker-chart-panel {
    grid-area: chart;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tracker-goals-panel {
    grid-area: goals;
}

.period-switcher {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 9px 10px;
    background: rgba(4, 17, 31, 0.72);
    border: 1px solid rgba(141, 232, 255, 0.2);
}

.period-switcher > div {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 10px;
    min-width: 0;
}

.period-title {
    color: var(--text-primary);
    font-size: clamp(0.68rem, 0.78vw, 0.82rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.period-dates {
    color: var(--text-secondary);
    font-size: clamp(0.58rem, 0.68vw, 0.74rem);
}

.period-arrow,
.chart-toggle {
    min-height: 34px;
    padding: 0 13px;
    color: var(--text-secondary);
    background: rgba(55, 185, 255, 0.06);
    border: 1px solid rgba(141, 232, 255, 0.3);
    cursor: pointer;
}

.period-arrow:hover,
.chart-toggle:hover,
.chart-toggle.active {
    color: #fff;
    background: rgba(55, 185, 255, 0.17);
    border-color: var(--accent-bright);
    box-shadow: var(--glow-small);
}

/* Exercise week --------------------------------------------------------- */

.week-log {
    display: grid;
    grid-template-columns: repeat(7, minmax(118px, 1fr));
    gap: 9px;
    flex: 1;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 3px;
}

.day-card {
    position: relative;
    min-width: 118px;
    min-height: 0;
    padding: 11px;
    overflow-y: auto;
    background: rgba(5, 20, 35, 0.72);
    border: 1px solid rgba(141, 232, 255, 0.22);
}

.day-card.current-day {
    border-color: var(--accent-bright);
    box-shadow:
        inset 0 0 22px rgba(55, 185, 255, 0.1),
        0 0 12px rgba(55, 185, 255, 0.28);
}

.current-day-badge {
    display: none;
    margin-bottom: 8px;
    color: var(--success);
    font-size: 0.54rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.current-day .current-day-badge {
    display: block;
}

.day-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 9px;
    border-bottom: 1px solid rgba(141, 232, 255, 0.16);
}

.day-card-header > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.day-name {
    color: var(--accent-bright);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.day-date {
    color: var(--text-primary);
    font-size: 1.15rem;
    font-weight: 700;
}

.day-edit {
    padding: 5px 7px;
    color: var(--accent-bright);
    background: rgba(55, 185, 255, 0.08);
    border: 1px solid rgba(141, 232, 255, 0.35);
    font-size: 0.55rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
}

.day-edit:hover {
    color: #fff;
    border-color: var(--accent-bright);
    background: rgba(55, 185, 255, 0.18);
}

.day-workouts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 9px;
}

.workout-summary {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px;
    background: rgba(2, 11, 20, 0.62);
    border-left: 2px solid var(--accent);
}

.workout-summary strong {
    color: var(--text-primary);
    font-size: 0.66rem;
    line-height: 1.25;
}

.workout-summary small,
.no-workout {
    color: var(--text-secondary);
    font-size: 0.57rem;
    line-height: 1.35;
}

.no-workout {
    padding: 10px 4px;
    font-style: italic;
}

/* Exercise progress chart ---------------------------------------------- */

.chart-toggle-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 12px;
}

.chart-toggle {
    width: 100%;
    font-size: clamp(0.58rem, 0.7vw, 0.76rem);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.bar-chart,
.sleep-chart {
    position: relative;
    display: grid;
    align-items: end;
    gap: clamp(7px, 0.85vw, 14px);
    flex: 1;
    min-height: 190px;
    padding: 18px 12px 9px;
    background:
        repeating-linear-gradient(
            to top,
            rgba(141, 232, 255, 0.08) 0,
            rgba(141, 232, 255, 0.08) 1px,
            transparent 1px,
            transparent 25%
        ),
        rgba(2, 11, 20, 0.52);
    border: 1px solid rgba(141, 232, 255, 0.2);
}

.bar-chart {
    grid-template-columns: repeat(6, minmax(30px, 1fr));
}

.sleep-chart {
    grid-template-columns: repeat(7, minmax(26px, 1fr));
}

.chart-column,
.sleep-bar {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    height: 100%;
    min-width: 0;
}

.chart-column > span,
.sleep-bar > span {
    display: block;
    width: min(38px, 72%);
    height: var(--bar, 50%);
    min-height: 8px;
    margin: 0 auto;
    background: linear-gradient(180deg, var(--accent-bright), var(--accent-dark));
    border: 1px solid rgba(141, 232, 255, 0.8);
    box-shadow: 0 0 15px rgba(55, 185, 255, 0.35);
}

.chart-column small,
.sleep-bar small {
    overflow: hidden;
    color: var(--text-secondary);
    font-size: clamp(0.5rem, 0.6vw, 0.68rem);
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-summary,
.sleep-quality-grid,
.goal-metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.chart-summary {
    margin-top: 10px;
}

.sleep-quality-grid {
    margin-top: 8px;
}

.chart-summary > div,
.sleep-quality-grid > div,
.goal-metric {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: 9px 10px;
    background: rgba(5, 20, 35, 0.72);
    border: 1px solid rgba(141, 232, 255, 0.18);
}

.chart-summary span,
.sleep-quality-grid span,
.goal-metric span {
    color: var(--text-secondary);
    font-size: clamp(0.49rem, 0.59vw, 0.66rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chart-summary strong,
.sleep-quality-grid strong,
.goal-metric strong {
    color: var(--text-primary);
    font-size: clamp(0.7rem, 0.85vw, 0.95rem);
}

.mini-progress {
    height: 6px;
    margin-top: 8px;
    overflow: hidden;
    background: rgba(2, 10, 18, 0.9);
    border: 1px solid rgba(141, 232, 255, 0.2);
}

.mini-progress i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-dark), var(--accent-bright));
    box-shadow: 0 0 10px rgba(55, 185, 255, 0.6);
}

/* Exercise editor modal ------------------------------------------------- */

.exercise-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(0, 4, 10, 0.8);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.exercise-modal.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.exercise-modal-card {
    width: min(980px, 96vw);
    max-height: 88vh;
    padding: 18px;
    overflow-y: auto;
    background: linear-gradient(145deg, rgba(15, 41, 68, 0.99), rgba(3, 14, 25, 0.99));
    border: 1px solid var(--border-bright);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), var(--glow-medium);
}

.modal-heading,
.modal-actions,
.workout-entry-head,
.exercise-entry-head,
.editor-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.modal-heading h2 {
    margin: 0;
    color: var(--accent-bright);
    font-size: 1rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.modal-close,
.remove-workout,
.remove-exercise,
.remove-set {
    color: var(--danger);
    background: rgba(255, 89, 103, 0.08);
    border: 1px solid rgba(255, 89, 103, 0.45);
    cursor: pointer;
}

.modal-close {
    width: 34px;
    height: 34px;
    color: var(--text-primary);
    background: transparent;
    border-color: rgba(141, 232, 255, 0.35);
    font-size: 1.2rem;
}

.workout-editor {
    margin: 16px 0;
}

.workout-entry {
    margin-bottom: 16px;
    padding: 14px;
    background: rgba(5, 20, 35, 0.8);
    border: 1px solid rgba(141, 232, 255, 0.25);
}

.exercise-entry {
    margin-top: 12px;
    padding: 12px;
    background: rgba(2, 11, 20, 0.65);
    border-left: 2px solid var(--accent);
}

.workout-name-input,
.exercise-name-input,
.set-input {
    color: var(--text-primary);
    background: rgba(2, 11, 20, 0.9);
    border: 1px solid rgba(141, 232, 255, 0.3);
    outline: none;
}

.workout-name-input,
.exercise-name-input {
    width: min(460px, 72%);
    padding: 9px 10px;
}

.workout-name-input:focus,
.exercise-name-input:focus,
.set-input:focus {
    border-color: var(--accent-bright);
    box-shadow: 0 0 8px rgba(55, 185, 255, 0.2);
}

.remove-workout,
.remove-exercise {
    padding: 7px 9px;
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.set-table {
    width: 100%;
    margin-top: 10px;
    border-collapse: collapse;
}

.set-table th,
.set-table td {
    padding: 7px;
    border-bottom: 1px solid rgba(141, 232, 255, 0.15);
    text-align: left;
    font-size: 0.66rem;
}

.set-table th {
    color: var(--text-secondary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.set-input {
    width: 100%;
    min-width: 65px;
    padding: 7px;
}

.remove-set {
    width: 28px;
    height: 28px;
}

.editor-actions {
    justify-content: flex-start;
    margin-top: 10px;
}

/* Food ------------------------------------------------------------------ */

.food-search-section {
    margin-bottom: 10px;
    padding: clamp(10px, 1.2vw, 15px);
    background:
        linear-gradient(135deg, rgba(55, 185, 255, 0.09), transparent 58%),
        rgba(3, 13, 24, 0.72);
    border: 1px solid rgba(55, 185, 255, 0.3);
    box-shadow: inset 0 0 18px rgba(55, 185, 255, 0.05);
}

.food-search-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 9px;
}

.food-search-kicker {
    display: block;
    margin-bottom: 2px;
    color: var(--accent);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.food-search-heading h2 {
    margin: 0;
    font-size: clamp(0.88rem, 1vw, 1.05rem);
    letter-spacing: 0.04em;
}

.food-search-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.food-search-input {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    color: var(--text-primary);
    background: rgba(1, 8, 15, 0.84);
    border: 1px solid rgba(141, 232, 255, 0.34);
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.food-search-input::placeholder {
    color: var(--text-muted);
}

.food-search-input:focus {
    border-color: var(--border-bright);
    box-shadow: var(--glow-small), inset 0 0 12px rgba(55, 185, 255, 0.06);
}

.food-search-button {
    min-width: 86px;
    padding: 0 18px;
    color: #03101a;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: linear-gradient(180deg, var(--accent-bright), var(--accent));
    border: 1px solid var(--accent-bright);
    cursor: pointer;
    box-shadow: var(--glow-small);
    transition: filter 160ms ease, box-shadow 160ms ease;
}

.food-search-button:hover {
    filter: brightness(1.12);
    box-shadow: var(--glow-medium);
}

.food-search-results,
.selected-food-panel {
    min-height: 40px;
    margin-top: 8px;
    padding: 11px 12px;
    color: var(--text-muted);
    font-size: 0.7rem;
    letter-spacing: 0.03em;
    background: rgba(5, 18, 31, 0.62);
    border: 1px dashed rgba(141, 232, 255, 0.22);
}

.food-search-results {
    max-height: 190px;
    overflow-y: auto;
}

.food-result-list {
    display: grid;
    gap: 7px;
}

.food-result-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3px 12px;
    width: 100%;
    padding: 9px 10px;
    text-align: left;
    background: rgba(55, 185, 255, 0.05);
    border: 1px solid rgba(141, 232, 255, 0.22);
    cursor: pointer;
}

.food-result-item:hover {
    background: rgba(55, 185, 255, 0.13);
    border-color: var(--accent-bright);
    box-shadow: var(--glow-small);
}

.food-result-item strong,
.food-result-item small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.food-result-item small {
    grid-column: 1;
    color: var(--text-secondary);
}

.food-result-item span {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    color: var(--success);
    white-space: nowrap;
}

.food-search-button:disabled {
    cursor: wait;
    filter: grayscale(0.35);
    opacity: 0.7;
}

.selected-food-panel:not([hidden]) {
    display: block;
}

.selected-food-header > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.selected-food-header strong {
    color: var(--text-primary);
    font-size: 0.86rem;
}

.selected-food-header small {
    color: var(--text-secondary);
}

.selected-nutrition-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin: 9px 0;
}

.selected-nutrition-grid > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 7px;
    background: rgba(55, 185, 255, 0.06);
    border: 1px solid rgba(141, 232, 255, 0.18);
}

.selected-nutrition-grid span {
    color: var(--text-muted);
    font-size: 0.54rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.selected-nutrition-grid strong {
    color: var(--success);
    font-size: 0.7rem;
}

.selected-food-controls {
    display: grid;
    grid-template-columns: minmax(100px, 0.75fr) minmax(130px, 1fr) auto;
    align-items: end;
    gap: 8px;
}

.selected-food-controls label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.selected-food-controls input,
.selected-food-controls select {
    width: 100%;
    height: 32px;
    padding: 5px 8px;
    color: var(--text-primary);
    background: rgba(1, 8, 15, 0.84);
    border: 1px solid rgba(141, 232, 255, 0.34);
}

.selected-food-controls select {
    cursor: pointer;
}

.selected-food-add {
    min-height: 32px;
    white-space: nowrap;
}

.manual-food-form {
    display: grid;
    gap: 10px;
}

.manual-food-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.manual-food-heading > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.manual-food-heading strong {
    color: var(--text-primary);
    font-size: 0.86rem;
}

.manual-food-heading small {
    color: var(--text-secondary);
}

.manual-food-heading .text-button {
    margin: 0;
}

.manual-field-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.manual-field-grid label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    color: var(--text-secondary);
    font-size: 0.56rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.manual-field-grid .manual-field-wide {
    grid-column: span 2;
}

.manual-field-grid input,
.manual-field-grid select {
    width: 100%;
    height: 32px;
    min-width: 0;
    padding: 5px 8px;
    color: var(--text-primary);
    background: rgba(1, 8, 15, 0.84);
    border: 1px solid rgba(141, 232, 255, 0.34);
}

.manual-entry-actions {
    display: flex;
    justify-content: flex-end;
}

.manual-entry-error {
    margin: 0;
    color: var(--danger);
    font-size: 0.64rem;
}

.selected-food-panel[hidden] {
    display: none;
}

.food-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.meal-log {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    gap: 9px;
    overflow-y: auto;
}

.meal-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: clamp(11px, 1.05vw, 17px);
    background: rgba(5, 20, 35, 0.72);
    border: 1px solid rgba(141, 232, 255, 0.2);
}

.meal-row > div {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.meal-row span {
    color: var(--accent-bright);
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.meal-row strong {
    color: var(--text-primary);
    font-size: clamp(0.72rem, 0.9vw, 0.98rem);
}

.meal-row small {
    color: var(--text-secondary);
    font-size: clamp(0.56rem, 0.66vw, 0.72rem);
}

.meal-row b {
    color: var(--success);
    font-size: clamp(0.65rem, 0.78vw, 0.86rem);
    white-space: nowrap;
}

.meal-row.empty {
    border-style: dashed;
    opacity: 0.78;
}

.meal-row .text-button {
    margin: 0;
}

.added-food-list {
    display: grid;
    gap: 5px;
    margin-top: 5px;
    padding-top: 6px;
    border-top: 1px solid rgba(141, 232, 255, 0.16);
}

.added-food-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.added-food-item > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.added-food-item strong {
    font-size: 0.68rem;
}

.added-food-item small {
    overflow: hidden;
    color: var(--text-muted);
    font-size: 0.56rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remove-food-entry {
    display: grid;
    place-items: center;
    width: 25px;
    height: 25px;
    padding: 0;
    color: var(--text-muted);
    background: rgba(255, 89, 103, 0.05);
    border: 1px solid rgba(255, 89, 103, 0.22);
    cursor: pointer;
}

.remove-food-entry:hover {
    color: #fff;
    background: rgba(255, 89, 103, 0.16);
    border-color: var(--danger);
}

.meal-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    margin-top: auto;
    padding-top: 4px;
}

.nutrition-panel-main {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
}

.calorie-breakdown {
    display: grid;
    grid-template-columns: minmax(190px, 1.1fr) minmax(150px, 0.9fr);
    align-items: center;
    gap: clamp(14px, 1.2vw, 22px);
    flex: 1;
    min-height: 0;
}

.calorie-donut {
    position: relative;
    width: min(100%, 310px);
    aspect-ratio: 1;
    margin: 0 auto;
    border-radius: 50%;
    background:
        conic-gradient(
            #55d6ff 0 var(--protein-deg, 102deg),
            #7f8cff var(--protein-deg, 102deg) var(--carb-deg, 256deg),
            #ffd664 var(--carb-deg, 256deg) var(--fat-deg, 360deg),
            rgba(255, 255, 255, 0.08) var(--fat-deg, 360deg) 360deg
        );
    box-shadow: 0 0 28px rgba(55, 185, 255, 0.22);
}

.calorie-donut::before {
    content: "";
    position: absolute;
    inset: 18%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(15, 41, 68, 0.98), rgba(3, 14, 25, 1));
    border: 1px solid rgba(141, 232, 255, 0.25);
}

.calorie-donut-center {
    position: absolute;
    inset: 24%;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
}

.calorie-donut-center strong {
    color: #fff;
    font-size: clamp(1.6rem, 2.6vw, 2.8rem);
    line-height: 1;
    text-shadow: 0 0 14px rgba(141, 232, 255, 0.5);
}

.calorie-donut-center span,
.calorie-donut-center small {
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: clamp(0.52rem, 0.63vw, 0.7rem);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.calorie-donut-center small {
    color: var(--success);
}

.macro-legend {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.macro-legend-item {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 10px 10px 15px;
    background: rgba(5, 20, 35, 0.72);
    border: 1px solid rgba(141, 232, 255, 0.16);
}

.macro-legend-item::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 4px;
}

.macro-protein::before { background: #55d6ff; }
.macro-carbs::before { background: #7f8cff; }
.macro-fat::before { background: #ffd664; }

.macro-legend-item span {
    color: var(--text-secondary);
    font-size: 0.55rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.macro-legend-item strong {
    color: var(--text-primary);
    font-size: clamp(0.72rem, 0.88vw, 0.98rem);
}

.macro-legend-item small {
    color: var(--text-secondary);
    font-size: 0.61rem;
}

.micro-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    margin-top: 10px;
}

.micro-grid > div {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px;
    background: rgba(5, 20, 35, 0.64);
    border: 1px solid rgba(141, 232, 255, 0.14);
}

.micro-grid span {
    color: var(--text-secondary);
    font-size: 0.52rem;
    text-transform: uppercase;
}

.micro-grid strong {
    color: var(--text-primary);
    font-size: 0.7rem;
}

/* Sleep ----------------------------------------------------------------- */

.sleep-log {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    gap: 9px;
    overflow-y: auto;
}

.log-row {
    display: grid;
    grid-template-columns: 52px minmax(80px, 0.65fr) minmax(150px, 1fr) auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: clamp(11px, 1vw, 16px);
    color: inherit;
    font: inherit;
    text-align: left;
    background: rgba(5, 20, 35, 0.72);
    border: 1px solid rgba(141, 232, 255, 0.2);
}

button.log-row {
    cursor: pointer;
}

button.log-row:hover,
button.log-row:focus-visible {
    background: rgba(12, 42, 68, 0.78);
    border-color: rgba(141, 232, 255, 0.48);
    outline: none;
}

.log-row.empty strong,
.log-row.empty small,
.log-row.empty b {
    color: var(--text-secondary);
}

.log-row > span {
    color: var(--accent-bright);
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.log-row strong {
    color: var(--text-primary);
    font-size: clamp(0.78rem, 1vw, 1.05rem);
}

.log-row small {
    color: var(--text-secondary);
    font-size: clamp(0.56rem, 0.66vw, 0.72rem);
}

.log-row b {
    color: var(--success);
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sleep-bar.empty > span {
    min-height: 0;
    opacity: 0.2;
}

.sleep-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px;
}

.sleep-form-grid .sleep-field-full {
    grid-column: 1 / -1;
}

.sleep-duration-preview {
    grid-column: 1 / -1;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.68rem;
}

.sleep-duration-preview strong {
    color: var(--accent-bright);
}

.sleep-form-actions {
    grid-column: 1 / -1;
    margin-top: 3px;
}

.home-modal button:disabled,
.sleep-period-arrow:disabled {
    opacity: 0.55;
    cursor: wait;
}

@media (max-width: 620px) {
    .sleep-form-grid {
        grid-template-columns: 1fr;
    }

    .sleep-form-grid .sleep-field-full,
    .sleep-duration-preview,
    .sleep-form-actions {
        grid-column: 1;
    }
}

/* Responsive tracker behavior ----------------------------------------- */

@media (max-width: 1150px) {
    .tracker-grid {
        grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.85fr);
    }

    .calorie-breakdown {
        grid-template-columns: minmax(160px, 1fr) minmax(135px, 0.9fr);
    }

    .calorie-donut {
        width: min(100%, 245px);
    }
}

@media (max-height: 760px) {
    .tracker-page {
        padding: 7px;
    }

    .tracker-grid {
        gap: 7px;
    }

    .period-switcher {
        margin-bottom: 7px;
        padding: 6px 8px;
    }

    .week-log {
        gap: 6px;
    }

    .day-card {
        padding: 7px;
    }

    .bar-chart,
    .sleep-chart {
        min-height: 135px;
        padding-top: 10px;
    }

    .chart-summary > div,
    .sleep-quality-grid > div,
    .goal-metric {
        padding: 6px 7px;
    }

    .meal-row,
    .log-row {
        padding: 8px;
    }

    .calorie-donut {
        width: min(100%, 205px);
    }
}

@media (max-width: 850px) {
    .tracker-grid {
        grid-template-columns: minmax(0, 1.2fr) minmax(270px, 0.8fr);
        gap: 8px;
    }

    .week-log {
        grid-template-columns: repeat(7, 108px);
    }

    .calorie-breakdown {
        grid-template-columns: 1fr;
        overflow-y: auto;
    }

    .calorie-donut {
        width: min(100%, 190px);
    }

    .micro-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* =========================================================
   HOME FUNCTIONALITY — EDITORS / DYNAMIC DATA
   ========================================================= */

.goals-panel .goal-list {
    display: flex;
    flex-direction: column;
    gap: clamp(5px, 0.7vh, 11px);
    height: calc(100% - 34px);
    min-height: 0;
    overflow-y: auto;
}

.goal-card-button {
    width: 100%;
    flex: 1 0 clamp(78px, 8.8vh, 112px);
    color: inherit;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.goal-card-button:focus-visible {
    outline: 1px solid var(--accent-bright);
    outline-offset: 2px;
}

.home-empty-state {
    margin: auto;
    padding: 18px;
    text-align: center;
}

.profile-image-preview {
    width: min(92px, 85%);
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid var(--border-bright);
    border-radius: 50%;
    box-shadow: var(--glow-small);
}

.home-modal {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(0, 4, 10, 0.82);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, visibility 0.18s ease;
}

.home-modal.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.home-modal-card {
    width: min(620px, 96vw);
    max-height: 88vh;
    padding: 18px;
    overflow-y: auto;
    background: linear-gradient(145deg, rgba(15, 41, 68, 0.99), rgba(3, 14, 25, 0.99));
    border: 1px solid var(--border-bright);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.72), var(--glow-medium);
}

.home-modal-body {
    margin-top: 16px;
}

.home-edit-form {
    display: grid;
    gap: 13px;
}

.home-form-field {
    display: grid;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.home-form-field input,
.home-form-field textarea,
.home-form-field select {
    width: 100%;
    min-width: 0;
    padding: 10px 11px;
    color: var(--text-primary);
    background: rgba(2, 11, 20, 0.9);
    border: 1px solid rgba(141, 232, 255, 0.34);
    outline: none;
    resize: vertical;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
}

.home-form-field input:focus,
.home-form-field textarea:focus,
.home-form-field select:focus {
    border-color: var(--accent-bright);
    box-shadow: 0 0 10px rgba(55, 185, 255, 0.22);
}

.home-modal-actions,
.home-modal-action-group {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
}

.home-modal-actions .text-button,
.home-modal-action-group .text-button {
    margin-top: 0;
}

.home-modal-actions.split-actions {
    justify-content: space-between;
}

.home-danger-button {
    padding: 7px 10px;
    color: var(--danger);
    background: rgba(255, 89, 103, 0.08);
    border: 1px solid rgba(255, 89, 103, 0.45);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
}

.home-danger-button:hover {
    color: #fff;
    background: rgba(255, 89, 103, 0.18);
    border-color: var(--danger);
}

.home-modal button:disabled,
.quest-item input:disabled + .custom-checkbox {
    opacity: 0.55;
    cursor: wait;
}


/* =========================================================
   INBOX
   ========================================================= */

.mail-badge[hidden] {
    display: none;
}

.inbox-nav-active {
    color: #ffffff;
    background: rgba(55, 185, 255, 0.12);
    text-shadow: 0 0 8px rgba(141, 232, 255, 0.9);
}

.inbox-page {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: clamp(10px, 1.25vw, 22px);
    overflow: hidden;
}

.inbox-layout {
    display: grid;
    grid-template-columns: minmax(330px, 0.78fr) minmax(0, 1.35fr);
    gap: clamp(12px, 1.2vw, 22px);
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

.inbox-list-panel,
.inbox-detail-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.inbox-list-panel .panel-heading {
    align-items: flex-start;
}

.inbox-list-panel .panel-heading > div:first-child {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.inbox-summary-text {
    color: var(--text-secondary);
    font-size: 0.66rem;
}

.inbox-filter-row {
    display: flex;
    gap: 6px;
}

.inbox-filter {
    padding: 6px 9px;
    color: var(--text-secondary);
    background: rgba(55, 185, 255, 0.05);
    border: 1px solid rgba(141, 232, 255, 0.25);
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
}

.inbox-filter:hover,
.inbox-filter.active {
    color: #ffffff;
    background: rgba(55, 185, 255, 0.17);
    border-color: var(--accent-bright);
}

.inbox-message-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 3px;
}

.inbox-message-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 7px;
    width: 100%;
    padding: 13px 14px;
    color: var(--text-primary);
    text-align: left;
    background: rgba(4, 17, 31, 0.72);
    border: 1px solid rgba(141, 232, 255, 0.2);
    cursor: pointer;
}

.inbox-message-card::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 3px;
    background: transparent;
}

.inbox-message-card:hover,
.inbox-message-card.selected {
    background: rgba(15, 43, 70, 0.78);
    border-color: rgba(141, 232, 255, 0.52);
}

.inbox-message-card.unread::before {
    background: var(--accent-bright);
    box-shadow: 0 0 10px rgba(55, 185, 255, 0.75);
}

.inbox-message-card.unread > strong {
    color: #ffffff;
}

.inbox-message-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.inbox-message-type {
    color: var(--accent-bright);
    font-size: 0.56rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.inbox-message-card time,
.inbox-detail-header time {
    color: var(--text-muted);
    font-size: 0.56rem;
}

.inbox-message-card > strong {
    overflow: hidden;
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inbox-message-card > p {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 0.65rem;
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.inbox-list-empty {
    display: grid;
    place-items: center;
    flex: 1;
    min-height: 160px;
    color: var(--text-muted);
    font-size: 0.72rem;
}

.inbox-empty-state {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 0;
    text-align: center;
}

.inbox-empty-icon {
    color: var(--accent-bright);
    font-size: clamp(2rem, 4vw, 4rem);
    text-shadow: 0 0 22px rgba(55, 185, 255, 0.45);
}

.inbox-empty-state strong {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.inbox-empty-state p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.76rem;
}

.inbox-message-detail {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

.inbox-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(141, 232, 255, 0.22);
}

.inbox-detail-header h1 {
    margin: 6px 0 7px;
    font-size: clamp(1.1rem, 1.6vw, 1.55rem);
    font-weight: 600;
}

.inbox-unread-pill {
    flex-shrink: 0;
    padding: 5px 8px;
    color: var(--accent-bright);
    background: rgba(55, 185, 255, 0.1);
    border: 1px solid rgba(141, 232, 255, 0.45);
    font-size: 0.55rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.inbox-detail-body {
    flex: 1;
    min-height: 0;
    padding: clamp(16px, 2vw, 28px) 2px;
    overflow-y: auto;
    color: var(--text-secondary);
    font-size: clamp(0.74rem, 0.86vw, 0.9rem);
    line-height: 1.7;
    white-space: pre-wrap;
}

.inbox-detail-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 13px;
    border-top: 1px solid rgba(141, 232, 255, 0.22);
}

.inbox-primary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.home-danger-button {
    padding: clamp(5px, 0.6vh, 8px) 10px;
    color: var(--danger);
    background: rgba(255, 89, 103, 0.08);
    border: 1px solid rgba(255, 89, 103, 0.45);
    font-size: clamp(0.54rem, 0.62vw, 0.7rem);
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    cursor: pointer;
}

.home-danger-button:hover {
    color: #ffffff;
    background: rgba(255, 89, 103, 0.18);
    border-color: var(--danger);
}

@media (max-width: 900px) {
    .inbox-layout {
        grid-template-columns: minmax(280px, 0.85fr) minmax(360px, 1.15fr);
        gap: 8px;
    }

    .inbox-filter {
        padding: 5px 6px;
        font-size: 0.52rem;
    }
}

@media (max-height: 760px) {
    .inbox-page {
        padding: 7px;
    }

    .inbox-layout {
        gap: 7px;
    }

    .inbox-message-card {
        padding: 9px 10px;
    }

    .inbox-detail-body {
        padding: 12px 2px;
    }
}

/* Journal --------------------------------------------------------------- */

.journal-page {
    min-width: 0;
    min-height: 0;
    padding: clamp(14px, 2vw, 30px) clamp(18px, 3vw, 52px);
    overflow: hidden;
}

.journal-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: clamp(12px, 1.5vh, 20px);
    width: min(1600px, 100%);
    height: 100%;
    margin: 0 auto;
    min-width: 0;
    min-height: 0;
}

.journal-page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    min-width: 0;
}

.journal-page-header h1 {
    margin: 4px 0 3px;
    font-size: clamp(1.45rem, 2.4vw, 2.35rem);
    font-weight: 600;
    letter-spacing: 0.035em;
}

.journal-page-header p {
    max-width: 740px;
    margin: 0;
    color: var(--text-secondary);
    font-size: clamp(0.68rem, 0.8vw, 0.88rem);
    line-height: 1.4;
}

.journal-status {
    min-width: 130px;
    min-height: 1.2em;
    color: var(--text-secondary);
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-align: right;
    text-transform: uppercase;
}

.journal-status[data-tone="success"] { color: var(--success); }
.journal-status[data-tone="error"] { color: var(--danger); }

.journal-view {
    display: flex;
    flex-direction: column;
    padding: clamp(16px, 1.5vw, 25px);
}

.journal-view[hidden] { display: none; }

.journal-toolbar,
.journal-editor-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex: 0 0 auto;
    padding-bottom: clamp(12px, 1.5vh, 18px);
    border-bottom: 1px solid rgba(141, 232, 255, 0.24);
}

.journal-toolbar h2 {
    margin: 5px 0 0;
    font-size: clamp(1.12rem, 1.55vw, 1.65rem);
    font-weight: 600;
}

.journal-step {
    display: block;
    color: var(--text-muted);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.journal-toolbar-actions,
.journal-card-actions,
.journal-row-actions,
.journal-modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Home running counter: fills the lower quarter of the right column. */
.running-counter-panel {
    height: 100%;
    container-type: inline-size;
}

.running-counter-button {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
    justify-items: center;
    align-items: start;
    width: 100%;
    height: 100%;
    padding: 0;
    color: var(--accent-bright);
    background: transparent;
    border: 0;
    text-align: center;
    cursor: pointer;
}

.running-counter-title {
    grid-row: 1;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(0.85rem, 1.25vw, 1.15rem);
    font-weight: 600;
}

.running-counter-elapsed {
    grid-row: 2;
    align-self: center;
    max-width: 100%;
    white-space: nowrap;
    font-size: clamp(1rem, 9cqw, 2.4rem);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.running-counter-elapsed:not([hidden]),
.running-counter-units:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, var(--counter-day-width, 1fr)) 0.3fr minmax(0, 1fr) 0.3fr minmax(0, 1fr) 0.3fr minmax(0, 1fr);
    width: 80%;
    align-items: center;
    text-align: center;
}

.running-counter-units {
    grid-row: 3;
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: clamp(0.75rem, 4cqw, 1rem);
}

.running-counter-edit {
    position: absolute;
    bottom: 6px;
    right: 9px;
    margin: 0;
    font-size: 0.5rem;
}

.running-counter-resets {
    position: absolute;
    bottom: 6px;
    left: 9px;
    color: var(--text-secondary);
    font-size: 0.65rem;
    pointer-events: none;
}

.running-counter-pause {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: 0.5rem;
}

.running-counter-button:focus-visible {
    outline: 1px solid var(--accent-bright);
    outline-offset: 3px;
}

.journal-create-control {
    position: relative;
    flex: 0 0 auto;
}

.journal-create-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 40;
    display: grid;
    width: max-content;
    min-width: 210px;
    padding: 6px;
    background: linear-gradient(145deg, rgba(15, 41, 68, 0.99), rgba(5, 18, 32, 0.99));
    border: 1px solid var(--border-bright);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.58), var(--glow-medium);
}

.journal-create-menu[hidden] { display: none; }

.journal-create-menu button {
    width: 100%;
    min-height: 38px;
    padding: 9px 11px;
    color: var(--text-secondary);
    text-align: left;
    background: transparent;
    border: 0;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.035em;
    cursor: pointer;
}

.journal-create-menu button:hover,
.journal-create-menu button:focus-visible {
    color: #fff;
    background: rgba(55, 185, 255, 0.12);
    outline: none;
}

.journal-primary-action {
    color: #fff;
    background: linear-gradient(135deg, rgba(20, 127, 202, 0.92), rgba(55, 185, 255, 0.36));
    border-color: var(--accent-bright);
    box-shadow: 0 0 14px rgba(55, 185, 255, 0.18);
}

.journal-primary-action:hover {
    background: linear-gradient(135deg, rgba(20, 127, 202, 1), rgba(55, 185, 255, 0.54));
}

.journal-primary-action:disabled,
.journal-view button:disabled,
.journal-modal button:disabled {
    cursor: wait;
    opacity: 0.55;
}

.journal-folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    align-content: start;
    gap: clamp(12px, 1.2vw, 18px);
    min-height: 0;
    margin: clamp(14px, 1.8vh, 22px) -4px -4px;
    padding: 4px;
    overflow: auto;
}

.journal-folder-card {
    min-width: 0;
    background: rgba(4, 17, 30, 0.72);
    border: 1px solid rgba(141, 232, 255, 0.24);
    box-shadow: inset 0 0 18px rgba(55, 185, 255, 0.025);
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.journal-folder-card:hover {
    background: rgba(11, 32, 52, 0.84);
    border-color: rgba(141, 232, 255, 0.52);
    transform: translateY(-1px);
}

.journal-folder-open {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    min-height: 112px;
    padding: 18px;
    color: inherit;
    text-align: left;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.journal-folder-open:focus-visible,
.journal-entry-open:focus-visible {
    outline: 2px solid var(--accent-bright);
    outline-offset: -2px;
}

.journal-folder-icon {
    color: var(--accent-bright);
    font-size: 2.15rem;
    line-height: 1;
    text-shadow: 0 0 14px rgba(55, 185, 255, 0.45);
}

.journal-folder-details,
.journal-entry-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.journal-folder-details strong {
    overflow: hidden;
    font-size: 1rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.journal-folder-details small,
.journal-folder-details time {
    margin-top: 5px;
    color: var(--text-secondary);
    font-size: 0.69rem;
}

.journal-folder-details time { color: var(--text-muted); }

.journal-card-actions {
    justify-content: flex-end;
    padding: 9px 12px;
    border-top: 1px solid rgba(141, 232, 255, 0.12);
}

.journal-card-actions button,
.journal-row-actions button,
.journal-back-button {
    padding: 4px 7px;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
}

.journal-card-actions button:hover,
.journal-row-actions button:hover,
.journal-back-button:hover { color: var(--accent-bright); }

.journal-card-actions .journal-danger-text,
.journal-row-actions .journal-danger-text { color: #ff9aa3; }

.journal-card-actions .journal-danger-text:hover,
.journal-row-actions .journal-danger-text:hover { color: var(--danger); }

.journal-back-button {
    margin: 0 0 8px -7px;
    color: var(--accent-bright);
    text-transform: uppercase;
}

.journal-sort-control {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.journal-sort-control select,
.journal-modal-field input,
.journal-modal-field select,
.journal-entry-name,
.journal-entry-content {
    color: var(--text-primary);
    background: rgba(2, 11, 20, 0.78);
    border: 1px solid rgba(141, 232, 255, 0.35);
    outline: none;
}

.journal-sort-control select {
    padding: 7px 30px 7px 9px;
    font-size: 0.72rem;
}

.journal-sort-control option,
.journal-modal-field option {
    color: var(--text-primary);
    background: #071829;
}

.journal-sort-control select:focus,
.journal-modal-field input:focus,
.journal-modal-field select:focus,
.journal-entry-name:focus,
.journal-entry-content:focus {
    border-color: var(--accent-bright);
    box-shadow: 0 0 0 2px rgba(55, 185, 255, 0.12), var(--glow-small);
}

.journal-list-heading,
.journal-entry-row {
    display: grid;
    grid-template-columns: minmax(300px, 2fr) minmax(90px, 0.45fr) minmax(145px, 0.72fr) minmax(145px, 0.72fr) minmax(225px, auto);
    align-items: center;
}

.journal-entry-table {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: auto;
}

.journal-list-heading {
    position: sticky;
    top: 0;
    z-index: 2;
    flex: 0 0 auto;
    gap: 14px;
    width: 100%;
    min-width: 980px;
    margin-top: 8px;
    padding: 8px 14px;
    color: var(--text-muted);
    background: rgba(5, 18, 32, 0.98);
    font-size: 0.61rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.journal-entry-list {
    width: 100%;
    min-width: 980px;
    min-height: 0;
    overflow: visible;
    border-top: 1px solid rgba(141, 232, 255, 0.12);
}

.journal-entry-row {
    min-width: 980px;
    gap: 14px;
    padding: 0 14px;
    border-bottom: 1px solid rgba(141, 232, 255, 0.13);
    transition: background 0.16s ease;
}

.journal-entry-row:hover { background: rgba(55, 185, 255, 0.055); }

.journal-entry-open {
    display: grid;
    grid-column: 1 / 5;
    grid-template-columns: subgrid;
    align-items: center;
    gap: 14px;
    min-width: 0;
    min-height: 68px;
    padding: 10px 0;
    color: inherit;
    text-align: left;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.journal-entry-text strong,
.journal-entry-text small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.journal-entry-text strong { font-size: 0.83rem; }

.journal-entry-type {
    display: inline-flex;
    align-items: center;
    justify-self: start;
    min-height: 23px;
    padding: 4px 8px;
    color: var(--accent-bright);
    background: rgba(55, 185, 255, 0.09);
    border: 1px solid rgba(141, 232, 255, 0.25);
    font-size: 0.61rem;
    font-weight: 800;
    letter-spacing: 0.055em;
    line-height: 1;
    text-transform: uppercase;
    white-space: nowrap;
}

.journal-entry-text small,
.journal-entry-open time {
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 0.67rem;
}

.journal-row-actions {
    justify-content: flex-end;
}

.journal-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    grid-column: 1 / -1;
    min-height: 240px;
    padding: 28px;
    color: var(--text-secondary);
    text-align: center;
    border: 1px dashed rgba(141, 232, 255, 0.25);
}

.journal-empty-state .journal-empty-icon {
    margin-bottom: 8px;
    color: var(--accent-bright);
    font-size: 2rem;
}

.journal-empty-state strong {
    color: var(--text-primary);
    font-size: 1rem;
}

.journal-empty-state p {
    max-width: 430px;
    margin: 8px 0 18px;
    font-size: 0.76rem;
    line-height: 1.45;
}

.journal-editor-view { gap: 14px; }

.journal-editor-fields {
    display: grid;
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
    min-height: 0;
    flex: 1 1 auto;
}

.journal-entry-name-label,
.journal-entry-content-label {
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.journal-entry-name {
    width: 100%;
    padding: 10px 12px;
    font-size: clamp(1rem, 1.4vw, 1.35rem);
    font-weight: 600;
}

.journal-entry-metadata {
    display: flex;
    gap: 18px;
    padding: 8px 2px 13px;
    color: var(--text-muted);
    font-size: 0.65rem;
}

.journal-entry-content {
    width: 100%;
    height: 100%;
    min-height: 140px;
    padding: clamp(13px, 1.4vw, 20px);
    resize: none;
    font-family: Arial, Helvetica, sans-serif;
    font-size: clamp(0.82rem, 0.95vw, 1rem);
    line-height: 1.65;
    white-space: pre-wrap;
}

.journal-entry-media {
    display: flex;
    align-items: center;
    justify-content: center;
    grid-row: 4 / 6;
    width: 100%;
    height: 100%;
    min-height: 180px;
    padding: clamp(12px, 1.4vw, 20px);
    background: rgba(2, 11, 20, 0.78);
    border: 1px solid rgba(141, 232, 255, 0.35);
}

.journal-entry-media[hidden],
.journal-entry-player[hidden] {
    display: none;
}

.journal-entry-player {
    display: block;
    width: min(900px, 100%);
    max-width: 100%;
}

video.journal-entry-player {
    height: 100%;
    max-height: 100%;
    object-fit: contain;
    background: #000;
}

audio.journal-entry-player {
    height: 54px;
}

.journal-modal {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 5, 10, 0.78);
    backdrop-filter: blur(6px);
}

.journal-modal.open { display: flex; }

.journal-modal-card {
    width: min(480px, 100%);
    padding: 18px;
    background: linear-gradient(145deg, rgba(15, 41, 68, 0.99), rgba(5, 18, 32, 0.99));
    border: 1px solid var(--border-bright);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.62), var(--glow-medium);
}

.journal-modal-card.journal-recording-modal-card {
    width: min(720px, 100%);
}

.journal-modal-card .modal-heading { margin-bottom: 18px; }

.journal-modal-card .modal-heading h2 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.journal-modal-body { min-height: 72px; }

.journal-modal-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    color: var(--text-secondary);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.journal-modal-field input,
.journal-modal-field select {
    width: 100%;
    padding: 11px;
    font-size: 0.84rem;
    text-transform: none;
}

.journal-modal-actions {
    justify-content: flex-end;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid rgba(141, 232, 255, 0.2);
}

.journal-modal-actions .text-button { margin: 0; }

.journal-download-selector {
    display: grid;
    gap: 12px;
}

.journal-download-intro,
.journal-download-empty {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.76rem;
    line-height: 1.5;
}

.journal-download-selection-bar,
.journal-download-selection-controls,
.journal-download-entry-metadata {
    display: flex;
    align-items: center;
}

.journal-download-selection-bar {
    justify-content: space-between;
    gap: 10px;
}

.journal-download-selection-count {
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.journal-download-selection-controls {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.journal-download-selection-controls .text-button {
    margin: 0;
    padding: 4px 0;
}

.journal-download-selection-controls button:disabled {
    cursor: not-allowed;
}

.journal-download-entry-list {
    display: grid;
    gap: 6px;
    max-height: min(50vh, 400px);
    padding: 6px;
    overflow-y: auto;
    background: rgba(2, 11, 20, 0.52);
    border: 1px solid rgba(141, 232, 255, 0.2);
}

.journal-download-entry-option {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    padding: 10px;
    background: rgba(12, 35, 58, 0.62);
    border: 1px solid rgba(141, 232, 255, 0.16);
    cursor: pointer;
}

.journal-download-entry-option:hover,
.journal-download-entry-option:focus-within {
    background: rgba(20, 60, 94, 0.7);
    border-color: rgba(141, 232, 255, 0.42);
}

.journal-download-entry-option input {
    width: 18px;
    height: 18px;
    margin: 2px 0 0;
    accent-color: var(--accent-bright);
}

.journal-download-entry-copy {
    display: grid;
    min-width: 0;
    gap: 4px;
}

.journal-download-entry-copy strong {
    overflow-wrap: anywhere;
    color: var(--text-primary);
    font-size: 0.8rem;
}

.journal-download-entry-metadata {
    flex-wrap: wrap;
    gap: 5px 12px;
    color: var(--text-muted);
    font-size: 0.68rem;
}

.journal-download-empty {
    padding: 18px 12px;
    text-align: center;
}

.journal-recording-ui {
    display: grid;
    gap: 14px;
}

.journal-recording-status {
    min-height: 1.4em;
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.74rem;
    line-height: 1.45;
}

.journal-recording-indicator {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--text-secondary);
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.journal-recording-indicator::before {
    content: "";
    width: 9px;
    height: 9px;
    flex: 0 0 auto;
    background: var(--text-muted);
    border-radius: 50%;
}

.journal-recording-indicator.active {
    color: #ff9aa3;
}

.journal-recording-indicator.active::before {
    background: var(--danger);
    box-shadow: 0 0 10px rgba(255, 89, 103, 0.75);
}

.journal-recording-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 84px;
    padding: 10px;
    background: rgba(1, 8, 15, 0.86);
    border: 1px solid rgba(141, 232, 255, 0.25);
}

.journal-recording-preview audio,
.journal-recording-preview video {
    display: block;
    width: 100%;
    max-width: 100%;
}

.journal-recording-preview video {
    max-height: min(46vh, 430px);
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: #000;
}

.journal-recording-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.journal-recording-controls button {
    min-height: 42px;
}

@media (max-width: 980px) {
    .journal-page {
        padding-right: 20px;
        padding-left: 20px;
    }

    .journal-list-heading,
    .journal-entry-row {
        grid-template-columns: minmax(230px, 1.45fr) 80px 125px 125px minmax(205px, auto);
    }

    .journal-list-heading,
    .journal-entry-list {
        min-width: 820px;
    }

    .journal-entry-row {
        min-width: 820px;
    }
}

/* =========================================================
   JOURNAL — MOBILE RESPONSIVE PASS
   First-pass mobile adaptation.
   Keeps the existing Journal views / behavior intact and only
   changes layout, scrolling, sizing, and touch ergonomics.
   ========================================================= */

@media (max-width: 768px) {
    body[data-page="journal"] {
        --navbar-height: 54px;
        --chat-row-height: 76px;
        --chat-button-size: 66px;

        display: grid;
        grid-template-rows:
            var(--navbar-height)
            auto
            var(--chat-row-height);

        width: 100%;
        height: 100dvh;
        min-height: 100dvh;

        overflow-x: hidden;
        overflow-y: auto;

        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    /* -------------------------
       GLOBAL JOURNAL VIEWPORT
       ------------------------- */

    body[data-page="journal"] > header {
        position: sticky;
        top: 0;
        z-index: 1500;

        width: 100%;
        height: var(--navbar-height);
    }

    body[data-page="journal"] .navbar {
        min-width: 0;
        padding: 0;
    }

    body[data-page="journal"] .nav-left {
        flex: 1 1 auto;

        min-width: 0;

        overflow-x: auto;
        overflow-y: hidden;

        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
    }

    body[data-page="journal"] .nav-item {
        scroll-snap-align: start;
    }

    body[data-page="journal"] .nav-item a {
        min-height: 44px;
        padding: 0 12px;

        font-size: 0.64rem;
    }

    body[data-page="journal"] .nav-actions {
        flex: 0 0 auto;
    }

    body[data-page="journal"] .nav-icon-button {
        width: 48px;
        min-width: 48px;
    }

    body[data-page="journal"] .account-menu {
        position: fixed;
        top: calc(var(--navbar-height) + 7px);
        right: 7px;

        width: min(190px, calc(100vw - 14px));
    }

    body[data-page="journal"] .journal-page {
        width: 100%;
        height: auto;
        min-width: 0;
        min-height: calc(100dvh - var(--navbar-height) - var(--chat-row-height));

        padding: 12px;

        overflow: visible;
    }

    body[data-page="journal"] .journal-shell {
        display: flex;
        flex-direction: column;

        width: 100%;
        height: auto;
        min-width: 0;
        min-height: 0;

        gap: 12px;
    }

    /* -------------------------
       JOURNAL PAGE HEADER
       ------------------------- */

    body[data-page="journal"] .journal-page-header {
        display: flex;
        flex-direction: column;
        align-items: flex-start;

        gap: 8px;
    }

    body[data-page="journal"] .journal-page-header h1 {
        margin-top: 3px;

        font-size: clamp(1.55rem, 8vw, 2rem);
    }

    body[data-page="journal"] .journal-page-header p {
        max-width: none;

        font-size: 0.76rem;
        line-height: 1.45;
    }

    body[data-page="journal"] .journal-status {
        width: 100%;
        min-width: 0;
        min-height: 0;

        font-size: 0.62rem;
        text-align: left;
    }

    /* -------------------------
       SHARED JOURNAL PANELS
       ------------------------- */

    body[data-page="journal"] .journal-view {
        width: 100%;
        height: auto;
        min-width: 0;
        min-height: 0;

        padding: 13px;

        overflow: visible;
    }

    body[data-page="journal"] .journal-view[hidden] {
        display: none;
    }

    body[data-page="journal"] .journal-toolbar,
    body[data-page="journal"] .journal-editor-toolbar {
        flex-direction: column;
        align-items: stretch;

        gap: 12px;
        padding-bottom: 12px;
    }

    body[data-page="journal"] .journal-toolbar h2 {
        font-size: 1.2rem;
    }

    body[data-page="journal"] .journal-step {
        font-size: 0.58rem;
    }

    body[data-page="journal"] .journal-toolbar-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: stretch;

        width: 100%;

        gap: 7px;
    }

    body[data-page="journal"] .journal-toolbar-actions > * {
        min-width: 0;
    }

    body[data-page="journal"] .journal-create-control {
        flex: 1 1 100%;
        width: 100%;
    }

    body[data-page="journal"] .journal-create-menu {
        right: 0;
        left: 0;
        width: 100%;
        min-width: 0;
    }

    body[data-page="journal"] .journal-create-menu button {
        min-height: 44px;
        font-size: 0.72rem;
    }

    body[data-page="journal"] .journal-toolbar-actions .panel-action,
    body[data-page="journal"] .journal-editor-toolbar .panel-action,
    body[data-page="journal"] .journal-editor-toolbar .home-danger-button,
    body[data-page="journal"] #newFolderButton {
        min-height: 44px;
    }

    body[data-page="journal"] #newFolderButton {
        width: 100%;
    }

    body[data-page="journal"] .journal-back-button {
        min-height: 38px;
        margin: 0 0 5px -7px;

        font-size: 0.68rem;
    }

    /* -------------------------
       FOLDER VIEW
       ------------------------- */

    body[data-page="journal"] .journal-folder-grid {
        display: flex;
        flex-direction: column;

        width: 100%;
        min-height: 0;

        margin: 12px 0 0;
        padding: 0;

        gap: 9px;

        overflow: visible;
    }

    body[data-page="journal"] .journal-folder-card {
        width: 100%;
    }

    body[data-page="journal"] .journal-folder-open {
        min-height: 82px;
        padding: 13px;

        gap: 12px;
    }

    body[data-page="journal"] .journal-folder-icon {
        font-size: 1.7rem;
    }

    body[data-page="journal"] .journal-folder-details strong {
        font-size: 0.92rem;
    }

    body[data-page="journal"] .journal-folder-details small,
    body[data-page="journal"] .journal-folder-details time {
        font-size: 0.66rem;
    }

    body[data-page="journal"] .journal-card-actions {
        min-height: 44px;
        padding: 6px 8px;

        gap: 2px;
    }

    body[data-page="journal"] .journal-card-actions button {
        min-height: 34px;
        padding: 7px 9px;

        font-size: 0.66rem;
    }

    /* -------------------------
       ENTRY LIST VIEW
       ------------------------- */

    body[data-page="journal"] .journal-list-toolbar {
        align-items: stretch;
    }

    body[data-page="journal"] .journal-sort-control {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);

        width: 100%;
        min-height: 44px;
    }

    body[data-page="journal"] .journal-sort-control select {
        width: 100%;
        min-width: 0;
        min-height: 44px;

        font-size: 16px;
    }

    body[data-page="journal"] #newEntryButton {
        width: 100%;
        min-height: 44px;
    }

    body[data-page="journal"] #downloadJournalFolderButton {
        flex: 1 1 100%;
        width: 100%;
    }

    body[data-page="journal"] .journal-list-heading {
        display: none;
    }

    body[data-page="journal"] .journal-entry-table {
        display: block;
        width: 100%;
        min-width: 0;
        min-height: 0;

        overflow: visible;
    }

    body[data-page="journal"] .journal-entry-list {
        width: 100%;
        min-width: 0;
        min-height: 0;

        margin-top: 10px;

        overflow: visible;

        border-top: 0;
    }

    body[data-page="journal"] .journal-entry-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: stretch;

        width: 100%;
        min-width: 0;

        margin-bottom: 8px;
        padding: 0;

        gap: 0;

        background: rgba(4, 17, 30, 0.68);
        border: 1px solid rgba(141, 232, 255, 0.17);
    }

    body[data-page="journal"] .journal-entry-open {
        display: flex;
        flex-direction: column;
        align-items: flex-start;

        grid-column: 1;

        width: 100%;
        min-width: 0;
        min-height: 76px;

        padding: 12px;

        gap: 4px;
    }

    body[data-page="journal"] .journal-entry-text {
        width: 100%;
    }

    body[data-page="journal"] .journal-entry-type {
        align-self: flex-start;
        margin-top: 4px;
        font-size: 0.58rem;
    }

    body[data-page="journal"] .journal-entry-text strong {
        width: 100%;

        font-size: 0.86rem;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    body[data-page="journal"] .journal-entry-text small,
    body[data-page="journal"] .journal-entry-open time {
        width: 100%;

        margin-top: 3px;

        font-size: 0.64rem;
        white-space: normal;
    }

    body[data-page="journal"] .journal-row-actions {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: center;

        grid-column: 2;

        min-width: 76px;

        padding: 5px;

        border-left: 1px solid rgba(141, 232, 255, 0.12);
    }

    body[data-page="journal"] .journal-row-actions button {
        min-height: 34px;
        padding: 6px 8px;

        font-size: 0.62rem;
    }

    body[data-page="journal"] .journal-empty-state {
        min-height: 220px;
        padding: 22px 14px;
    }

    /* -------------------------
       ENTRY EDITOR
       ------------------------- */

    body[data-page="journal"] .journal-editor-view {
        gap: 12px;
    }

    body[data-page="journal"] .journal-editor-toolbar {
        align-items: stretch;
    }

    body[data-page="journal"] .journal-editor-toolbar .journal-toolbar-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));

        gap: 6px;
    }

    body[data-page="journal"] .journal-editor-toolbar .journal-toolbar-actions button {
        width: 100%;
        min-width: 0;
        padding-inline: 7px;

        font-size: 0.58rem;
    }

    body[data-page="journal"] .journal-editor-fields {
        display: flex;
        flex-direction: column;

        width: 100%;
        min-height: 0;

        flex: 0 0 auto;
    }

    body[data-page="journal"] .journal-entry-name-label,
    body[data-page="journal"] .journal-entry-content-label {
        font-size: 0.58rem;
    }

    body[data-page="journal"] .journal-entry-name {
        width: 100%;
        min-height: 44px;

        padding: 10px;

        font-size: 16px;
    }

    body[data-page="journal"] .journal-entry-metadata {
        display: flex;
        flex-direction: column;

        gap: 3px;
        padding: 8px 2px 12px;

        font-size: 0.62rem;
    }

    body[data-page="journal"] .journal-entry-content {
        width: 100%;
        height: auto;
        min-height: 56dvh;
        max-height: none;

        padding: 13px;

        overflow-y: auto;

        resize: vertical;

        font-size: 16px;
        line-height: 1.6;

        -webkit-overflow-scrolling: touch;
    }

    body[data-page="journal"] .journal-entry-media {
        grid-row: auto;
        width: 100%;
        height: auto;
        min-height: 180px;
        padding: 10px;
    }

    body[data-page="journal"] video.journal-entry-player {
        height: auto;
        max-height: 62dvh;
    }

    /* -------------------------
       JOURNAL MODAL
       ------------------------- */

    body[data-page="journal"] .journal-modal {
        align-items: flex-end;

        padding:
            10px
            10px
            max(10px, env(safe-area-inset-bottom));
    }

    body[data-page="journal"] .journal-modal-card {
        width: 100%;
        max-width: none;
        max-height: min(82dvh, 720px);

        padding: 15px;

        overflow-y: auto;

        -webkit-overflow-scrolling: touch;
    }

    body[data-page="journal"] .journal-modal-field input,
    body[data-page="journal"] .journal-modal-field select {
        min-height: 44px;

        font-size: 16px;
    }

    body[data-page="journal"] .journal-modal-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;

        gap: 8px;
    }

    body[data-page="journal"] .journal-modal-actions button {
        width: 100%;
        min-height: 44px;
    }

    body[data-page="journal"] .journal-download-selection-bar {
        align-items: stretch;
        flex-direction: column;
    }

    body[data-page="journal"] .journal-download-selection-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }

    body[data-page="journal"] .journal-download-selection-controls button {
        min-height: 44px;
    }

    body[data-page="journal"] .journal-download-entry-list {
        max-height: 42dvh;
    }

    body[data-page="journal"] .journal-recording-preview video {
        max-height: 38dvh;
    }

    body[data-page="journal"] .journal-recording-controls button {
        flex: 1 1 calc(50% - 4px);
        min-height: 44px;
    }

    /* -------------------------
       CHAT RAIL / CHAT PANEL
       ------------------------- */

    body[data-page="journal"] .chat-rail {
        width: 100%;
        height: var(--chat-row-height);
        min-height: var(--chat-row-height);

        margin: 0;
    }

    body[data-page="journal"] .chat-panel {
        right: 8px;
        bottom: calc(var(--chat-row-height) + max(8px, env(safe-area-inset-bottom)));

        width: calc(100% - 16px);
        height: min(62dvh, 470px);
        max-height: calc(100dvh - var(--navbar-height) - var(--chat-row-height) - 18px);
    }

    body[data-page="journal"] .chat-input-row input {
        font-size: 16px;
    }

    /* -------------------------
       MOBILE SAFE AREAS
       ------------------------- */

    @supports (padding: max(0px)) {
        body[data-page="journal"] .journal-page {
            padding-right: max(12px, env(safe-area-inset-right));
            padding-bottom: max(14px, env(safe-area-inset-bottom));
            padding-left: max(12px, env(safe-area-inset-left));
        }
    }
}

/* =========================================================
   JOURNAL — EXTRA SMALL PHONES
   ========================================================= */

@media (max-width: 430px) {
    body[data-page="journal"] .journal-page {
        padding: 8px;
    }

    body[data-page="journal"] .journal-view {
        padding: 10px;
    }

    body[data-page="journal"] .journal-page-header p {
        font-size: 0.71rem;
    }

    body[data-page="journal"] .journal-folder-open {
        min-height: 76px;
        padding: 11px;
    }

    body[data-page="journal"] .journal-card-actions {
        flex-wrap: wrap;
    }

    body[data-page="journal"] .journal-card-actions button {
        flex: 1 1 auto;
    }

    body[data-page="journal"] .journal-entry-row {
        grid-template-columns: minmax(0, 1fr);
    }

    body[data-page="journal"] .journal-entry-open,
    body[data-page="journal"] .journal-row-actions {
        grid-column: 1;
    }

    body[data-page="journal"] .journal-row-actions {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-end;

        min-width: 0;

        padding: 5px 7px;

        border-top: 1px solid rgba(141, 232, 255, 0.12);
        border-left: 0;
    }

    body[data-page="journal"] .journal-row-actions button {
        flex: 1 1 calc(50% - 4px);
    }

    body[data-page="journal"] .journal-editor-toolbar .journal-toolbar-actions {
        grid-template-columns: 1fr 1fr;
    }

    body[data-page="journal"] #saveEntryButton {
        grid-column: 1 / -1;
    }

    body[data-page="journal"] .journal-entry-content {
        min-height: 62dvh;
    }
}

/* =========================================================
   JOURNAL MOBILE — FIX CHAT RAIL TO VIEWPORT
   ========================================================= */

@media (max-width: 768px) {
    body[data-page="journal"] .chat-rail {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;

        z-index: 1600;

        width: 100%;
        height: var(--chat-row-height);
        min-height: var(--chat-row-height);

        margin: 0;

        pointer-events: none;
    }

    body[data-page="journal"] .chat-button {
        pointer-events: auto;
    }
}

/* =========================================================
   SHARED MOBILE SHELL
   Same navigation, account controls, Inbox and Chat as desktop.
   Keep the media query in sync with mobile-shell.js. Page internals stay
   under their existing styles (including Journal's mobile pass).
   ========================================================= */

.als-mobile-launcher,
.als-mobile-title,
.als-mobile-panel:not([open]) {
    display: none;
}

@media (max-width: 900px), (max-width: 1100px) and (orientation: landscape) and (pointer: coarse) {
    html.als-mobile-root {
        height: auto;
        overflow: auto;
        scroll-padding-top: calc(56px + env(safe-area-inset-top, 0px) + 12px);
        scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px) + 16px);
    }

    body.als-mobile-shell {
        --mobile-header-height: 56px;
        --mobile-chat-height: 76px;
        --mobile-edge-space: max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px), 8px);
        --navbar-height: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
        --chat-row-height: calc(var(--mobile-chat-height) + env(safe-area-inset-bottom, 0px));
        --chat-button-size: 56px;

        display: block;
        height: auto;
        min-height: 100svh;
        min-height: 100dvh;
        padding-top: var(--navbar-height);
        padding-bottom: calc(var(--chat-row-height) + 16px);
        overflow: visible;
    }

    body.als-mobile-shell > .als-mobile-header {
        position: fixed;
        inset: 0 0 auto;
        z-index: 1500;
        width: 100%;
        height: var(--navbar-height);
        padding-top: env(safe-area-inset-top, 0px);
        background: var(--background-secondary);
    }

    body.als-mobile-shell .navbar {
        display: grid;
        grid-template-columns: 96px minmax(0, 1fr) 96px;
        align-items: center;
        gap: 4px;
        height: var(--mobile-header-height);
        padding: 0 var(--mobile-edge-space);
    }

    body.als-mobile-shell .als-mobile-title {
        display: block;
        min-width: 0;
        overflow: hidden;
        color: var(--text-primary);
        font-size: 1rem;
        font-weight: 700;
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.als-mobile-shell .als-mobile-control,
    body.als-mobile-shell .nav-icon-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 44px;
        width: 44px;
        min-width: 44px;
        height: 44px;
        min-height: 44px;
        padding: 0;
        color: var(--accent-bright);
        background: transparent;
        border: 1px solid transparent;
        border-radius: 8px;
        font-size: 1.5rem;
        line-height: 1;
        cursor: pointer;
        touch-action: manipulation;
    }

    body.als-mobile-shell .als-mobile-launcher {
        justify-self: start;
    }

    .als-mobile-icon {
        width: 24px;
        height: 24px;
        flex: none;
    }

    body.als-mobile-shell .nav-actions {
        justify-content: end;
        align-items: center;
        gap: 4px;
        height: 44px;
    }

    body.als-mobile-shell .mail-badge {
        top: 0;
        right: 0;
    }

    body.als-mobile-shell .als-mobile-control:hover,
    body.als-mobile-shell .nav-icon-button:hover {
        background: var(--panel-hover);
    }

    body.als-mobile-shell :is(.als-mobile-header, .als-mobile-panel, .als-mobile-chat-dock, .chat-panel) :focus-visible {
        outline: 2px solid var(--accent-bright);
        outline-offset: 2px;
    }

    /* Auto height keeps vertical scrolling on the document. Untranslated pages
       get a wide canvas inside this horizontal scroller, keeping all controls
       reachable without changing their grids or hiding content. */
    body.als-mobile-shell > .als-mobile-content {
        --mobile-content-min-width: 900px;
        min-height: calc(100svh - var(--navbar-height) - var(--chat-row-height));
        min-height: calc(100dvh - var(--navbar-height) - var(--chat-row-height));
        overflow: auto;
        border-left: env(safe-area-inset-left, 0px) solid transparent;
        border-right: env(safe-area-inset-right, 0px) solid transparent;
    }

    body.als-mobile-shell > .als-mobile-content-responsive {
        --mobile-content-min-width: 0px;
        overflow: visible;
    }

    body.als-mobile-shell .als-shell-page {
        min-width: var(--mobile-content-min-width);
        min-height: inherit;
        height: auto;
        overflow: visible;
    }

    body.als-mobile-shell > .als-mobile-chat-dock {
        position: fixed;
        inset: auto 0 0;
        z-index: 1600;
        width: 100%;
        height: var(--chat-row-height);
        min-height: var(--chat-row-height);
        margin: 0;
        padding: 10px var(--mobile-edge-space) calc(10px + env(safe-area-inset-bottom, 0px));
        background: rgba(3, 11, 20, 0.98);
        border-top: 1px solid var(--border);
        pointer-events: none;
    }

    body.als-mobile-shell .chat-line {
        display: none;
    }

    body.als-mobile-shell .chat-button {
        width: var(--chat-button-size);
        height: var(--chat-button-size);
        min-height: 44px;
        box-shadow: var(--glow-small);
        pointer-events: auto;
    }

    body.als-mobile-shell .chat-button-label {
        font-size: 0.625rem;
        margin-top: 4px;
    }

    body.als-mobile-shell .chat-panel {
        z-index: 1700;
        right: var(--mobile-edge-space);
        bottom: calc(var(--chat-row-height) + 8px);
        width: min(420px, calc(100% - 2 * var(--mobile-edge-space)));
        height: 470px;
        max-height: calc(100svh - var(--navbar-height) - var(--chat-row-height) - 16px);
        max-height: calc(100dvh - var(--navbar-height) - var(--chat-row-height) - 16px);
        overflow-y: auto;
    }

    body.als-mobile-shell .chat-close-button,
    body.als-mobile-shell .chat-input-row :is(input, button) {
        min-width: 44px;
        min-height: 44px;
    }

    body.als-mobile-shell .chat-input-row input {
        font-size: 1rem; /* Prevent input-focus zoom in mobile Safari. */
    }

    html.als-mobile-root.als-shell-panel-open {
        overflow: hidden;
    }

    body.als-mobile-shell .als-mobile-panel {
        position: fixed;
        inset: 0;
        width: min(560px, calc(100% - 2 * var(--mobile-edge-space)));
        max-width: none;
        max-height: calc(100svh - var(--navbar-height) - var(--chat-row-height) - 16px);
        max-height: calc(100dvh - var(--navbar-height) - var(--chat-row-height) - 16px);
        margin: auto;
        padding: 16px;
        overflow: auto;
        overscroll-behavior: contain;
        color: var(--text-primary);
        background: var(--background-secondary);
        border: 1px solid var(--border-bright);
        border-radius: 14px;
        box-shadow: var(--glow-medium);
    }

    .als-mobile-panel::backdrop {
        background: rgba(0, 4, 10, 0.78);
    }

    .als-mobile-panel-heading {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 12px;
    }

    .als-mobile-panel-heading h2 {
        margin: 0;
        font-size: 1.125rem;
    }

    body.als-mobile-shell .als-mobile-panel .nav-left {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        height: auto;
        overflow: visible;
    }

    body.als-mobile-shell .als-mobile-panel .nav-item {
        min-width: 0;
        border: 1px solid var(--border);
        border-radius: 8px;
    }

    body.als-mobile-shell .als-mobile-panel .nav-item a {
        width: 100%;
        min-height: 60px;
        padding: 12px;
        font-size: 0.875rem;
        letter-spacing: normal;
        text-transform: none;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    body.als-mobile-shell .als-mobile-panel .account-menu {
        display: block;
        position: static;
        width: 100%;
        margin: 0;
        padding: 0;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    body.als-mobile-shell .als-mobile-panel .account-menu::before {
        display: none;
    }

    body.als-mobile-shell .als-mobile-panel .account-menu :is(a, button) {
        min-height: 48px;
        font-size: 0.875rem;
    }
}
