/* Chartissimo Web App */

html {
    scrollbar-gutter: stable;
    overflow-x: hidden;
}

:root {
    --warm-bg: #FFF1E0;
    --warm-text: #3D2B1F;
    --warm-accent: #E8854A;
    --warm-accent-dark: #C46E4A;
    --warm-accent-gold: #D4A04A;
    --warm-card-bg: #FFFFFF;
    --border: #E0D5C8;
    --border-selected: #E8854A;
    --muted: #8B7D6B;
    --error: #C0392B;
    --radius: 10px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--warm-bg);
    color: var(--warm-text);
    min-height: 100vh;
}

/* ── Top bar ── */

.top-bar {
    background: var(--warm-card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--warm-text);
    text-decoration: none;
}

/* ── Nav tabs ── */

.top-nav {
    display: flex;
    gap: 4px;
    margin-left: 32px;
}

.nav-tab {
    background: none;
    border: none;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.nav-tab:hover {
    color: var(--warm-text);
}

.nav-tab.active {
    color: var(--warm-text);
    border-bottom-color: var(--warm-accent);
}

.auth-area {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

#auth-signed-in {
    align-items: center;
    gap: 12px;
}

.user-email {
    font-size: 14px;
    color: var(--muted);
}

.user-credits {
    font-size: 13px;
    font-weight: 600;
    color: var(--warm-accent);
    background: rgba(232, 133, 74, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
}

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--warm-accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--warm-accent-dark);
}

.btn-secondary {
    background: transparent;
    color: var(--warm-text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(0,0,0,0.04);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-danger {
    background: #d32f2f;
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #b71c1c;
}

.btn-danger:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-danger-link {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    text-decoration: underline;
    opacity: 0.6;
}

.btn-danger-link:hover {
    color: #d32f2f;
    opacity: 1;
}

.btn-blue {
    background: #3B7DD8;
    color: #fff;
}

.btn-blue:hover:not(:disabled) {
    background: #2E6BC0;
}

.btn-generate {
    background: var(--warm-accent);
    color: #fff;
}

.btn-generate:hover:not(:disabled) {
    background: var(--warm-accent-dark);
}

.sparkle-icon {
    flex-shrink: 0;
}

.btn-go {
    width: 100%;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 700;
    background: var(--warm-accent);
    color: #fff;
    border-radius: var(--radius);
}

.btn-go:hover:not(:disabled) {
    background: var(--warm-accent-dark);
}

/* ── Screen switching ── */

.screen { display: none; }
.screen.active { display: block; }

/* ── Layout ── */

.app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.app-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.app-right {
    position: sticky;
    top: 80px;
}

/* ── Cards ── */

.card {
    background: var(--warm-card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card h2 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 12px;
}

.hint {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 10px;
}

/* ── Data input ── */

#data-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: 'Inter', monospace;
    font-size: 13px;
    resize: vertical;
    background: #FDFAF5;
}

#data-input:focus {
    outline: none;
    border-color: var(--warm-accent);
}

#data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 10px;
}

#data-table th,
#data-table td {
    padding: 6px 10px;
    border: 1px solid var(--border);
    text-align: left;
    width: 50%;
}

#data-table th:first-child,
#data-table td:first-child {
    padding-left: 20%;
}

#data-table th:last-child,
#data-table td:last-child {
    text-align: right;
    font-variant-numeric: tabular-nums;
    padding-right: 20%;
}

#data-table th {
    background: #F5EFE6;
    font-weight: 600;
}

#data-table tr:nth-child(even) td {
    background: #FDFAF5;
}

/* ── Toggle groups ── */

.toggle-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.toggle-btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--warm-card-bg);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: var(--warm-text);
    transition: border-color 0.15s, background 0.15s;
}

.toggle-btn:hover {
    border-color: var(--warm-accent);
}

.toggle-btn.selected {
    border-color: var(--warm-accent);
    background: rgba(232, 133, 74, 0.1);
    color: var(--warm-accent-dark);
    font-weight: 600;
}

.bg-hint {
    font-size: 12px;
    color: var(--warm-muted);
    margin-left: 4px;
    white-space: nowrap;
}

.toggle-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: auto;  /* allow tooltip on hover */
}
.toggle-btn:disabled:hover {
    border-color: var(--border);
}

/* ── Data section accordion ── */

.data-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: flex-end;
}

.data-collapsed {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    cursor: pointer;
}

.data-collapsed-icon {
    font-size: 14px;
    color: var(--muted);
}

#data-collapsed-summary {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--warm-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Chart type icons ── */

.chart-type-icons .toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.chart-type-icons .toggle-btn svg {
    fill: currentColor;
    flex-shrink: 0;
}

/* ── Background selector (inside style section) ── */

.settings-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 10px 0 6px;
}

.bg-selector .form-row {
    margin-top: 12px;
}

/* ── Brand color picker ── */

.brand-color-row .form-row {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.brand-color-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.brand-color-row input[type="color"] {
    width: 32px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px;
    cursor: pointer;
    background: transparent;
}
.brand-color-row input[type="color"]:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.brand-color-hash {
    font-size: 13px;
    font-family: monospace;
    color: var(--warm-muted);
    margin-right: -1px;
    user-select: none;
}
input.brand-color-hex {
    width: 80px !important;
    min-width: 80px;
    max-width: 80px;
    flex: none !important;
    font-size: 13px;
    color: var(--text);
    font-family: monospace;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 5px;
    background: var(--bg);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
input.brand-color-hex:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
input.brand-color-hex:focus {
    outline: none;
    border-color: var(--accent);
}

/* ── Section toggle (collapsible headers) ── */

.section-toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-toggle:hover {
    color: var(--warm-accent);
}

.section-chevron {
    font-size: 10px;
    transition: transform 0.2s;
    color: var(--muted);
}

.section-toggle.collapsed .section-chevron {
    transform: rotate(-90deg);
}

/* ── Label controls ── */

.label-controls {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.form-row > label {
    font-size: 13px;
    font-weight: 500;
    min-width: 80px;
    flex-shrink: 0;
}

#chart-title-row,
#rl-chart-title-row,
#axis-label-row,
#rl-axis-label-row {
    min-height: 34px;
    flex-wrap: nowrap !important;
}

.form-row input[type="text"] {
    flex: 1;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
}

.form-row input[type="text"]:focus {
    outline: none;
    border-color: var(--warm-accent);
}

/* ── Style tabs ── */

.style-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.style-tab {
    background: none;
    border: none;
    padding: 8px 16px;
    font-family: inherit;
    font-weight: 500;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 13px;
    transition: color 0.15s, border-color 0.15s;
}

.style-tab:hover {
    color: var(--warm-text);
}

.style-tab.active {
    color: var(--warm-text);
    border-bottom-color: var(--warm-accent);
}

.style-tab.locked {
    opacity: 0.45;
}

.style-tab-panel {
    display: none;
}

.style-tab-panel.active {
    display: block;
}

/* ── Custom panel ── */

.custom-desc-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.custom-desc-row input[type="text"] {
    width: 100%;
}

.custom-expanded-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-top: 12px;
}

.custom-expanded-row textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    background: #FDFAF5;
}

.custom-expanded-row textarea:focus {
    outline: none;
    border-color: var(--warm-accent);
}

.char-count {
    font-size: 11px;
    color: var(--muted);
    text-align: right;
    margin-top: 2px;
    margin-bottom: 8px;
}

#custom-preview-btn {
    margin-top: 4px;
    margin-bottom: 4px;
}

/* ── Favorites grid ── */

#favorites-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 2px 0;
}

/* ── Fav options ── */

.fav-options {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Manage favorites gear ── */

.manage-favs-gear {
    margin-left: auto;
    color: var(--warm-muted);
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
}
.manage-favs-gear:hover {
    opacity: 1;
    color: var(--text);
}

/* ── Manage favorites modal ── */

.manage-favs-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.manage-favs-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
}
.manage-favs-card {
    position: relative;
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 440px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
.manage-favs-card h3 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
}
.manage-favs-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.manage-favs-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.manage-favs-row:last-child {
    border-bottom: none;
}
.manage-favs-row img {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}
.manage-favs-row .mf-name {
    flex: 1;
    font-size: 13px;
    border: none;
    border-bottom: 1px solid transparent;
    padding: 4px 2px;
    font-family: inherit;
    background: transparent;
    outline: none;
    transition: border-color 0.15s;
}
.manage-favs-row .mf-name:focus {
    border-bottom-color: var(--accent);
}
.manage-favs-row .mf-delete {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--warm-muted);
    padding: 4px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.manage-favs-row .mf-delete:hover {
    color: #d32f2f;
    background: rgba(211, 47, 47, 0.08);
}
.manage-favs-row.mf-confirming {
    background: rgba(211, 47, 47, 0.05);
    border-radius: 6px;
}
.mf-confirm-msg {
    font-size: 12px;
    color: #d32f2f;
    white-space: nowrap;
}
.mf-confirm-yes, .mf-confirm-no {
    font-size: 12px;
    border: none;
    background: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
}
.mf-confirm-yes {
    color: #d32f2f;
}
.mf-confirm-yes:hover {
    background: rgba(211, 47, 47, 0.12);
}
.mf-confirm-no {
    color: var(--warm-muted);
}
.manage-favs-card > .btn {
    margin-top: 16px;
    align-self: flex-end;
}

/* ── Delete account modal ── */

.delete-account-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.delete-account-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
}
.delete-account-card {
    position: relative;
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
.delete-account-card h3 {
    margin: 0 0 12px;
    font-size: 18px;
    color: #d32f2f;
}
.delete-account-card p {
    margin: 0 0 12px;
    font-size: 14px;
    color: var(--warm-text);
    line-height: 1.4;
}
.delete-account-card .input {
    margin-bottom: 16px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}
.delete-account-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Save favorite inline input ── */

.save-fav-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    width: 100%;
}

.save-fav-inline input[type="text"] {
    flex: 0 0 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
}

.save-fav-inline input[type="text"]:focus {
    outline: none;
    border-color: var(--warm-accent);
}

/* ── Style grid ── */

.style-grid {
    height: 500px;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    user-select: none;
}

.category-header:hover {
    color: var(--warm-accent);
}

.category-chevron {
    font-size: 10px;
    transition: transform 0.15s;
    flex-shrink: 0;
}

.category-header.collapsed .category-chevron {
    transform: rotate(-90deg);
}

.category-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.category-header:hover .category-label {
    color: var(--warm-accent);
}

.category-items {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 10px 0;
}

.category-items.collapsed {
    display: none;
}

/* ── Style summary (collapsed selection) ── */

.style-summary {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: #FDFAF5;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.style-summary:hover {
    border-color: var(--warm-accent);
}

.style-summary img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.style-summary-text {
    min-width: 0;
}

.style-unavailable {
    padding: 16px;
    background: #FAF5EE;
    border: 1px solid var(--warm-border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
    line-height: 1.5;
    cursor: default;
}
.style-unavailable a {
    color: var(--warm-accent);
    text-decoration: underline;
    cursor: pointer;
}
.style-unavailable a:hover {
    color: #C76B2A;
}

#summary-name,
#fav-summary-name {
    font-size: 14px;
    font-weight: 600;
}

#summary-desc,
#fav-summary-desc {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.style-thumb {
    border: 2px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
    background: #F5EFE6;
}

.style-thumb:hover {
    border-color: var(--warm-accent);
    transform: scale(1.03);
}

.style-thumb.selected {
    border-color: var(--warm-accent);
    box-shadow: 0 0 0 2px rgba(232, 133, 74, 0.3);
}

.style-thumb img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.style-thumb .style-label {
    font-size: 11px;
    font-weight: 500;
    text-align: center;
    padding: 4px 4px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── GO area ── */

.go-area {
    margin-bottom: 16px;
}

.go-wrapper {
    position: relative;
}

.go-hint {
    text-align: center;
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
    min-height: 16px;
}

/* ── Result (Create screen right column) ── */

.result-card {
    min-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.result-placeholder {
    position: relative;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    width: 100%;
    overflow: hidden;
}

.demo-slideshow-wrap {
    width: 100%;
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 12px;
}

.demo-slideshow {
    width: 100%;
    display: block;
    object-fit: cover;
    border-radius: var(--radius);
    transition: opacity 0.8s ease-in-out;
}

.demo-slideshow.fade-out {
    opacity: 0;
}

.demo-overlay-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    z-index: 1;
    text-shadow: 0 1px 3px rgba(255,255,255,0.8);
}

/* ── Chart Preview ── */

.result-preview {
    width: 100%;
    position: relative;
}

#preview-svg {
    width: 100%;
    height: auto;
    display: block;
    border-radius: var(--radius);
}

/* Generating overlay on top of preview */
.preview-generating {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius);
    z-index: 2;
}

.preview-generating p {
    font-size: 14px;
    color: var(--muted);
}

.cancel-job-btn {
    margin-top: 10px;
    padding: 6px 20px;
    font-size: 13px;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.cancel-job-btn:hover {
    color: var(--text);
    border-color: var(--text);
}

/* Color sweep animation during generating */
.result-preview {
    --sweep-c1: #D5CFC7;
    --sweep-c2: #E8854A;
    --sweep-c3: #3B7DD8;
    --sweep-c4: #D5CFC7;
    --sweep-c5: #E8854A;
    --sweep-c6: #3B7DD8;
}

.preview-pulsing #preview-chart rect,
.preview-pulsing #preview-chart path,
.preview-pulsing #preview-chart circle {
    animation: shape-color-sweep 5s ease-in-out infinite;
}

.preview-pulsing #preview-chart polyline {
    animation: stroke-color-sweep 5s ease-in-out infinite;
}

@keyframes shape-color-sweep {
    0%, 100% { fill: var(--sweep-c1); }
    17%      { fill: var(--sweep-c2); }
    33%      { fill: var(--sweep-c3); }
    50%      { fill: var(--sweep-c4); }
    67%      { fill: var(--sweep-c5); }
    83%      { fill: var(--sweep-c6); }
}

@keyframes stroke-color-sweep {
    0%, 100% { stroke: var(--sweep-c1); }
    17%      { stroke: var(--sweep-c2); }
    33%      { stroke: var(--sweep-c3); }
    50%      { stroke: var(--sweep-c4); }
    67%      { stroke: var(--sweep-c5); }
    83%      { stroke: var(--sweep-c6); }
}


/* ── Spinner ── */

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--warm-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#result-progress {
    text-align: center;
}

#progress-text {
    font-size: 14px;
    color: var(--muted);
}

/* ── Error ── */

.error-msg {
    color: var(--error);
    font-size: 13px;
    margin-top: 8px;
}

/* ── My Charts screen ── */

/* Hero + sidebar grid */
.my-charts-body {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 24px;
    align-items: start;
    position: sticky;
    top: 52px;
    z-index: 10;
    background: var(--warm-bg);
    padding: 8px 24px 12px;
    margin: 0 -24px;
}


/* Hero image */
.hero-area {
    aspect-ratio: 1344 / 768;
    max-height: calc(100vh - 140px);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--warm-card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.hero-empty {
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

.hero-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
    transition: border-color 0.15s;
}

.hero-img:hover {
    border: 2px solid var(--warm-accent);
}

/* Rework sidebar */
.rework-sidebar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 72px);
    overflow-y: auto;
}

.action-btn {
    width: 100%;
    position: relative;
}

.sidebar-divider {
    height: 12px;
}

.relabel-toggle {
    position: relative;
}

.relabel-chevron {
    font-size: 9px;
    margin-left: 4px;
    transition: transform 0.2s;
    display: inline-block;
}

.relabel-toggle.open .relabel-chevron {
    transform: rotate(180deg);
}

.relabel-panel {
    margin-top: -4px;
    padding: 12px;
    background: #FDFAF5;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.relabel-panel .label-controls {
    gap: 10px;
}

.relabel-panel .checkbox-row {
    flex-direction: column;
    gap: 8px;
}

.relabel-panel .form-row {
    flex-wrap: wrap;
    gap: 6px;
}

.relabel-panel .form-row > label {
    min-width: 40px;
    font-size: 12px;
}

.relabel-panel .toggle-group {
    gap: 4px;
}

.relabel-panel .toggle-btn {
    padding: 4px 8px;
    font-size: 11px;
}

.relabel-panel #rl-apply-btn {
    margin-top: 8px;
}

/* ── History grid (below hero) ── */

.history-section {
    margin-top: 32px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.history-heading {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--warm-text);
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.history-card {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid var(--border);
    transition: border-color 0.15s, transform 0.1s;
    background: var(--warm-card-bg);
}

.history-card:hover {
    border-color: var(--warm-accent);
    transform: scale(1.02);
}

.history-card.active {
    border-color: var(--warm-accent);
    box-shadow: 0 0 0 2px rgba(232, 133, 74, 0.3);
}

.history-card img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
}

.history-card-label {
    font-size: 11px;
    font-weight: 500;
    padding: 6px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--muted);
}

.history-loader {
    text-align: center;
    padding: 20px 0;
}

.history-card:focus {
    outline: 2px solid var(--warm-accent);
    outline-offset: 1px;
}

.history-empty {
    color: var(--muted);
    font-size: 13px;
    padding: 16px 0;
}

/* ── Inline tooltip (replaces alert()) ── */

.inline-tooltip {
    display: none;
    position: absolute;
    right: 0;
    padding: 8px 12px;
    background: var(--warm-text);
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    white-space: nowrap;
    z-index: 50;
    pointer-events: none;
    animation: tooltip-fade 2.5s ease forwards;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.inline-tooltip::after {
    content: '';
    position: absolute;
    right: 20px;
    border: 5px solid transparent;
}

.inline-tooltip.above {
    bottom: calc(100% + 8px);
}

.inline-tooltip.above::after {
    top: 100%;
    border-top-color: var(--warm-text);
}

.inline-tooltip.below {
    top: calc(100% + 8px);
}

.inline-tooltip.below::after {
    bottom: 100%;
    border-bottom-color: var(--warm-text);
}

@keyframes tooltip-fade {
    0%, 80% { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Toast ── */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--warm-text);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    max-width: 500px;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.toast.error {
    top: 24px;
    bottom: auto;
    background: #dc2626;
    font-size: 14px;
    padding: 12px 24px;
    cursor: pointer;
    transform: translateX(-50%) translateY(-20px);
}

.toast.error.show {
    transform: translateX(-50%) translateY(0);
}

/* ── Lightbox ── */

.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.85);
    align-items: center;
    justify-content: center;
}

.lightbox.open {
    display: flex;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    object-fit: contain;
    user-select: none;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    background: none;
    border: none;
    color: #fff;
    font-size: 36px;
    cursor: pointer;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.lightbox-close:hover {
    opacity: 1;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    font-size: 48px;
    line-height: 1;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s, background 0.15s;
    user-select: none;
}

.lightbox-nav:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-nav:disabled {
    opacity: 0.15;
    cursor: default;
    background: none;
}

.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }

.lightbox-bottom {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.lightbox-meta {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 8px 20px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    white-space: nowrap;
}

.lightbox-meta:empty {
    display: none;
}

.lightbox-copy {
    padding: 10px 28px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    backdrop-filter: blur(8px);
}

.lightbox-copy:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.lightbox-copy:active {
    background: rgba(255, 255, 255, 0.35);
}

.lightbox-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.lightbox-meta .meta-label {
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.lightbox-meta .meta-sep {
    color: rgba(255, 255, 255, 0.25);
}

/* ── Morph transition (CREATE → My Charts) ── */

.morph-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    pointer-events: none;
}

.morph-image {
    position: fixed;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.result-image {
    width: 100%;
    border-radius: var(--radius);
    object-fit: cover;
    aspect-ratio: 1344 / 768;
}

.result-image.revealing {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 2;
    animation: result-reveal 200ms ease-out forwards;
}

@keyframes result-reveal {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Crossfade: preview fades out while result fades in */
.result-preview.crossfading-out {
    animation: crossfade-out 200ms ease-in forwards;
}
@keyframes crossfade-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* Hero crossfade for rerolls */
.hero-img-crossfading {
    animation: hero-crossfade-in 200ms ease-out forwards;
}
@keyframes hero-crossfade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.app-left.fading-out {
    opacity: 0;
    transition: opacity 400ms ease-out;
    pointer-events: none;
}

.screen-entering {
    opacity: 0;
    display: block !important;
}

.screen-enter-active {
    transition: opacity 300ms ease-in;
    opacity: 1;
}

/* ── Reuse-data morph (My Charts → CREATE) ── */

.reuse-morph-image {
    position: fixed;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    transition: top 400ms cubic-bezier(0.4, 0, 0.2, 1),
                left 400ms cubic-bezier(0.4, 0, 0.2, 1),
                width 400ms cubic-bezier(0.4, 0, 0.2, 1),
                height 400ms cubic-bezier(0.4, 0, 0.2, 1),
                filter 400ms ease-out,
                border-radius 400ms ease-out,
                opacity 400ms ease-out;
}

.mini-table {
    position: fixed;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 8px 10px;
    background: var(--warm-card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    transition: top 400ms cubic-bezier(0.4, 0, 0.2, 1),
                left 400ms cubic-bezier(0.4, 0, 0.2, 1),
                width 400ms cubic-bezier(0.4, 0, 0.2, 1),
                height 400ms cubic-bezier(0.4, 0, 0.2, 1),
                opacity 200ms ease-out;
}

.mini-table-bar {
    height: 4px;
    border-radius: 2px;
    background: var(--border);
}

.mini-table-bar:nth-child(1) { width: 85%; background: var(--warm-accent); opacity: 0.6; }
.mini-table-bar:nth-child(2) { width: 65%; background: var(--warm-accent-gold); opacity: 0.5; }
.mini-table-bar:nth-child(3) { width: 75%; background: var(--warm-accent); opacity: 0.4; }
.mini-table-bar:nth-child(4) { width: 50%; background: var(--warm-accent-gold); opacity: 0.5; }
.mini-table-bar:nth-child(5) { width: 70%; background: var(--warm-accent); opacity: 0.3; }

.data-collapsed.flash {
    animation: data-absorb 400ms ease-out;
}

@keyframes data-absorb {
    0%   { background: rgba(232, 133, 74, 0.25); box-shadow: 0 0 0 0 rgba(232, 133, 74, 0.3); }
    50%  { background: rgba(232, 133, 74, 0.12); box-shadow: 0 0 12px 4px rgba(232, 133, 74, 0.15); }
    100% { background: transparent; box-shadow: none; }
}

/* ── Responsive: stack on narrow screens ── */

@media (max-width: 840px) {
    .app-columns {
        grid-template-columns: 1fr;
    }
    .app-right {
        position: static;
    }
    .my-charts-body {
        grid-template-columns: 1fr;
        position: static;
    }
    .top-bar-inner {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 16px;
    }
    .top-nav {
        order: 3;
        width: 100%;
        margin-left: 0;
        justify-content: center;
        border-top: 1px solid var(--border);
        padding-top: 8px;
    }
    .nav-tab {
        padding: 6px 12px;
        font-size: 13px;
    }
    .auth-area {
        margin-left: auto;
    }
    .auth-area .btn {
        white-space: nowrap;
        font-size: 13px;
        padding: 8px 14px;
    }
    .user-email {
        display: none;
    }
    .app-main {
        padding: 16px;
    }
}

/* ── Responsive: prevent horizontal overflow on small phones ── */

@media (max-width: 480px) {
    .top-bar-inner {
        overflow: hidden;
    }
    .logo {
        font-size: 17px;
    }
    .auth-area .btn {
        font-size: 12px;
        padding: 7px 12px;
    }
}

/* ============================================================
   Waitlist Modal
   ============================================================ */

.waitlist-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9000;
    align-items: center;
    justify-content: center;
}

.waitlist-modal.open {
    display: flex;
}

.waitlist-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.waitlist-modal-card {
    position: relative;
    background: #fff;
    border-radius: 12px;
    padding: 40px 36px 32px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.waitlist-modal-card h2 {
    font-size: 1.35rem;
    margin-bottom: 8px;
    color: #1a1a1a;
}

.waitlist-modal-card > p {
    font-size: 0.95rem;
    color: #555;
    margin-bottom: 20px;
    line-height: 1.5;
}

.waitlist-modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #999;
    cursor: pointer;
    line-height: 1;
}

.waitlist-modal-close:hover {
    color: #333;
}

#waitlist-modal-form {
    display: flex;
    gap: 8px;
}

#waitlist-modal-form input[type="email"] {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
}

#waitlist-modal-form input[type="email"]:focus {
    outline: none;
    border-color: #4285F4;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}

#waitlist-modal-form button {
    white-space: nowrap;
}

.waitlist-modal-msg {
    margin-top: 12px;
    font-size: 0.85rem;
    min-height: 1.2em;
}

.waitlist-modal-msg.success {
    color: #2e7d32;
}

.waitlist-modal-msg.error {
    color: #c62828;
}

.waitlist-modal-dismiss {
    display: block;
    margin: 12px auto 0;
    background: none;
    border: none;
    color: #999;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
}

.waitlist-modal-dismiss:hover {
    color: #666;
}

/* ── Demo mode ── */

.demo-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.demo-notice {
    text-align: center;
    font-size: 12px;
    color: #888;
    padding: 8px 0;
    font-style: italic;
}

.demo-locked::after {
    content: ' \1F512';
    font-size: 12px;
}
.demo-locked {
    opacity: 0.6;
    cursor: default;
}

.placeholder-card {
    min-height: 150px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.04), rgba(0, 0, 0, 0.08));
    border-color: transparent !important;
    cursor: default !important;
}

.hero-signin-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    color: #666;
}

/* Gallery hint nudge */
.gallery-hint {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: #1a73e8;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    animation: hint-fade-in 0.3s ease;
}
.gallery-hint::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 20px;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #1a73e8;
}
.gallery-hint-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    margin-left: 8px;
    padding: 0;
}
@keyframes hint-fade-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Billing button ── */

.btn-accent-link {
    background: none;
    border: none;
    color: var(--warm-accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}
.btn-accent-link:hover {
    background: rgba(232, 133, 74, 0.1);
}

/* ── Upgrade modal ── */

.upgrade-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.upgrade-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}
.upgrade-card {
    position: relative;
    background: #fff;
    border-radius: 12px;
    padding: 28px;
    width: 90%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
.upgrade-card h3 {
    margin: 0;
    font-size: 20px;
    color: var(--warm-text);
}
.upgrade-subtitle {
    margin: -8px 0 0;
    font-size: 14px;
    color: var(--muted);
}
.upgrade-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--muted);
    cursor: pointer;
    line-height: 1;
}
.upgrade-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.upgrade-section h4 {
    margin: 0;
    font-size: 14px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.upgrade-period-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: 8px;
    padding: 3px;
    width: fit-content;
}
.upgrade-period-toggle .toggle-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.15s;
}
.upgrade-period-toggle .toggle-btn.selected {
    background: #fff;
    color: var(--warm-text);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.upgrade-period-toggle .toggle-btn small {
    color: var(--warm-accent);
    font-size: 11px;
}
.upgrade-plans {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.topup-plans {
    grid-template-columns: repeat(2, 1fr);
}
.upgrade-plan {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.upgrade-plan.pilot-plan {
    border-color: var(--warm-accent);
    background: rgba(232, 133, 74, 0.04);
}
.upgrade-plan-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.upgrade-plan-header strong {
    font-size: 15px;
    color: var(--warm-text);
}
.upgrade-price {
    font-size: 15px;
    font-weight: 600;
    color: var(--warm-text);
}
.upgrade-price small {
    font-size: 12px;
    font-weight: 400;
    color: var(--muted);
}
.upgrade-plan-desc {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}
.upgrade-plan .btn {
    margin-top: 4px;
    align-self: flex-start;
}

@media (max-width: 540px) {
    .upgrade-plans {
        grid-template-columns: 1fr;
    }
    .topup-plans {
        grid-template-columns: 1fr;
    }
}
