/* Shared responsive layout for all dashboard panels */
.login-gate {
    position: fixed;
    z-index: 2000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    overflow-y: auto;
    background:
        radial-gradient(circle at 50% 20%, rgba(237, 135, 56, 0.12), transparent 32rem),
        #151719;
}

.login-gate[hidden] {
    display: none;
}

.login-gate-card {
    width: min(460px, 100%);
    padding: 28px;
    border: 1px solid #383d41;
    border-top: 3px solid #ed8738;
    border-radius: 8px;
    background: #1c1f22;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

.login-gate-heading {
    margin-bottom: 22px;
}

.login-gate-heading h1 {
    margin: 8px 0 8px;
    color: #edf0f2;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(1.5rem, 6vw, 2rem);
    font-weight: 500;
}

.login-gate-heading p {
    margin: 0;
    color: #a2a8ad;
    line-height: 1.55;
}

.login-gate-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.settings-required {
    color: #ed8738;
    font-size: 0.68rem;
    text-transform: uppercase;
}

.settings-optional {
    color: #a2a8ad;
    font-size: 0.68rem;
    text-transform: uppercase;
}

.login-gate-message {
    min-height: 20px;
    margin: 0;
    color: #dd756d;
    font-size: 0.82rem;
}

.login-gate-submit {
    min-height: 44px;
    border: 1px solid #ed8738;
    border-radius: 5px;
    background: #ed8738;
    color: #17191b;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.login-gate-submit:disabled {
    cursor: wait;
    opacity: 0.65;
}

.login-gate-active {
    overflow: hidden;
}

.main-wrapper[aria-hidden="true"] {
    visibility: hidden;
    pointer-events: none;
}

html {
    -webkit-text-size-adjust: 100%;
    width: 100%;
    overflow-x: hidden;
}

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

body {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
}

body,
.main-wrapper,
.panel,
.panel > .container,
#main-panel,
#dashboard,
#energy-panel,
#targets-panel,
#war-room-panel,
#chain-watching-panel,
#education-panel {
    min-width: 0;
}

.header-actions,
.energy-toolbar,
.t-filter-bar,
.chart-controls,
.war-target-controls,
.war-chain-toolbar,
.settings-dialog-footer {
    max-width: 100%;
}

.card-value,
.summary-pill,
.travel-date,
.travel-countdown,
.checklist-text,
.war-target-row,
.war-chain-member-row,
.war-chain-enemy-row,
.energy-activity-row {
    min-width: 0;
    overflow-wrap: anywhere;
}

.panel:not(#main-panel) {
    box-sizing: border-box;
}

.panel:not(#main-panel),
.panel:not(#main-panel) > .container {
    max-width: 100%;
    overflow-x: hidden;
}

.t-table-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    contain: inline-size;
}

.panel:not(#main-panel) > .container {
    margin: 0 auto;
}

@media (max-width: 1320px) {
    body {
        padding-inline: 16px;
    }

    .dashboard-layout {
        grid-template-areas:
            "dashboard dashboard"
            "cooldowns checklist";
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 14px;
    }

    .checklist-panel-container {
        max-height: 720px;
    }

    .core-grid-single-line {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

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

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

    .header-actions {
        gap: 6px;
    }

    .header-actions .btn-war-room {
        padding-inline: 10px;
    }
}

@media (max-width: 980px) {
    .header-top {
        gap: 12px;
    }

    .header-actions {
        max-width: 620px;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .header-actions .settings-button {
        order: 99;
    }

    .dashboard-layout {
        grid-template-areas:
            "dashboard"
            "cooldowns"
            "checklist";
        grid-template-columns: minmax(0, 1fr);
    }

    .side-panel,
    .checklist-panel-container {
        position: static;
        width: 100%;
        max-height: none;
    }

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

    .travel-stocks-container {
        max-width: none;
    }

    .panel:not(#main-panel) {
        padding-inline: 16px;
    }

    #war-room-panel,
    #chain-watching-panel,
    #education-panel,
    #targets-panel,
    #energy-panel {
        height: 100dvh;
        padding: 16px;
        transform: none !important;
    }

    .main-wrapper.war-room-active #war-room-panel,
    .main-wrapper.chain-watching-active #chain-watching-panel,
    .main-wrapper.education-room-active #education-panel,
    .main-wrapper.targets-active #targets-panel,
    .main-wrapper.energy-active #energy-panel {
        transform: none !important;
    }

    #targets-panel .t-table-wrapper,
    #targets-panel .t-filter-bar,
    #targets-panel .t-stats-grid {
        max-width: 100%;
        box-sizing: border-box;
    }

    .panel:not(#main-panel) > .container > header {
        position: sticky;
        top: 0;
        z-index: 20;
    }

    .panel:not(#main-panel) .header-top {
        min-height: 38px;
    }

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

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

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

    .t-filter-bar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .t-filter-bar input[type="search"],
    .t-filter-bar input[type="number"] {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .war-chain-layout {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 760px) {
    .login-gate {
        align-items: start;
        padding: 12px;
    }

    .login-gate-card {
        margin: 12px 0;
        padding: 20px 16px;
    }

    .login-gate-heading h1 {
        font-size: 1.5rem;
    }
    body {
        padding: 10px 8px 24px;
    }

    #main-panel > .container > header {
        margin-bottom: 12px;
        padding: 13px;
    }

    .header-top {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }

    .app-heading {
        width: 100%;
    }

    .app-heading-line {
        width: 100%;
        justify-content: space-between;
    }

    .app-heading h1 {
        font-size: 1.35rem;
    }

    .header-actions {
        width: 100%;
        max-width: none;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        overflow: visible;
        padding: 0;
    }

    .header-actions .btn-war-room,
    .header-actions .settings-button {
        width: 100%;
        min-width: 0;
        min-height: 40px;
        box-sizing: border-box;
    }

    .header-actions .btn-war-room {
        white-space: normal;
        line-height: 1.15;
    }

    .header-actions .settings-button {
        grid-column: 3;
        justify-self: end;
    }

    .core-grid-single-line {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .core-grid-single-line .card:last-child {
        grid-column: 1 / -1;
    }

    .efficiency-grid,
    .summary-grid,
    .economy-grid,
    .battle-stats-grid,
    .work-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .stats-group {
        padding-inline: 8px;
    }

    .stats-group-header {
        grid-template-columns: minmax(0, 1fr) auto 24px;
    }

    .stats-group-header::after {
        right: 4px;
    }

    .summary-card {
        min-height: 72px;
    }

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

    .checklist-panel-container {
        max-height: none;
    }

    .chart-section {
        padding: 12px;
    }

    .chart-container {
        height: 300px;
    }

    .chart-controls {
        justify-content: stretch;
    }

    .btn-range,
    #chart-metric {
        min-height: 38px;
    }

    .panel:not(#main-panel) {
        padding-inline: 8px;
    }

    #war-room-panel,
    #chain-watching-panel,
    #education-panel,
    #targets-panel,
    #energy-panel {
        padding: 10px 8px 24px;
    }

    .panel:not(#main-panel) > .container > header {
        padding: 10px 12px;
        margin-bottom: 12px;
    }

    .panel:not(#main-panel) .header-top {
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .panel:not(#main-panel) .header-top h1 {
        font-size: 1.2rem;
    }

    .panel:not(#main-panel) .header-top .btn-war-room {
        width: auto;
        min-height: 38px;
        padding: 8px 10px;
    }

    .war-section,
    .education-room-status,
    .education-course-tree,
    .education-path-grid {
        max-width: none;
    }

    .education-path-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .education-path-button {
        min-height: 150px;
    }

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

    .t-filter-bar {
        grid-template-columns: minmax(0, 1fr);
    }

    .t-filter-bar input[type="search"] {
        min-width: 0;
    }

    .t-table-wrapper {
        max-width: calc(100vw - 32px);
    }

    .t-pagination {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    #t-page-status {
        text-align: center;
        line-height: 1.25;
    }

    .war-target-heading,
    .education-tree-heading,
    .war-chain-next-preview-heading,
    .war-chain-members-heading,
    .war-chain-toolbar {
        flex-wrap: wrap;
    }

    .war-chain-summary {
        width: 100%;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .war-chain-refresh {
        width: 100%;
    }

    .settings-dialog {
        width: calc(100% - 16px);
        max-height: calc(100dvh - 16px);
    }

    .settings-form {
        max-height: calc(100dvh - 16px);
        overflow-y: auto;
        box-sizing: border-box;
        padding: 16px;
    }

    .settings-dialog-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .settings-dialog-footer button {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .header-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .header-actions .settings-button {
        grid-column: 2;
    }

    .core-grid-single-line,
    .efficiency-grid,
    .summary-grid,
    .economy-grid,
    .battle-stats-grid,
    .work-stats-grid,
    .cooldown-list,
    .education-path-grid,
    .t-stats-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .core-grid-single-line .card:last-child {
        grid-column: auto;
    }

    .stats-group-header {
        grid-template-columns: minmax(0, 1fr) auto 18px;
    }

    .stats-group-value {
        font-size: 0.92rem;
    }

    .chart-container {
        height: 260px;
    }

    .chart-controls {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    #chart-metric {
        grid-column: 1 / -1;
        width: 100%;
        box-sizing: border-box;
    }

    .panel:not(#main-panel) .header-top {
        align-items: flex-start;
    }

    .panel:not(#main-panel) .header-top h1 {
        max-width: 150px;
        overflow-wrap: anywhere;
    }

    .panel:not(#main-panel) .header-top .btn-war-room {
        flex: 0 0 auto;
        max-width: 50%;
        white-space: normal;
    }

    .t-stat-card {
        min-height: 68px;
    }

    .t-pagination {
        grid-template-columns: 42px minmax(0, 1fr) 42px;
    }

    .t-pagination-button {
        width: 42px;
        padding-inline: 0;
    }

    .war-chain-summary {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }

    .war-chain-summary-item {
        width: 100%;
    }

    .war-target-controls,
    .war-target-controls label,
    .war-target-controls select {
        width: 100%;
        max-width: none;
    }

    .war-result-heading,
    .war-winner {
        align-items: flex-start;
        flex-direction: column;
    }

    .energy-toolbar {
        gap: 8px;
    }

    .energy-date-controls {
        width: 100%;
        justify-content: space-between;
    }

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

    .energy-summary-card {
        min-height: 68px;
    }

    .energy-history-chart {
        min-height: 170px;
        overflow-x: auto;
    }

    .energy-history-column {
        height: 170px;
        min-width: 18px;
    }

    .energy-history-bar {
        max-height: 150px;
    }

    .energy-activity-list {
        max-height: 360px;
    }

    .energy-activity-row {
        grid-template-columns: 54px 82px minmax(0, 1fr);
        gap: 6px;
        min-height: 52px;
        font-size: 0.72rem;
    }

    .energy-activity-row > :nth-child(4),
    .energy-activity-row > :nth-child(5) {
        display: none;
    }
}

@media (max-height: 520px) and (orientation: landscape) {
    body {
        padding-top: 6px;
    }

    #war-room-panel,
    #chain-watching-panel,
    #education-panel,
    #targets-panel,
    #energy-panel {
        padding-top: 8px;
    }

    .panel:not(#main-panel) > .container > header {
        position: relative;
    }

    .checklist-panel-container,
    .settings-form,
    .settings-dialog {
        max-height: calc(100dvh - 16px);
    }
}
