/* Chart Builder — pictograms & bar charts */

@import url('/css/styles.css');

body.cb-page {
    background: #f8f9fa !important;
    display: block !important;
    justify-content: unset !important;
    align-items: unset !important;
    min-height: auto !important;
    text-align: left !important;
}

.cb-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #1d1d1b;
}

.cb-wrap h1 {
    color: #c90c0f;
    text-align: center;
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
}

.cb-wrap h1 i {
    color: #fab719;
    margin-right: 0.35rem;
}

.cb-lead {
    text-align: center;
    color: #444;
    max-width: 720px;
    margin: 0 auto 1.5rem;
    line-height: 1.5;
}

.cb-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 1.5rem;
}

@media (max-width: 960px) {
    .cb-grid {
        grid-template-columns: 1fr;
    }
}

.cb-panel {
    background: #fff;
    border: 3px solid #c90c0f;
    border-radius: 14px;
    padding: 1.25rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

.cb-panel h2 {
    color: #c90c0f;
    font-size: 1.15rem;
    margin: 0 0 1rem;
}

.cb-panel h2 i {
    color: #fab719;
    margin-right: 0.35rem;
}

.cb-field {
    margin-bottom: 1rem;
}

.cb-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.cb-field input[type="text"],
.cb-field input[type="number"],
.cb-field select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
}

.cb-field input:focus,
.cb-field select:focus {
    border-color: #c90c0f;
    outline: none;
}

.cb-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 500px) {
    .cb-field-row {
        grid-template-columns: 1fr;
    }
}

.cb-field-scale {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
    gap: 0.35rem;
}

.cb-field-scale input {
    grid-column: 1;
}

.cb-field-hint {
    font-size: 0.9rem;
    color: #666;
    padding-bottom: 0.5rem;
}

.cb-hint {
    font-size: 0.9rem;
    color: #555;
    margin: 0.75rem 0 0;
    min-height: 1.25em;
}

.cb-hint.cb-warn {
    color: #a33;
    font-weight: 600;
}

.cb-categories {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    max-height: 420px;
    overflow-y: auto;
}

.cb-category {
    border: 2px solid #eee;
    border-radius: 10px;
    padding: 0.75rem;
    background: #fafafa;
}

.cb-category.cb-category-warn {
    border-color: #e8a0a0;
    background: #fff8f8;
}

.cb-category-head {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.cb-category-head input {
    padding: 0.4rem 0.55rem;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
}

.cb-category-remove {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 1.1rem;
}

.cb-category-remove:hover {
    color: #c90c0f;
}

.cb-freq-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.cb-freq-btn {
    width: 2.25rem;
    height: 2.25rem;
    border: 2px solid #c90c0f;
    background: #fff;
    color: #c90c0f;
    border-radius: 8px;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
}

.cb-freq-btn:hover {
    background: #c90c0f;
    color: #fff;
}

.cb-freq-input {
    width: 4rem;
    text-align: center;
    padding: 0.4rem;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1.1rem;
}

.cb-swatch {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

.cb-actions-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cb-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    font-size: 0.95rem;
}

.cb-btn-secondary {
    background: #fff;
    border-color: #c90c0f;
    color: #c90c0f;
}

.cb-btn-secondary:hover {
    background: #c90c0f;
    color: #fff;
}

.cb-btn-sm {
    padding: 0.4rem 0.65rem;
    font-size: 0.85rem;
}

.cb-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.cb-preview-header h2 {
    margin: 0;
}

.cb-chart-type-label {
    font-size: 0.9rem;
    color: #666;
    margin: 0 0 0.75rem;
    font-style: italic;
}

.cb-chart-stage {
    --cb-icon-surface: #fafafa;
    min-height: 280px;
    padding: 1rem;
    background: #fafafa;
    border-radius: 10px;
    border: 1px dashed #ccc;
}

.cb-chart-empty {
    color: #888;
    text-align: center;
    padding: 3rem 1rem;
}

.cb-chart-title-display {
    text-align: center;
    font-weight: 700;
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #1d1d1b;
}

/* Bar chart */
.cb-bar-chart {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 1rem;
    min-height: 220px;
    padding: 0.5rem 0 2rem;
    position: relative;
}

.cb-bar-chart::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 2rem;
    height: 2px;
    background: #333;
}

.cb-bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 120px;
    min-width: 48px;
}

.cb-bar-value {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
    color: #333;
}

.cb-bar-fill {
    width: 100%;
    max-width: 64px;
    border-radius: 6px 6px 0 0;
    transition: height 0.25s ease;
    min-height: 4px;
}

.cb-bar-label {
    margin-top: 0.5rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    word-break: break-word;
    line-height: 1.2;
}

.cb-bar-axis {
    position: absolute;
    left: 0;
    bottom: 0;
    font-size: 0.75rem;
    color: #666;
}

/* Pictogram */
.cb-pictogram {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.cb-picto-row {
    display: grid;
    grid-template-columns: minmax(80px, 140px) 1fr;
    gap: 0.75rem;
    align-items: center;
}

.cb-picto-label {
    font-weight: 600;
    font-size: 0.95rem;
    word-break: break-word;
}

.cb-picto-symbols {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.cb-picto-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    background: transparent;
    flex-shrink: 0;
    overflow: hidden;
}

.cb-picto-icon i {
    font-size: 1.65rem;
    line-height: 1;
    position: relative;
    z-index: 0;
}

/* Quadrant layout: Q1 top-right, Q2 top-left, Q3 bottom-left, Q4 bottom-right */
.cb-picto-quadrants {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.cb-picto-q {
    position: absolute;
    width: 50%;
    height: 50%;
    background: var(--cb-icon-surface, #fafafa);
    display: none;
}

.cb-picto-q1 {
    top: 0;
    right: 0;
}

.cb-picto-q2 {
    top: 0;
    left: 0;
}

.cb-picto-q3 {
    bottom: 0;
    left: 0;
}

.cb-picto-q4 {
    bottom: 0;
    right: 0;
}

/* ¼ shown: quadrant 2 only — mask 1, 3, 4 */
.cb-picto-partial-quarter .cb-picto-q1,
.cb-picto-partial-quarter .cb-picto-q3,
.cb-picto-partial-quarter .cb-picto-q4 {
    display: block;
}

/* ½ shown: quadrants 2 and 3 — mask 1 and 4 */
.cb-picto-partial-half .cb-picto-q1,
.cb-picto-partial-half .cb-picto-q4 {
    display: block;
}

/* ¾ shown: quadrants 2, 3, 4 — mask 1 (top-right) */
.cb-picto-partial-three-quarters .cb-picto-q1 {
    display: block;
}

.cb-partial-raw {
    font-weight: 700;
    font-size: 0.95rem;
}

.cb-key {
    margin-top: 1rem;
    text-align: center;
    font-style: italic;
    color: #444;
    font-size: 0.95rem;
}

.cb-fraction-legend {
    --cb-icon-surface: #fff;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #eee;
    font-size: 0.85rem;
    color: #555;
}

.cb-fraction-legend span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.cb-fraction-legend .cb-picto-icon {
    width: 1.35rem;
    height: 1.35rem;
}

.cb-fraction-legend .cb-picto-icon i {
    font-size: 1.2rem;
}

.cb-fraction-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

/* Tally sheet */
.cb-panel-tally {
    margin-top: 0;
}

.cb-tally-intro {
    color: #555;
    margin: 0 0 1rem;
    font-size: 0.95rem;
}

.cb-tally-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.cb-tally-card {
    border: 2px solid #fab719;
    border-radius: 10px;
    padding: 0.75rem;
    background: #fffef8;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.cb-tally-card:hover {
    background: #fff8e0;
}

.cb-tally-card:active {
    transform: scale(0.98);
}

.cb-tally-card h3 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    color: #1d1d1b;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.cb-tally-marks {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    min-height: 2.5rem;
    align-items: flex-end;
}

.cb-tally-group {
    position: relative;
    display: inline-flex;
    align-items: flex-end;
    gap: 4px;
    height: 2rem;
    padding: 0 1px;
    flex-shrink: 0;
}

.cb-tally-v {
    width: 3px;
    height: 1.65rem;
    background: #1d1d1b;
    border-radius: 1px;
    flex-shrink: 0;
}

.cb-tally-cross {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    pointer-events: none;
}

.cb-tally-cross::after {
    content: '';
    position: absolute;
    left: 1px;
    bottom: 1px;
    width: calc(100% - 2px);
    height: 3px;
    background: #1d1d1b;
    border-radius: 1px;
    transform: rotate(-33deg);
    transform-origin: left bottom;
}

.cb-tally-count {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.35rem;
}

/* Fullscreen */
.cb-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: #fff;
    padding: 2rem;
    overflow: auto;
}

.cb-fullscreen-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10001;
    width: 3rem;
    height: 3rem;
    border: none;
    border-radius: 50%;
    background: #c90c0f;
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
}

.cb-fullscreen-inner {
    --cb-icon-surface: #fff;
}

.cb-fullscreen-inner .cb-chart-stage {
    --cb-icon-surface: #fff;
    min-height: 60vh;
    border: none;
    background: #fff;
}

@media print {
    body.cb-page > *:not(.cb-wrap),
    .cb-panel-data,
    .cb-panel-tally,
    .cb-preview-actions,
    .cb-fraction-legend,
    .cb-hint {
        display: none !important;
    }

    .cb-wrap {
        max-width: none;
        padding: 0;
    }

    .cb-grid {
        display: block;
    }

    .cb-panel-preview {
        border: none;
        box-shadow: none;
    }
}
