/* ── Tips page layout ──────────────────────────────────────────────────────── */

.tips-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px); /* subtract nav height */
    overflow: hidden;
}

/* ── Loading / error states ────────────────────────────────────────────────── */

.tips-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 1rem;
    color: var(--color-muted);
}

.tips-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #222;
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.tips-error {
    padding: 2rem;
    text-align: center;
    color: #ff6b6b;
}

.hidden { display: none !important; }

/* ── Toolbar ───────────────────────────────────────────────────────────────── */

.tips-toolbar {
    flex-shrink: 0;
    background: var(--color-bg);
    padding: 0.75rem 1rem 0.5rem;
    border-bottom: 1px solid #1e1e1e;
    z-index: 10;
    /* Center the toolbar column so it lines up with the list below */
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
}

.tips-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--color-surface);
    border-radius: 10px;
    padding: 0.5rem 0.75rem;
}

.tips-search svg {
    flex-shrink: 0;
    color: var(--color-muted);
}

.tips-search input {
    flex: 1;
    background: none;
    border: none;
    color: var(--color-text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    min-width: 0;
}

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

.search-clear {
    background: none;
    border: none;
    color: var(--color-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 2px;
    line-height: 1;
    display: flex;
    align-items: center;
}

.search-clear:hover { color: var(--color-text); }

/* ── Toolbar top row ───────────────────────────────────────────────────────── */

.tips-toolbar-top {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.tips-toolbar-top .tips-search {
    flex: 1;
    margin-bottom: 0;
}

.tips-controls {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.ctrl-btn {
    background: var(--color-surface);
    border: 1px solid #2e2e2e;
    border-radius: 999px;
    color: var(--color-muted);
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    padding: 4px 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.ctrl-btn:hover { color: var(--color-text); border-color: #444; }

.ctrl-btn.active {
    background: rgba(78, 205, 196, 0.12);
    color: var(--color-accent);
    border-color: rgba(78, 205, 196, 0.35);
}

/* ── Tag bar ───────────────────────────────────────────────────────────────── */

.tips-tag-section {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 2px 0 4px;
}

.tag-bar-label {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--color-muted);
    padding-top: 4px;
    white-space: nowrap;
}

.tips-tag-bar {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 2px 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
    min-height: 30px;
    flex: 1;
}

.tips-tag-bar.expanded {
    overflow-x: visible;
    flex-wrap: wrap;
}

.tips-tag-bar::-webkit-scrollbar { display: none; }

.tag-chip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
    border: 1px solid transparent;
}

.tag-chip:active { transform: scale(0.95); }

.tag-chip.neutral {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: #2e2e2e;
}

.tag-chip.selected {
    /* background and color set inline from tag.colorHex */
    border-color: transparent;
}

.tag-chip.excluded {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: #2e2e2e;
    text-decoration: line-through;
}

/* ── Filter logic + count ──────────────────────────────────────────────────── */

.filter-logic {
    font-size: 0.78rem;
    color: var(--color-muted);
    padding: 4px 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tips-count {
    font-size: 0.78rem;
    color: var(--color-muted);
    padding: 3px 0 0;
}

/* ── Main layout: centered list, modal-style detail card overlay ──────────── */

.tips-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Detail is hidden until a tip is opened. List stays rendered behind the
   modal so it shows through the dimmed backdrop. */
.tips-layout:not(.detail-active) .tips-detail-panel,
.tips-layout:not(.detail-active) .detail-backdrop { display: none; }

/* Backdrop dims the page below the nav — header stays fully visible/clickable. */
.detail-backdrop {
    position: fixed;
    top: 80px;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 40;
    cursor: pointer;
}

/* ── List panel ────────────────────────────────────────────────────────────── */

.tips-list-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    /* Center the list column so the page reads as a single centered column
       on wide screens. The detail panel uses the same column when open. */
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
}

.tips-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.tip-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #141414;
    cursor: pointer;
    transition: background 0.12s;
    -webkit-tap-highlight-color: transparent;
}

.tip-item:hover { background: var(--color-surface); }

.tip-item.active {
    background: rgba(78, 205, 196, 0.06);
    border-left: 3px solid var(--color-accent);
    padding-left: calc(1rem - 3px);
}

.tip-item-content {
    flex: 1;
    min-width: 0;
}

.tip-item-title {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--color-text);
    transition: opacity 0.2s, font-weight 0.2s;
}

.tip-item-title.read {
    font-weight: 400;
    opacity: 0.65;
}

.tip-item-preview {
    font-size: 0.82rem;
    color: var(--color-muted);
    margin-top: 2px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tip-item-tags {
    display: flex;
    gap: 4px;
    margin-top: 5px;
    flex-wrap: wrap;
}

.tip-item-tag {
    font-size: 0.7rem;
    padding: 1px 7px;
    border-radius: 999px;
    font-weight: 500;
    opacity: 0.7;
}

.unread-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-accent);
    transition: opacity 0.3s;
}

/* ── Detail panel: top-anchored modal card on top of dimmed list ──────────── */

.tips-detail-panel {
    position: fixed;
    top: calc(80px + 1rem);
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 4rem);
    max-width: 760px;
    max-height: calc(100vh - 80px - 4rem);
    z-index: 50;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #1c1c1c;
    border: 1px solid #383838;
    border-radius: 16px;
    box-shadow: 0 24px 72px rgba(0, 0, 0, 0.7);
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid #2a2a2a;
    flex-shrink: 0;
}

.detail-back {
    background: none;
    border: none;
    color: var(--color-muted);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 8px;
    margin-left: -8px;
}

.detail-back:hover { color: var(--color-text); }

.detail-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.detail-nav-btn {
    background: rgba(78, 205, 196, 0.1);
    border: 1px solid rgba(78, 205, 196, 0.4);
    border-radius: 8px;
    color: var(--color-accent);
    padding: 0.45rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.15s, opacity 0.15s;
}

.detail-nav-btn:hover:not(:disabled) { background: rgba(78, 205, 196, 0.2); }

.detail-nav-btn:disabled {
    background: transparent;
    border-color: #2a2a2a;
    color: var(--color-muted);
    opacity: 0.4;
    cursor: default;
}

.detail-position {
    font-size: 0.8rem;
    color: var(--color-muted);
    min-width: 4ch;
    text-align: center;
}

.detail-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1.25rem 3rem;
}

#detail-title {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
    margin-bottom: 0.75rem;
    color: var(--color-text);
}

.detail-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.detail-tag {
    font-size: 0.78rem;
    padding: 3px 10px;
    border-radius: 999px;
    font-weight: 500;
}

/* ── Formatted body HTML ───────────────────────────────────────────────────── */

.detail-formatted-body {
    font-size: 0.97rem;
    line-height: 1.65;
    color: var(--color-text);
}

.detail-formatted-body p {
    margin-bottom: 0.85rem;
}

.detail-formatted-body h1,
.detail-formatted-body h2,
.detail-formatted-body h3 {
    font-weight: 600;
    margin: 1.25rem 0 0.5rem;
    letter-spacing: -0.01em;
}

.detail-formatted-body ul,
.detail-formatted-body ol {
    padding-left: 1.4rem;
    margin-bottom: 0.85rem;
}

.detail-formatted-body li { margin-bottom: 0.35rem; }

.detail-formatted-body strong { font-weight: 600; }
.detail-formatted-body em { font-style: italic; }

.detail-formatted-body img {
    max-width: 100%;
    border-radius: 8px;
    margin: 0.5rem 0;
    display: block;
}

.detail-formatted-body a {
    color: var(--color-accent);
    text-decoration: none;
}

.detail-formatted-body a:hover { text-decoration: underline; }

/* tip:// internal links */
.tip-link {
    color: var(--color-accent);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.tip-link::before { content: "→ "; }
.tip-link:hover { text-decoration: underline; }

/* ── Deep dive ─────────────────────────────────────────────────────────────── */

.dive-deeper-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color-accent);
    background: rgba(78, 205, 196, 0.08);
    border: 1px solid rgba(78, 205, 196, 0.2);
    border-radius: 999px;
    padding: 0.45rem 1rem;
    cursor: pointer;
    font-family: inherit;
    margin-top: 1.25rem;
    transition: background 0.15s;
}

.dive-deeper-btn:hover { background: rgba(78, 205, 196, 0.15); }

.dive-deeper-btn .dive-arrow {
    transition: transform 0.2s;
    display: inline-block;
}

.dive-deeper-btn.open .dive-arrow { transform: rotate(90deg); }

.deep-dive-content {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #222;
    font-size: 0.97rem;
    line-height: 1.65;
    color: var(--color-text);
}

/* deep dive body inherits same HTML styles */
.deep-dive-content p { margin-bottom: 0.85rem; }
.deep-dive-content ul,
.deep-dive-content ol { padding-left: 1.4rem; margin-bottom: 0.85rem; }
.deep-dive-content li { margin-bottom: 0.35rem; }
.deep-dive-content strong { font-weight: 600; }
.deep-dive-content em { font-style: italic; }
.deep-dive-content img { max-width: 100%; border-radius: 8px; margin: 0.5rem 0; display: block; }
.deep-dive-content a { color: var(--color-accent); text-decoration: none; }
.deep-dive-content a:hover { text-decoration: underline; }

/* ── Empty state ───────────────────────────────────────────────────────────── */

.tips-empty {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--color-muted);
    font-size: 0.95rem;
}

/* ── Split handle (legacy, hidden — current layout doesn't use it) ────────── */

.split-handle { display: none; }

/* ── Group headers ─────────────────────────────────────────────────────────── */

.group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.55rem 1rem;
    border-bottom: 1px solid #252525;
    border-top: 2px solid #252525;
    cursor: pointer;
    background: #111;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: sticky;
    top: 0;
    z-index: 2;
}

.group-header:hover { background: #181818; }

.group-chevron {
    font-size: 0.65rem;
    color: var(--color-muted);
    flex-shrink: 0;
    width: 10px;
    text-align: center;
}

.group-name {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    flex: 1;
}

.group-count {
    font-size: 0.73rem;
    color: var(--color-muted);
    background: #1e1e1e;
    border-radius: 999px;
    padding: 2px 9px;
    font-weight: 500;
}

/* ── Responsive: mobile (<=900px) ──────────────────────────────────────────── */

@media (max-width: 900px) {
    .tips-page { height: auto; overflow: visible; }

    .tips-toolbar-top { flex-wrap: wrap; }

    .tips-controls { flex-wrap: wrap; }

    .split-handle { display: none; }

    .tips-layout {
        flex-direction: column;
        overflow: visible;
        min-height: 0;
    }

    .tips-list-panel {
        flex: none;
        border-right: none;
        border-bottom: 1px solid #1e1e1e;
        overflow: visible;
        max-height: none;
    }

    .tips-list {
        overflow: visible;
        max-height: none;
    }

    /* Mobile: detail covers the viewport edge-to-edge — no card chrome. */
    .tips-detail-panel {
        position: fixed;
        inset: 0;
        top: 0;
        left: 0;
        transform: none;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background: var(--color-bg);
    }

    /* No backdrop needed on mobile — detail covers the whole viewport. */
    .detail-backdrop { display: none !important; }

    .detail-scroll {
        padding: 1.25rem 1rem 3rem;
    }
}

@media (max-width: 500px) {
    .tips-toolbar { padding: 0.6rem 0.75rem 0.4rem; }
    #detail-title { font-size: 1.25rem; }
    .detail-scroll { padding: 1rem 0.75rem 3rem; }
}

/* Locked tag chip (driven by experience mode) */
.tag-chip[data-locked="1"] { cursor: pointer; }

/* ── Profile / Onboarding modal ────────────────────────────────────────────── */

.profile-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.profile-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.profile-content {
    position: relative;
    background: var(--color-surface);
    border: 1px solid #2a2a2a;
    border-radius: 16px;
    padding: 2rem;
    max-width: 520px;
    width: 100%;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    animation: profile-in 0.18s ease-out;
}

.profile-content.profile-confirm {
    max-width: 420px;
    padding: 1.75rem;
}

.profile-confirm-message {
    color: var(--color-muted);
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0.75rem 0 1.5rem;
}

@keyframes profile-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.profile-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: transparent;
    border: none;
    color: var(--color-muted);
    font-size: 1.6rem;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.profile-close:hover {
    background: #222;
    color: var(--color-text);
}

#profile-modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 0.35rem;
}

.profile-subtitle {
    color: var(--color-muted);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.profile-section {
    margin-bottom: 1.5rem;
}

.profile-section-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.6rem;
}

.profile-section-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
}

.profile-section-label-row .profile-section-label {
    margin-bottom: 0;
}

.profile-vehicle-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--color-muted);
    cursor: pointer;
    user-select: none;
}

.profile-vehicle-toggle input {
    margin: 0;
    accent-color: var(--color-accent);
    cursor: pointer;
}

.profile-vehicle-toggle:hover { color: var(--color-text); }

.profile-section-hint {
    font-size: 0.85rem;
    color: var(--color-muted);
    margin-bottom: 0.6rem;
}

/* Experience cards */
.profile-experience {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.profile-experience-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    background: #1c1c1c;
    border: 1.5px solid transparent;
    border-radius: 10px;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.profile-experience-card:hover {
    background: #232323;
}
.profile-experience-card[aria-checked="true"] {
    background: rgba(78, 205, 196, 0.08);
    border-color: var(--color-accent);
}

.profile-exp-icon {
    font-size: 1.3rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.profile-exp-text {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.profile-exp-title {
    font-size: 1rem;
    font-weight: 600;
}

.profile-exp-sub {
    font-size: 0.82rem;
    color: var(--color-muted);
    margin-top: 1px;
}

.profile-exp-check {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1.5px solid #444;
    flex-shrink: 0;
    position: relative;
    transition: border-color 0.15s, background 0.15s;
}
.profile-experience-card[aria-checked="true"] .profile-exp-check {
    border-color: var(--color-accent);
    background: var(--color-accent);
}
.profile-experience-card[aria-checked="true"] .profile-exp-check::after {
    content: "";
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M3.5 8.5l3 3 6-6.5' stroke='%23000' stroke-width='2.2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>") center/14px no-repeat;
}

/* Vehicle grid */
.profile-vehicles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.profile-vehicle-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.65rem 0.85rem;
    background: #1c1c1c;
    border: 1.5px solid transparent;
    border-radius: 10px;
    color: var(--color-text);
    font: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.profile-vehicle-card:hover {
    background: #232323;
}
.profile-vehicle-card[aria-pressed="true"] {
    background: rgba(78, 205, 196, 0.08);
    border-color: var(--color-accent);
}
.profile-vehicle-card[aria-pressed="true"]::after {
    content: "✓";
    color: var(--color-accent);
    font-weight: 700;
}

/* Actions */
.profile-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.75rem;
}

.profile-btn {
    padding: 0.7rem 1.4rem;
    font: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    border: 1.5px solid transparent;
}

.profile-btn-ghost {
    background: transparent;
    color: var(--color-muted);
    border-color: #333;
}
.profile-btn-ghost:hover {
    color: var(--color-text);
    border-color: #555;
}

.profile-btn-primary {
    background: var(--color-accent);
    color: #001a1a;
}
.profile-btn-primary:hover {
    background: var(--color-accent-hover);
}
.profile-btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

@media (max-width: 500px) {
    .profile-content { padding: 1.5rem; }
    .profile-vehicles { grid-template-columns: 1fr; }
}
