/* Ishikawa Fishbone Diagram. shared.css has no component classes, so the
   panels, buttons and dialogs used here are defined here. */

/* The hidden attribute wins over the display values set below. */
[hidden] {
    display: none !important;
}

.fb-layout {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.fb-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px;
    min-width: 0;
}

.fb-h2 {
    font-size: 1.125rem;
    margin: 0 0 8px;
    color: var(--text-primary);
}

.fb-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 6px 0;
}

.fb-row input[type="text"],
.fb-row select {
    width: auto;
    min-width: 0;
    flex: 0 1 auto;
    padding: 8px 10px;
}

.fb-row select {
    padding-right: 36px;
}

.fb-label,
.fb-inline {
    display: block;
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
    margin: 10px 0 4px;
}

.fb-inline {
    display: inline;
    margin: 0;
}

.fb-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
    margin: 0;
    cursor: pointer;
}

.fb-check input {
    width: auto;
    margin: 0;
}

.fb-hint {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 4px 0;
}

.fb-btn {
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.fb-btn:hover:not(:disabled) {
    border-color: var(--accent-general);
}

.fb-btn:focus-visible {
    outline: 2px solid var(--accent-general);
    outline-offset: 2px;
}

.fb-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.fb-btn.primary {
    background: var(--accent-general-dim);
    border-color: var(--accent-general);
}

.fb-btn.small {
    min-height: 30px;
    padding: 2px 8px;
    font-size: 0.8125rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.text-link {
    color: var(--text-primary);
    text-decoration: underline;
}

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

/* Mode label and banners */
.fb-mode {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 8px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.fb-mode strong {
    color: var(--text-primary);
}

.fb-mode-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-general);
}

.fb-banner {
    border: 2px solid var(--accent-general);
    border-radius: 10px;
    padding: 12px 16px;
    background: var(--accent-general-dim);
    color: var(--text-primary);
}

.fb-banner p {
    margin: 4px 0;
}

.fb-banner-error {
    border-color: var(--accent-error);
    background: var(--accent-error-dim);
}

.fb-guide-hint {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin: 0;
    padding: 10px 14px;
    border: 1px solid var(--accent-general);
    border-radius: 10px;
    background: var(--accent-general-dim);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.fb-guide-hint span {
    flex: 1 1 16em;
}

/* Problem statement above the diagram */
.fb-problem {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    gap: 0 16px;
    margin-bottom: 10px;
}

.fb-problem .fb-label {
    margin-top: 0;
}

.fb-problem input[type="text"] {
    padding: 8px 10px;
}

.fb-problem-effect input[type="text"] {
    font-weight: 600;
}

.fb-problem-input {
    display: flex;
    gap: 8px;
}

.fb-problem-input input[type="text"] {
    flex: 1 1 auto;
    min-width: 0;
}

.fb-problem-input .fb-btn {
    flex: 0 0 auto;
}

#effectHelper .fb-btn {
    margin-top: 8px;
}

.fb-helper-grid {
    display: grid;
    gap: 2px;
}

.fb-helper-grid input {
    padding: 8px 10px;
}

@media (min-width: 520px) {
    .fb-helper-parts {
        grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 6px 10px;
        align-items: center;
    }

    .fb-helper-parts .fb-label {
        margin: 0;
    }
}

/* Toolbar and its menus */
.fb-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: center;
    padding: 10px 0 8px;
    border-top: 1px solid var(--border-color);
}

.fb-tool-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.fb-menu-btn::after {
    content: "";
    width: 0;
    height: 0;
    margin-left: 8px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
}

.fb-project-btn {
    gap: 8px;
    max-width: 22em;
}

.fb-menu-kicker {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.fb-project-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fb-dirty {
    font-size: 0.75rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 0 6px;
}

.fb-btn[aria-pressed="true"],
.fb-btn[aria-expanded="true"] {
    background: var(--accent-general-dim);
    border-color: var(--accent-general);
}

/* Popover menus. The script places each one under its button. */
.fb-menu {
    position: fixed;
    inset: auto;
    margin: 0;
    min-width: 200px;
    max-width: min(360px, calc(100vw - 16px));
    max-height: calc(100vh - 16px);
    overflow: auto;
    padding: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.fb-menu-wide,
#projectMenu {
    max-width: min(460px, calc(100vw - 16px));
}

.fb-menu-section + .fb-menu-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.fb-menu-section > .fb-label:first-child {
    margin-top: 2px;
}

.fb-menu-section > select {
    padding: 8px 36px 8px 10px;
}

.fb-menu-section > input[type="text"] {
    padding: 8px 10px;
}

.fb-menu .fb-check {
    display: flex;
    padding: 6px 4px;
}

.fb-menu-item {
    display: block;
    width: 100%;
    min-height: 36px;
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--text-primary);
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}

.fb-menu-item:hover:not(:disabled),
.fb-menu-item:focus-visible {
    background: var(--accent-general-dim);
    outline: none;
}

.fb-menu-item:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.fb-menu-png {
    display: flex;
    align-items: center;
    gap: 6px;
}

.fb-menu-png .fb-menu-item {
    flex: 0 0 auto;
    width: auto;
}

.fb-menu-png select {
    flex: 1 1 auto;
    width: auto;
    padding: 6px 30px 6px 8px;
    font-size: 0.8125rem;
}

.fb-zoom-label {
    min-width: 3.5em;
    text-align: center;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8125rem;
}

.fb-statusbar {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 16px;
    margin: 4px 0 10px;
}

.fb-tally {
    margin: 0;
    font-weight: 600;
    color: var(--text-primary);
}

.fb-status {
    margin: 0;
}

/* The diagram has its row to itself. The outline sits under it, with the
   selected item's panel beside the outline on wide screens. */
.fb-outline-area {
    display: grid;
    gap: 16px;
    margin-top: 16px;
    min-width: 0;
}

@media (min-width: 1000px) {
    .fb-outline-area {
        grid-template-columns: minmax(0, 1fr) minmax(0, 420px);
        align-items: start;
    }

    .fb-outline-area:has(> #itemPanel[hidden]) {
        grid-template-columns: minmax(0, 1fr);
    }

    .fb-outline-area .fb-item-panel {
        position: sticky;
        top: 12px;
        margin-top: 0;
    }
}

/* Maximize: the diagram alone fills the window, with a slim bar of zoom controls. */
.fb-max-bar {
    display: none;
}

.fb-diagram-wrap.is-maximized {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-primary);
}

.is-maximized .fb-max-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.fb-max-title {
    flex: 1 1 12em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: var(--text-primary);
}

.is-maximized .fb-frame {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

.is-maximized #diagramHost {
    margin: auto;
}

.is-maximized .fb-desktop-note {
    display: none;
}

body:has(.fb-diagram-wrap.is-maximized) {
    overflow: hidden;
}

.fb-diagram-wrap {
    min-width: 0;
}

.fb-work {
    --fb-frame-h: clamp(420px, calc(100vh - 240px), 960px);
}

/* The frame is as tall as the diagram, up to a cap; fit reads the cap. */
.fb-frame {
    position: relative;
    display: flex;
    overflow: auto;
    min-height: 200px;
    max-height: var(--fb-frame-h);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    touch-action: pan-x pan-y;
}

.fb-frame:focus-visible {
    outline: 2px solid var(--accent-general);
}

#diagramHost {
    margin: 0 auto;
}

#diagramHost svg {
    display: block;
}


.fb-item,
.fb-label {
    cursor: pointer;
}

.fb-item:focus,
.fb-label:focus {
    outline: none;
}

.fb-item .fb-hit {
    stroke: transparent;
    stroke-width: 2;
}

.fb-item:hover .fb-hit {
    stroke: var(--border-hover);
}

.fb-item.is-selected .fb-hit,
.fb-item:focus-visible .fb-hit {
    stroke: var(--accent-general);
}

.fb-label.is-selected .fb-label-box,
.fb-label:focus-visible .fb-label-box {
    stroke-width: 3;
}

.fb-item.is-dragging {
    opacity: 0.5;
}

.fb-drop-target .fb-hit,
.fb-drop-target .fb-label-box {
    stroke: var(--accent-success);
    stroke-width: 3;
}

.fb-inline-edit {
    position: absolute;
    z-index: 5;
    padding: 2px 6px;
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 13px;
}

.fb-outliner-wrap {
    min-width: 0;
}

.fb-outliner {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px;
    max-height: 60vh;
    overflow: auto;
    background: var(--bg-secondary);
}

.ol-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 2px 0;
}

.ol-d1 { padding-left: 14px; }
.ol-d2 { padding-left: 28px; }
.ol-d3 { padding-left: 42px; }
.ol-d4 { padding-left: 56px; }
.ol-d5 { padding-left: 70px; }
.ol-d6 { padding-left: 84px; }

.ol-row input[type="text"] {
    flex: 1 1 auto;
    min-width: 6em;
    padding: 5px 8px;
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 0.9rem;
}

.ol-row.is-category input[type="text"] {
    font-weight: 700;
}

.ol-row.is-bin .ol-bin-name {
    flex: 1 1 auto;
    font-weight: 700;
    padding: 5px 8px;
    color: var(--text-primary);
}

.ol-row.is-selected input[type="text"],
.ol-row.is-selected .ol-bin-name {
    border-color: var(--accent-general);
}

.ol-row select {
    width: auto;
    flex: 0 0 auto;
    padding: 4px 22px 4px 6px;
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 0.75rem;
    background-position: right 4px center;
}

.ol-flag {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.ol-empty {
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding: 8px;
}

.fb-item-panel {
    margin-top: 10px;
    border: 1px solid var(--accent-general);
    border-radius: 8px;
    padding: 10px 12px;
}

.fb-item-panel h3 {
    font-size: 1rem;
    margin: 0 0 6px;
    overflow-wrap: anywhere;
}

.fb-item-panel textarea,
.fb-item-panel input[type="text"] {
    padding: 6px 8px;
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 0.875rem;
}

.fb-desktop-note {
    margin-top: 6px;
}

/* Checks, table, history */
.fb-checks {
    margin: 0;
    padding-left: 1.2em;
}

.fb-checks li {
    margin: 6px 0;
    color: var(--text-primary);
}

.fb-checks .fb-btn {
    margin-left: 6px;
}

.table-scroll {
    position: relative;
    overflow-x: auto;
    max-width: 100%;
}

.fb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.fb-table th,
.fb-table td {
    text-align: left;
    vertical-align: top;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.fb-table th button {
    font: inherit;
    font-weight: 700;
    color: var(--text-primary);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}

.fb-table td.ruled {
    text-decoration: line-through;
}

.fb-table ul {
    margin: 0;
    padding-left: 1em;
}

/* Checks, causes and history share one tabbed panel. */
.fb-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.fb-tab {
    font-family: 'Space Grotesk', system-ui, sans-serif;
    font-size: 0.9375rem;
    font-weight: 600;
    min-height: 40px;
    padding: 6px 14px;
    margin-bottom: -1px;
    border: 1px solid transparent;
    border-radius: 8px 8px 0 0;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.fb-tab[aria-selected="true"] {
    color: var(--text-primary);
    border-color: var(--border-color);
    border-bottom-color: var(--bg-card);
    background: var(--bg-card);
}

.fb-tab:focus-visible,
.fb-tabpanel:focus-visible {
    outline: 2px solid var(--accent-general);
    outline-offset: 2px;
}

.fb-count {
    display: inline-block;
    min-width: 1.6em;
    margin-left: 4px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--accent-general-dim);
    color: var(--text-primary);
    font-size: 0.75rem;
    text-align: center;
}

.fb-count:empty {
    display: none;
}

.fb-history-list {
    margin: 8px 0 0;
    padding-left: 1.4em;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.fb-history-list time {
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    margin-right: 6px;
}

.fb-foot-row {
    justify-content: flex-end;
}

/* Dialogs */
.fb-dialog {
    max-width: min(640px, calc(100vw - 32px));
    width: 100%;
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 18px 20px;
}

.fb-dialog.fb-wide {
    max-width: min(920px, calc(100vw - 32px));
}

.fb-dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

.fb-dialog-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.fb-dialog h2 {
    font-size: 1.25rem;
    margin: 0;
}

.fb-dialog textarea {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8125rem;
    padding: 8px;
    margin: 8px 0;
}

.fb-dialog input[type="text"] {
    padding: 8px 10px;
    margin: 8px 0;
}

.fb-warnings li,
.fb-findings li {
    margin: 6px 0;
}

.fb-findings {
    color: var(--text-primary);
    font-size: 0.875rem;
    max-height: 10em;
    overflow: auto;
}

.fb-guide-toc {
    columns: 2;
    font-size: 0.875rem;
}

.fb-guide-toc a {
    color: var(--text-primary);
}

.fb-guide-body h3 {
    font-size: 1.05rem;
    margin: 18px 0 6px;
}

.fb-guide-body p,
.fb-guide-body li {
    color: var(--text-primary);
    line-height: 1.55;
}

.fb-keys {
    border-collapse: collapse;
    font-size: 0.875rem;
}

.fb-keys th,
.fb-keys td {
    border-bottom: 1px solid var(--border-color);
    padding: 4px 10px 4px 0;
    text-align: left;
}

kbd {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8em;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0 4px;
}

.library-entry h3 {
    font-size: 1rem;
    margin: 14px 0 4px;
}

.fb-print {
    display: none;
}

/* Phones */
@media (max-width: 768px) {
    .fb-btn {
        min-height: 44px;
    }

    .ol-row select,
    .ol-row input[type="text"] {
        min-height: 44px;
    }

    .fb-work {
        --fb-frame-h: 60vh;
    }

    .fb-problem {
        grid-template-columns: minmax(0, 1fr);
    }

    .fb-menu-item,
    .fb-tab {
        min-height: 44px;
    }

    .fb-desktop-note {
        display: none;
    }

    .fb-guide {
        max-width: 100vw;
        max-height: 100vh;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .fb-guide-toc {
        columns: 1;
    }
}

/* Print: the diagram and tally only, on one landscape page */
@page {
    size: landscape;
    margin: 10mm;
}

@media print {
    body * {
        visibility: hidden;
    }

    .fb-print,
    .fb-print * {
        visibility: visible;
    }

    .fb-print {
        display: block;
        position: absolute;
        inset: 0;
    }

    .fb-print svg {
        width: 100%;
        height: auto;
    }
}

/* Privacy page */
.fb-privacy h2 {
    font-size: 1.125rem;
    margin: 22px 0 6px;
}

.fb-privacy p,
.fb-privacy li {
    color: var(--text-primary);
    line-height: 1.6;
}
