@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
    /* ── PALETTE ─────────────────────────────────────────────────── */
    /* Aurora over deep ink — same darkness, but atmospheric instead of flat */
    --bg: #08070f;
    --bg-deep: #04030a;
    --surface: rgba(22, 20, 35, 0.55);
    --surface-solid: #16142a;
    --surface-raised: rgba(30, 27, 48, 0.88);
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.10);
    --border-stronger: rgba(255, 255, 255, 0.16);

    --text: #f0eef7;
    --text-dim: #9c98ad;
    --text-faint: #6a6680;

    /* Primary accent shifts from tan → violet (kept variable name for compatibility) */
    --accent: #b9a4ff;
    --accent-bright: #cbb9ff;
    --accent-dim: #8b6df0;
    --accent-deeper: #6f4ce0;

    /* Secondary accents */
    --pink:    #f06aa8;
    --sky:     #7cc5f0;
    --amber:   #f0c460;
    --emerald: #5cd49a;

    --user-bg: rgba(120, 90, 200, 0.18);
    --assistant-bg: rgba(22, 20, 35, 0.50);
    --code-bg: rgba(0, 0, 0, 0.32);
    --danger: #f07a82;

    /* Reused tokens */
    --radius-sm: 6px;
    --radius-md: 9px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --rail-width: 56px;
    --column-width: 220px;        /* was 280px — Niyx wanted this smaller */
    --blur: blur(22px);
    --shadow-glow: 0 6px 18px rgba(139, 109, 240, 0.28);
}

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

body {
    font-family: 'DM Sans', system-ui, sans-serif;
    color: var(--text);
    display: flex;
    /* Aurora gradients over the deep ink base — gives the dark places to breathe */
    background:
        radial-gradient(ellipse 60% 45% at 8% 4%,   rgba(139, 92, 246, 0.20), transparent 60%),
        radial-gradient(ellipse 55% 55% at 92% 96%, rgba(56, 189, 248, 0.10), transparent 60%),
        radial-gradient(ellipse 70% 50% at 60% 50%, rgba(236, 72, 153, 0.07),  transparent 65%),
        var(--bg);
    background-attachment: fixed;
}

/* Subtle film grain — fixed in viewport so it doesn't scroll with content */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: radial-gradient(rgba(255,255,255,0.022) 1px, transparent 1px);
    background-size: 3px 3px;
    pointer-events: none;
    z-index: 0;
    opacity: 0.55;
}

/* Everything sits above the grain */
.rail, .context-column, .main, .modal-overlay, .los-sidebar, .los-main {
    position: relative;
    z-index: 1;
}

/* ====================================================================
   ICON RAIL — far left, always visible
   ==================================================================== */
.rail {
    width: var(--rail-width);
    background: rgba(8, 7, 16, 0.65);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 0;
    flex-shrink: 0;
    z-index: 10;
}

/* Rail logo = the "you are here" app marker, always at top */
.rail-logo {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    margin-bottom: 18px;
    user-select: none;
    border-radius: 11px;
    background: linear-gradient(135deg, rgba(185, 164, 255, 0.22), rgba(111, 76, 224, 0.10));
    border: 0.5px solid rgba(185, 164, 255, 0.20);
    box-shadow:
        0 4px 16px rgba(139, 92, 246, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    color: var(--accent-bright);
    position: relative;
}

.rail-logo::after {
    content: "";
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    background: linear-gradient(180deg, var(--accent), var(--accent-deeper));
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(185, 164, 255, 0.55);
}

.rail-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: none;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
    color: var(--text-dim);
    font-size: 15px;
    cursor: pointer;
    position: relative;
    font-family: inherit;
    text-decoration: none;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}

/* Switcher button — sits at the bottom of the rail, jumps to the other app.
   Distinct look: outlined, slightly faded, hover brightens. */
.rail-switcher {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    border: 0.5px solid var(--border-strong);
    background: rgba(255, 255, 255, 0.025);
    margin-bottom: 0;
    margin-top: 6px;
    opacity: 0.78;
    font-size: 17px;
    color: var(--text);
    text-decoration: none;
}

.rail-switcher:hover {
    opacity: 1;
    border-color: rgba(185, 164, 255, 0.30);
    background: rgba(185, 164, 255, 0.08);
    color: var(--text);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(139, 109, 240, 0.18);
}

.rail-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

.rail-btn.active {
    color: var(--accent);
    background: linear-gradient(135deg, rgba(185, 164, 255, 0.20), rgba(139, 109, 240, 0.06));
    border-color: rgba(185, 164, 255, 0.24);
}

.rail-btn.active::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    background: linear-gradient(180deg, var(--accent), var(--accent-deeper));
    border-radius: 2px;
    box-shadow: 0 0 6px rgba(185, 164, 255, 0.4);
}

.rail-spacer {
    flex: 1;
}

/* Tooltips on rail icons (desktop only) */
.rail-btn[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface-raised);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
}

/* ====================================================================
   CONTEXT COLUMN — content depends on active rail view
   Narrower than before — Niyx asked to shrink this.
   ==================================================================== */
.context-column {
    width: var(--column-width);
    background: rgba(14, 12, 26, 0.55);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
}

/* Each view (conversations/tracker/ideas/memory) lives in its own .view */
.view {
    display: none;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

.view.active {
    display: flex;
}

.view-header {
    padding: 16px 14px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.view-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.view-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: -0.01em;
}

.view-subtitle {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

.icon-btn {
    background: linear-gradient(135deg, rgba(185, 164, 255, 0.16), rgba(185, 164, 255, 0.05));
    border: 1px solid rgba(185, 164, 255, 0.22);
    border-radius: var(--radius-sm);
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.icon-btn:hover {
    border-color: rgba(185, 164, 255, 0.4);
    background: linear-gradient(135deg, rgba(185, 164, 255, 0.22), rgba(185, 164, 255, 0.08));
    transform: translateY(-1px);
}

.icon-btn.ghost {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border-strong);
    color: var(--text-dim);
}

.icon-btn.ghost:hover {
    border-color: rgba(185, 164, 255, 0.32);
    color: var(--text);
}

/* ====================================================================
   CONVERSATIONS VIEW
   ==================================================================== */
.conv-search-wrap {
    padding: 6px 12px 10px;
}

.conv-search {
    width: 100%;
    padding: 7px 11px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.conv-search:focus {
    border-color: rgba(185, 164, 255, 0.35);
    box-shadow: 0 0 0 2px rgba(185, 164, 255, 0.08);
}

.conv-search::placeholder {
    color: var(--text-dim);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 6px 8px;
}

.conv-group-label {
    font-size: 10px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    padding: 10px 8px 4px;
    font-weight: 500;
}

.conv-item {
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 12.5px;
    color: var(--text-dim);
    margin: 1px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
    transition: color 0.12s, background 0.12s;
    position: relative;
}

.conv-item:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.025);
}

.conv-item.active {
    color: var(--accent);
    background: linear-gradient(90deg, rgba(185, 164, 255, 0.12), rgba(185, 164, 255, 0.02));
    padding-left: 12px;
}

.conv-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 2px;
    background: linear-gradient(180deg, var(--accent), var(--accent-deeper));
    border-radius: 2px;
}

/* ====================================================================
   TRACKER VIEW
   ==================================================================== */
.tracker-progress {
    padding: 14px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.tracker-ring {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.tracker-ring-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.07);
    stroke-width: 4;
}

.tracker-ring-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 4;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.4s ease;
    filter: drop-shadow(0 0 4px rgba(185, 164, 255, 0.4));
}

.tracker-ring-text {
    font-size: 10.5px;
    fill: var(--accent);
    font-weight: 500;
    text-anchor: middle;
    dominant-baseline: middle;
    font-family: inherit;
}

.tracker-progress-info {
    flex: 1;
    min-width: 0;
}

.tracker-progress-title {
    font-size: 12.5px;
    color: var(--text);
    font-weight: 500;
}

.tracker-progress-meta {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

.tracker-items {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
}

.tracker-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.12s;
}

.tracker-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.tracker-checkbox {
    width: 16px;
    height: 16px;
    border-radius: 5px;
    border: 1.5px solid rgba(255, 255, 255, 0.18);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.tracker-checkbox:hover {
    border-color: rgba(185, 164, 255, 0.45);
}

.tracker-checkbox.checked {
    background: linear-gradient(135deg, var(--accent), var(--accent-deeper));
    border-color: transparent;
    box-shadow: 0 2px 6px rgba(139, 109, 240, 0.35);
}

.tracker-checkbox.checked::after {
    content: "✓";
    color: white;
    font-size: 11px;
    font-weight: 700;
}

.tracker-item-label {
    font-size: 12.5px;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tracker-item.checked .tracker-item-label {
    color: var(--text-dim);
    text-decoration: line-through;
    text-decoration-color: rgba(255, 255, 255, 0.18);
}

.tracker-remove {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    opacity: 0;
    padding: 0 4px;
    line-height: 1;
    font-family: inherit;
    transition: opacity 0.12s, color 0.12s;
}

.tracker-item:hover .tracker-remove,
.idea-item:hover .tracker-remove {
    opacity: 0.5;
}

.tracker-remove:hover {
    opacity: 1 !important;
    color: var(--danger);
}

/* History collapsible inside tracker */
.tracker-history-btn {
    margin: 8px 12px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.tracker-history-btn:hover {
    border-color: rgba(185, 164, 255, 0.32);
    color: var(--text);
}

.tracker-history {
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
}

.history-entry {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.5;
}

.history-entry:last-child {
    border-bottom: none;
}

.history-entry strong {
    color: var(--accent);
    font-weight: 500;
}

/* ====================================================================
   IDEAS VIEW
   ==================================================================== */
.filter-row {
    padding: 10px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    border-bottom: 1px solid var(--border);
}

.filter-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 3px 10px;
    font-size: 10.5px;
    color: var(--text-dim);
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: all 0.12s;
}

.filter-btn:hover {
    border-color: rgba(185, 164, 255, 0.32);
    color: var(--text);
}

.filter-btn.active {
    background: linear-gradient(135deg, rgba(185, 164, 255, 0.20), rgba(185, 164, 255, 0.06));
    border-color: rgba(185, 164, 255, 0.30);
    color: var(--accent);
}

.idea-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.idea-item {
    padding: 11px 13px;
    margin: 6px 0;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    position: relative;
    transition: border-color 0.15s, background 0.15s;
}

.idea-item:hover {
    border-color: var(--border-stronger);
    background: rgba(255, 255, 255, 0.04);
}

.idea-content {
    font-size: 12.5px;
    color: var(--text);
    line-height: 1.55;
    margin-bottom: 6px;
    padding-right: 20px;
    word-wrap: break-word;
}

.idea-content strong {
    color: var(--accent);
    font-weight: 500;
}

.idea-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 10px;
    color: var(--text-faint);
}

.idea-meta .category-tag {
    background: rgba(185, 164, 255, 0.10);
    color: var(--text-dim);
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 10px;
}

.idea-item .tracker-remove {
    position: absolute;
    top: 8px;
    right: 8px;
}

/* Empty state inside views */
.view-empty {
    padding: 24px 18px;
    text-align: center;
    color: var(--text-dim);
    font-size: 12.5px;
    line-height: 1.6;
}

/* ====================================================================
   VIEW FOOTER — input rows at the bottom of context column views
   ==================================================================== */
.view-footer {
    padding: 12px 12px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.18);
    flex-shrink: 0;
}

.input-cluster {
    display: flex;
    gap: 6px;
    align-items: center;
}

.input-cluster input,
.input-cluster textarea {
    flex: 1;
    padding: 8px 11px;
    background: rgba(0, 0, 0, 0.30);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input-cluster input:focus,
.input-cluster textarea:focus {
    border-color: rgba(185, 164, 255, 0.40);
    box-shadow: 0 0 0 2px rgba(185, 164, 255, 0.08);
}

.input-cluster input::placeholder {
    color: var(--text-faint);
}

.input-cluster-stacked {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ====================================================================
   MEMORY VIEW
   ==================================================================== */
.memory-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
}

.memory-summary {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-bottom: 12px;
    padding: 0 4px;
}

.memory-entry {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.memory-entry:last-child {
    border-bottom: none;
}

.memory-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
    gap: 8px;
}

.memory-source {
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.memory-meta {
    font-size: 10px;
    color: var(--text-faint);
    flex-shrink: 0;
}

.memory-text {
    font-size: 11.5px;
    color: var(--text-dim);
    line-height: 1.55;
    white-space: pre-wrap;
}

/* ====================================================================
   MAIN CHAT AREA
   ==================================================================== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
}

.topbar {
    padding: 12px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    height: 56px;
    background: rgba(8, 7, 16, 0.30);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 6px;
}

.chat-title {
    font-size: 13.5px;
    color: var(--text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background 0.12s;
    min-width: 0;
    max-width: 50%;
    letter-spacing: -0.01em;
}

.chat-title:hover {
    background: rgba(255, 255, 255, 0.04);
}

.chat-title.editing {
    background: rgba(0, 0, 0, 0.3);
    cursor: text;
    outline: 1px solid rgba(185, 164, 255, 0.45);
}

.chat-meta {
    font-size: 11px;
    color: var(--text-dim);
    padding-left: 10px;
    border-left: 1px solid var(--border-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.topbar-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 13px;
    padding: 5px 9px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    line-height: 1;
}

.topbar-btn:hover {
    border-color: rgba(185, 164, 255, 0.32);
    color: var(--text);
}

.topbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.topbar-divider {
    width: 1px;
    height: 16px;
    background: var(--border-strong);
}

/* Temperature popover */
.temp-wrap {
    position: relative;
}

.temp-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface-raised);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    z-index: 50;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    min-width: 180px;
    display: none;
}

.temp-popover.open {
    display: block;
}

.temp-popover-label {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
}

.temp-popover-label span:last-child {
    color: var(--accent);
    font-weight: 500;
}

.temp-popover input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

/* Avatar in top-right */
.avatar-wrap {
    position: relative;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-deeper));
    border: 1.5px solid rgba(185, 164, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    user-select: none;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(139, 109, 240, 0.25);
}

.avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 0 0 3px rgba(185, 164, 255, 0.12), 0 2px 8px rgba(139, 109, 240, 0.35);
}

.avatar-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface-raised);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 6px;
    z-index: 50;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    min-width: 180px;
    display: none;
}

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

.avatar-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    background: none;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background 0.12s;
}

.avatar-menu-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.avatar-menu-item.danger:hover {
    background: rgba(240, 122, 130, 0.10);
    color: var(--danger);
}

.avatar-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* ====================================================================
   MESSAGES
   ==================================================================== */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
    gap: 14px;
    text-align: center;
    padding: 40px 20px;
}

.empty-state-glyph {
    font-size: 56px;
    opacity: 0.85;
    line-height: 1;
    filter: drop-shadow(0 0 24px rgba(185, 164, 255, 0.25));
}

.empty-state-title {
    font-size: 17px;
    color: var(--text);
    font-weight: 500;
    letter-spacing: -0.01em;
    background: linear-gradient(135deg, #f0eef7, var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.empty-state-sub {
    font-size: 13px;
    color: var(--text-dim);
    max-width: 320px;
    line-height: 1.55;
}

.empty-state-cta {
    margin-top: 8px;
    padding: 10px 22px;
    background: linear-gradient(135deg, var(--accent), var(--accent-deeper));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow-glow);
    transition: transform 0.15s, box-shadow 0.15s;
}

.empty-state-cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(139, 109, 240, 0.35);
}

.message {
    max-width: 75%;
    padding: 11px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(139, 109, 240, 0.22), rgba(99, 76, 200, 0.16));
    border: 1px solid rgba(185, 164, 255, 0.18);
    border-radius: 16px 16px 4px 16px;
    white-space: pre-wrap;
}

.message.assistant {
    align-self: flex-start;
    background: var(--assistant-bg);
    border: 1px solid var(--border);
    border-radius: 16px 16px 16px 4px;
}

.message.system-message {
    align-self: center;
    max-width: 60%;
    background: transparent;
    border: 1px dashed var(--border-strong);
    opacity: 0.75;
    font-size: 12px;
    border-radius: var(--radius-md);
}

.message .timestamp {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 6px;
}

.message .internal-btn {
    font-size: 11px;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    margin-top: 6px;
    font-family: inherit;
    padding: 0;
}

.message .internal-btn:hover {
    text-decoration: underline;
}

/* Typing animation */
.typing-dots {
    color: var(--text-dim);
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Memory search indicator */
.memory-search-indicator {
    font-size: 11px;
    color: var(--accent);
    padding: 4px 0;
    opacity: 0.85;
}

/* ====================================================================
   MAIN INPUT
   ==================================================================== */
.input-area {
    padding: 14px 22px 18px;
    flex-shrink: 0;
}

.cost-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    padding: 0 4px;
    min-height: 14px;
}

.token-display,
.daily-cost {
    font-size: 10.5px;
    color: var(--text-faint);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
}

.input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.input-row textarea {
    flex: 1;
    padding: 12px 16px;
    background: rgba(22, 20, 35, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input-row textarea:focus {
    border-color: rgba(185, 164, 255, 0.40);
    box-shadow: 0 0 0 3px rgba(185, 164, 255, 0.08);
}

.input-row textarea::placeholder {
    color: var(--text-faint);
}

.input-row button {
    padding: 11px 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-deeper));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 500;
    flex-shrink: 0;
    box-shadow: var(--shadow-glow);
    transition: transform 0.12s, box-shadow 0.15s, opacity 0.15s;
    line-height: 1;
}

.input-row button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(139, 109, 240, 0.35);
}

.input-row button:active {
    transform: translateY(0);
}

.input-row button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ====================================================================
   MODALS (Settings, Internal viewer)
   ==================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(4, 3, 10, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

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

.modal {
    background: var(--surface-raised);
    backdrop-filter: blur(26px);
    -webkit-backdrop-filter: blur(26px);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 580px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.modal-header {
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: -0.01em;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    line-height: 1;
    font-family: inherit;
    transition: color 0.15s;
}

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

.modal-body {
    padding: 20px 22px;
    overflow-y: auto;
}

.modal-body label {
    display: block;
    font-size: 12.5px;
    color: var(--text-dim);
    margin-bottom: 8px;
    margin-top: 4px;
}

.modal-body textarea {
    width: 100%;
    padding: 12px;
    background: rgba(0, 0, 0, 0.32);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12.5px;
    resize: vertical;
    outline: none;
    margin-bottom: 12px;
    line-height: 1.55;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.modal-body textarea:focus {
    border-color: rgba(185, 164, 255, 0.40);
    box-shadow: 0 0 0 2px rgba(185, 164, 255, 0.08);
}

.modal-body pre {
    white-space: pre-wrap;
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
}

.modal-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 18px 0;
}

.setting-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.30);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

select.setting-input {
    cursor: pointer;
    appearance: auto;
}
.setting-input:focus {
    border-color: rgba(185, 164, 255, 0.40);
    box-shadow: 0 0 0 2px rgba(185, 164, 255, 0.08);
}

.save-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--accent), var(--accent-deeper));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(139, 109, 240, 0.25);
}

.save-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(139, 109, 240, 0.35);
}

.save-btn.secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
    font-size: 12px;
    padding: 8px 14px;
    box-shadow: none;
}

.save-btn.secondary:hover {
    box-shadow: none;
    color: var(--text);
    border-color: rgba(185, 164, 255, 0.32);
}

.btn-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

#systemPromptPreview {
    display: none;
    margin-top: 12px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.32);
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

/* ====================================================================
   MARKDOWN INSIDE MESSAGES
   ==================================================================== */
.message-content p { margin: 0 0 8px 0; }
.message-content p:last-child { margin: 0; }
.message-content strong { color: var(--accent-bright); font-weight: 500; }
.message-content em { font-style: italic; }
.message-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.message-content a:hover { color: var(--accent-bright); }

.message-content code {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12px;
    color: var(--accent-bright);
}

.message-content pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin: 8px 0;
    overflow-x: auto;
    line-height: 1.5;
}

.message-content pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 12px;
    color: var(--text);
}

.message-content ul,
.message-content ol {
    margin: 4px 0 8px 20px;
}

.message-content li {
    margin-bottom: 2px;
}

.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-dim);
    font-style: italic;
}

.message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
    width: 100%;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-strong);
    padding: 6px 10px;
    text-align: left;
}

.message-content th {
    background: var(--code-bg);
    color: var(--accent);
    font-weight: 500;
}

.message-content hr {
    border: none;
    border-top: 1px solid var(--border-strong);
    margin: 12px 0;
}

/* ====================================================================
   CONVERSATION CONTEXT MENU
   ==================================================================== */
.context-menu {
    position: fixed;
    background: var(--surface-raised);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 4px;
    z-index: 200;
    min-width: 140px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.context-menu button {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.context-menu button:hover {
    background: rgba(255, 255, 255, 0.04);
}

.context-menu button.danger:hover {
    background: rgba(240, 122, 130, 0.10);
    color: var(--danger);
}

/* ====================================================================
   SCROLLBARS
   ==================================================================== */
::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.10);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(185, 164, 255, 0.30);
}

/* ====================================================================
   MOBILE
   ==================================================================== */
@media (max-width: 768px) {
    .rail {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 60;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .rail.open {
        transform: translateX(0);
    }

    .context-column {
        position: fixed;
        left: var(--rail-width);
        top: 0;
        bottom: 0;
        z-index: 55;
        transform: translateX(calc(-100% - var(--rail-width)));
        transition: transform 0.2s ease;
        width: calc(100vw - var(--rail-width));
        max-width: 300px;
    }

    .rail.open ~ .context-column {
        transform: translateX(0);
    }

    .menu-btn {
        display: block;
    }

    /* Hide rail tooltips on touch */
    .rail-btn[data-tooltip]:hover::after {
        display: none;
    }

    .message {
        max-width: 88%;
    }

    .message.system-message {
        max-width: 80%;
    }

    .chat-meta {
        display: none;
    }

    .messages {
        padding: 16px 14px;
    }

    .topbar {
        padding: 10px 14px;
    }

    .input-area {
        padding: 10px 14px 14px;
    }

    /* Backdrop when rail open on mobile */
    .rail.open ~ .mobile-backdrop {
        display: block;
    }
}

.mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 40;
}

/* ====================================================================
   LOGIN PAGE
   ==================================================================== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.login-box {
    background: var(--surface-raised);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    width: 360px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    position: relative;
    z-index: 1;
}

/* A soft halo behind the login card */
.login-box::before {
    content: "";
    position: absolute;
    inset: -40px;
    background: radial-gradient(circle, rgba(185, 164, 255, 0.15), transparent 60%);
    z-index: -1;
    pointer-events: none;
}

.login-logo {
    font-size: 40px;
    margin-bottom: 14px;
    line-height: 1;
    filter: drop-shadow(0 0 28px rgba(185, 164, 255, 0.35));
}

.login-box h1 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 28px;
    letter-spacing: 0.3px;
    background: linear-gradient(135deg, var(--text), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-box input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.32);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    margin-bottom: 14px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.login-box input:focus {
    border-color: rgba(185, 164, 255, 0.45);
    box-shadow: 0 0 0 3px rgba(185, 164, 255, 0.10);
}

.login-box button {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-deeper));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow-glow);
    transition: transform 0.12s, box-shadow 0.15s;
}

.login-box button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(139, 109, 240, 0.40);
}

.login-error {
    color: var(--danger);
    font-size: 12.5px;
    margin-bottom: 12px;
}

/* --- Weekly tracker modal --- */
.modal-wide {
    max-width: 720px;
}

.modal-wide .modal-header {
    gap: 12px;
}

.week-nav-btn {
    background: none;
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s;
}

.week-nav-btn:hover {
    color: var(--text);
    border-color: var(--accent-dim);
    background: rgba(185, 164, 255, 0.08);
}

.weekly-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.weekly-row {
    display: grid;
    grid-template-columns: minmax(120px, 1.5fr) repeat(7, 1fr);
    border-bottom: 1px solid var(--border);
}

.weekly-row:last-child {
    border-bottom: none;
}

.weekly-row.weekly-inactive {
    opacity: 0.5;
}

.weekly-header {
    border-bottom: 1px solid var(--border-strong);
}

.weekly-cell {
    padding: 10px 6px;
    text-align: center;
    font-size: 13px;
    color: var(--text-dim);
    transition: background 0.12s;
}

.weekly-label {
    text-align: left;
    padding-left: 12px;
    color: var(--text);
    font-size: 13px;
    font-weight: 400;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.weekly-day-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
}

.weekly-day-name {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-faint);
}

.weekly-day-num {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dim);
}

.weekly-today {
    background: rgba(185, 164, 255, 0.06);
}

.weekly-today .weekly-day-num {
    color: var(--accent);
}

.weekly-check {
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
}

.weekly-check:hover {
    background: rgba(185, 164, 255, 0.1);
}

.weekly-check.checked {
    color: var(--accent);
    font-weight: 600;
    font-size: 15px;
}

.weekly-loading {
    padding: 32px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

/* --- Load more messages banner --- */
.load-more-banner {
    text-align: center;
    padding: 10px 0;
    color: var(--text-dim);
    font-size: 12px;
    letter-spacing: 0.3px;
}

.date-separator {
    text-align: center;
    padding: 18px 0 8px;
    color: var(--text-faint);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    position: relative;
}
.date-separator::before,
.date-separator::after {
    content: "";
    position: absolute;
    top: 50%;
    width: calc(50% - 80px);
    height: 1px;
    background: var(--border);
}
.date-separator::before { left: 0; }
.date-separator::after { right: 0; }
