/* Compact responsive overrides for the server-rendered Pico UI. */

*,
*::before,
*::after {
    box-sizing: border-box;
}

.brand-short {
    display: none;
}

.brand-link {
    white-space: nowrap;
}

img,
canvas,
iframe,
pre {
    max-width: 100%;
}

pre {
    overflow-x: auto;
}

.nav-label-short {
    display: none;
}

.table-scroll,
.compare-table,
main > table,
article > table,
details + p + table {
    max-width: 100%;
}

main > table,
article > table,
details + p + table {
    overflow-x: auto;
}

.detail-nav .nav-info {
    min-width: 0;
}

.detail-nav .nav-info .title-line {
    overflow-wrap: anywhere;
}

.detail-nav .nav-slot a[role="button"],
.detail-nav .nav-button.disabled {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-nav,
.filter-buttons,
.selected-companies,
.action-bar {
    min-width: 0;
}

nav.container,
nav.container ul,
nav.container li,
.search-form,
.search-form > *,
.search-box,
.filter-buttons > *,
.selected-companies > *,
.action-bar > * {
    min-width: 0;
}

@media (max-width: 1024px) {
    :root {
        --pico-spacing: 0.85rem;
    }

    body > .container,
    body > nav.container,
    body > form.container,
    body > main.container,
    body > footer.container {
        max-width: none;
        padding-right: 0.9rem;
        padding-left: 0.9rem;
    }

    nav.container {
        gap: 0.35rem 0.75rem;
        align-items: flex-start;
    }

    nav.container ul {
        gap: 0.35rem 0.65rem;
        flex-wrap: wrap;
        min-width: 0;
    }

    nav.container li {
        margin: 0;
        min-width: 0;
    }

    nav.container a,
    nav.container small,
    #snapshot-selector {
        font-size: 0.9rem;
    }

    #snapshot-selector {
        max-width: 12rem;
        min-width: 0;
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }

    .search-form {
        gap: 0.4rem;
        align-items: stretch;
    }

    .search-form button,
    .search-form a[role="button"] {
        min-width: max-content;
    }

    .search-box {
        min-width: min(100%, 20rem);
    }

    .company-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
        gap: 0.65rem;
        margin-bottom: 1.25rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-card .value {
        font-size: 1.45rem;
        line-height: 1.15;
    }

    .section-title {
        margin-top: 1.25rem;
        padding-bottom: 0.35rem;
        font-size: 1.15rem;
    }

    .metric-card,
    article,
    .ai-section-card,
    .edinet-analysis-panel {
        padding: 0.75rem;
    }

    .detail-nav {
        gap: 0.5rem;
        padding: 0.65rem;
    }

    .detail-nav .nav-info .title-line {
        font-size: clamp(1rem, 3vw, 1.15rem);
        line-height: 1.25;
    }

    .detail-nav .nav-info .meta-line {
        font-size: 0.85rem;
    }

    .action-bar {
        flex-wrap: wrap;
        padding: 0.6rem;
    }

    .tab-nav {
        gap: 0.35rem;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 0.15rem;
    }

    .tab-nav a {
        flex: 0 0 auto;
        padding: 0.3rem 0.55rem;
        font-size: 0.9rem;
    }

    .filter-buttons {
        gap: 0.35rem;
    }

    .filter-buttons a,
    .industry-filter a,
    .pagination a,
    .pagination span {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }

    .industry-filter {
        max-height: 12rem;
        padding: 0.4rem;
    }

    table {
        font-size: 0.82rem;
    }

    th,
    td,
    .metrics-table th,
    .metrics-table td {
        padding: 0.28rem 0.45rem;
        line-height: 1.25;
    }

    main > table,
    article > table,
    details + p + table {
        display: block;
        width: 100%;
        max-inline-size: 100%;
        white-space: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .compare-table,
    div[style*="overflow-x: auto"] {
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 900px) {
    .detail-nav {
        grid-template-columns: minmax(0, 1fr);
    }

    .detail-nav .nav-info {
        order: -1;
    }

    .detail-nav .nav-slot {
        min-width: 0;
    }

    .detail-nav .nav-slot a[role="button"],
    .detail-nav .nav-button.disabled {
        width: 100%;
    }

    .nav-label-full {
        display: none;
    }

    .nav-label-short {
        display: inline;
    }

    .edinet-pdf {
        padding: 0.55rem;
    }

    .edinet-pdf-toolbar,
    .analysis-header,
    .ai-section-header,
    .ai-qa-form form {
        align-items: stretch;
        flex-direction: column;
    }

    .analysis-actions {
        flex-wrap: wrap;
    }
}

@media (max-width: 600px) {
    :root {
        --pico-font-size: 15px;
        --pico-spacing: 0.65rem;
    }

    body > .container,
    body > nav.container,
    body > form.container,
    body > main.container,
    body > footer.container {
        padding-right: 0.55rem;
        padding-left: 0.55rem;
    }

    nav {
        margin-bottom: 0.55rem;
    }

    nav.container {
        flex-direction: column;
    }

    nav.container ul {
        width: 100%;
        justify-content: flex-start;
    }

    .brand-full {
        display: none;
    }

    .brand-short {
        display: inline;
    }

    #snapshot-selector {
        max-width: 9.5rem;
    }

    .search-form {
        margin-bottom: 0.75rem;
    }

    .search-box {
        flex-basis: 100%;
        min-width: 100%;
    }

    .search-form button,
    .search-form a[role="button"] {
        flex: 1 1 auto;
        min-width: 0;
        padding: 0.45rem 0.6rem;
    }

    .search-suggestions a {
        padding: 0.45rem 0.55rem;
    }

    h1 {
        font-size: 1.35rem;
        line-height: 1.25;
        margin-bottom: 0.65rem;
        overflow-wrap: anywhere;
    }

    h2 {
        font-size: 1.15rem;
    }

    .section-title {
        margin-top: 1rem;
        font-size: 1.05rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-card .value {
        font-size: 1.2rem;
    }

    .stat-card .label {
        font-size: 0.78rem;
    }

    .company-grid {
        grid-template-columns: 1fr;
        gap: 0.7rem;
    }

    .detail-nav .nav-info .title-line {
        font-size: 1rem;
    }

    .detail-nav .nav-slot a[role="button"],
    .detail-nav .nav-button.disabled,
    .action-btn,
    .ai-generate-btn,
    .ai-ask-btn {
        font-size: 0.8rem;
    }

    .action-btn {
        flex: 1 1 auto;
        justify-content: center;
        padding: 0.35rem 0.5rem;
    }

    .tab-nav {
        margin: 0.65rem 0;
    }

    .tab-nav a {
        padding: 0.28rem 0.48rem;
        font-size: 0.82rem;
    }

    .pagination {
        gap: 0.3rem;
    }

    .note-box,
    .note-entry,
    .ai-summary-box,
    .ai-conversation-box,
    #analysis-summary-content,
    .section-original-text {
        padding: 0.65rem;
    }

    table {
        font-size: 0.78rem;
    }

    th,
    td,
    .metrics-table th,
    .metrics-table td {
        padding: 0.22rem 0.35rem;
    }
}

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

    nav.container a,
    nav.container small,
    #snapshot-selector {
        font-size: 0.82rem;
    }
}

/* Shared compact dialogs. */
.app-dialog {
    position: fixed;
    inset: 0;
    display: block;
    width: min(32rem, calc(100vw - 1.5rem));
    min-width: 0;
    height: fit-content;
    min-height: 0;
    max-width: none;
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--pico-card-background-color);
    box-shadow: 0 18px 48px -16px rgba(15, 23, 42, 0.45);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    overflow: hidden;
}

.app-dialog::backdrop {
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
}

.app-dialog > article {
    width: 100%;
    max-width: none;
    max-height: inherit;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    border-radius: inherit;
    background: var(--pico-card-background-color);
}

.app-dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0;
    padding: 0.6rem 0.85rem 0.5rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.app-dialog-heading {
    min-width: 0;
}

.app-dialog-heading h3 {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.25;
}

.app-dialog-subtitle {
    margin: 0.08rem 0 0;
    color: var(--pico-muted-color);
    font-size: 0.72rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.app-dialog-code {
    margin-right: 0.25rem;
    padding: 0.01rem 0.25rem;
    border-radius: 4px;
    background: var(--pico-muted-border-color);
    color: var(--pico-color);
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
}

.app-dialog-close {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--pico-muted-color);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
}

.app-dialog-close:hover,
.app-dialog-close:focus-visible {
    background: var(--pico-muted-border-color);
    color: var(--pico-color);
}

.app-dialog form {
    margin: 0;
}

.app-dialog-body {
    padding: 0.6rem 0.85rem 0.5rem;
}

.app-dialog-body label {
    margin-bottom: 0.2rem;
    font-size: 0.74rem;
}

.app-dialog textarea {
    width: 100%;
    min-height: 13rem;
    max-height: 55vh;
    margin-bottom: 0;
    padding: 0.45rem 0.55rem;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.45;
    resize: vertical;
}

.app-dialog-error {
    margin: 0.25rem 0 0;
}

.app-dialog-footer {
    padding: 0.45rem 0.85rem 0.5rem;
    border-top: 1px solid var(--pico-muted-border-color);
    background: var(
        --pico-card-sectioning-background-color,
        var(--pico-card-background-color)
    );
}

.app-dialog-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0;
}

.app-dialog-buttons {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: auto;
}

.app-dialog-actions button {
    width: auto;
    margin: 0;
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
    line-height: 1.2;
}

.app-dialog-count {
    color: var(--pico-muted-color);
    font-size: 0.66rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    white-space: nowrap;
}

.app-dialog-hint {
    display: block;
    margin-top: 0.15rem;
    color: var(--pico-muted-color);
    font-size: 0.63rem;
    line-height: 1.2;
    text-align: right;
}

.app-dialog-hint kbd {
    display: inline-block;
    padding: 0.01rem 0.22rem;
    border: 1px solid var(--pico-muted-border-color);
    border-bottom-width: 1px;
    border-radius: 3px;
    background: var(--pico-card-background-color);
    color: var(--pico-muted-color);
    font-family: inherit;
    font-size: 0.58rem;
    line-height: 1.3;
}

@media (max-width: 480px) {
    .app-dialog {
        width: calc(100vw - 1rem);
        max-height: calc(100vh - 1rem);
        max-height: calc(100dvh - 1rem);
    }

    .app-dialog-header {
        padding: 0.55rem 0.7rem 0.45rem;
    }

    .app-dialog-body {
        padding: 0.55rem 0.7rem 0.45rem;
    }

    .app-dialog-footer {
        padding: 0.45rem 0.7rem 0.5rem;
    }
}
