/* Shared responsive overrides. Loaded after each page's existing styles.
   Keep table columns and navigation available; scroll wide data locally. */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body .layout {
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    max-width: 100%;
    overflow: visible;
}

body .layout > .sidebar {
    box-sizing: border-box;
    flex: 0 0 250px;
    width: 250px;
    min-width: 0;
}

body .layout > .main {
    box-sizing: border-box;
    flex: 1 1 0%;
    min-width: 0;
    max-width: none;
    overflow: visible;
}

.content, .topbar, .issue-container, .modern-modal-content,
.settings-wrapper, .settings-card, .auth-container, .reset-card,
.profile-wrap, .profile-body, .sa-main, .sa-card, .tool-wrap,
.report-panel, .jira-card, .dashboard-card {
    box-sizing: border-box;
    min-width: 0;
}

.content, .issue-container, .msw-shell, .report-grid, .dashboard-grid,
.report-panel, .settings-card, .profile-body > *, .sa-grid > * {
    max-width: 100%;
    min-width: 0;
}

body .issue-container {
    overflow: visible;
}

.search-group, .filter-bar, .content-title-wrap, .report-toolbar > *,
.msw-filter-bar > *, .msw-filter-right, .sa-form, .worked-item,
.comment-content, .activity-body, .time-item > * {
    min-width: 0;
}

.topbar .search-group, .topbar .filter-bar {
    flex-wrap: wrap;
}

.topbar .search-box {
    box-sizing: border-box;
    flex: 1 1 220px;
    min-width: 0;
    max-width: 100%;
}

.topbar .search {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
}

.topbar .filter-bar {
    margin-left: 0;
}

.search-results, .account-dropdown, .notification-panel {
    box-sizing: border-box;
}

.content-header, .report-toolbar, .sa-top, .jira-card-header,
.dashboard-card-header, .time-header, .msw-title-row {
    flex-wrap: wrap;
    gap: 12px;
}

.content h2, .issue-header h2, .worked-item a, .sa-admin,
.comment-attachment-names, .progress-row > span, .msw-card-title,
.result, .alert-error, .alert-success {
    overflow-wrap: anywhere;
}

img, video {
    max-width: 100%;
}

body .ck-content img, body .issue-description img,
body .ck-content figure, body .ck-content .image-inline {
    max-width: min(500px, 100%) !important;
    box-sizing: border-box;
}

.comment-body img, .activity-body img {
    max-width: 100% !important;
    height: auto;
}

.ck-editor, .ck-editor__main, .ck-content, .comment-form {
    min-width: 0;
    max-width: 100%;
}

.ck-content {
    overflow-wrap: anywhere;
}

.ck-content pre, .comment-body pre, .activity-body pre,
.sa-diagnostics pre, body > pre {
    max-width: 100%;
    overflow-x: auto;
}

.ck-content .table {
    max-width: 100%;
    overflow-x: auto;
}

input, select, textarea {
    min-width: 0;
    max-width: 100%;
}

.auth-container, .reset-card {
    width: min(480px, calc(100% - 32px));
}

.auth-container input:not([type="checkbox"]):not([type="radio"]),
.reset-card input, .sa-form input, .sa-form select, .sa-form textarea,
.comment-form textarea, .top-worklog-grid input, .time-form input,
.time-edit input {
    box-sizing: border-box;
    max-width: 100%;
}

.auth-container input:not([type="checkbox"]):not([type="radio"]),
.reset-card input {
    width: 100%;
}

.settings-wrapper {
    width: 100%;
}

.settings-card {
    max-width: 100%;
}

.modern-modal {
    box-sizing: border-box;
    padding: 16px;
}

.modern-modal-content {
    max-width: 100%;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overscroll-behavior: contain;
}

.modal, .modal-content, .modal-box {
    box-sizing: border-box;
    max-width: 100%;
}

.modal {
    padding: 16px;
    overflow-y: auto;
}

.modal-box {
    width: min(510px, 100%);
    margin: min(120px, 8vh) auto;
}

.modal-box input, .modal-box select {
    box-sizing: border-box;
}

.form-row > *, .half {
    min-width: 0;
}

.attachments-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr));
}

.attachment-item, .company-logo-preview {
    box-sizing: border-box;
    max-width: 100%;
}

.attachment-actions, .modern-actions, .editor-actions, .settings-actions,
.report-actions, .top-worklog-actions {
    flex-wrap: wrap;
}

body .time-list-head, body .time-item {
    grid-template-columns: minmax(110px, 1fr) minmax(110px, .8fr) minmax(140px, 2fr) minmax(150px, 1fr);
}

body .time-edit {
    grid-column: 1 / -1;
}

.time-edit input, .time-form input {
    min-width: 0;
}

body .issue-meta .top-worklog-menu {
    box-sizing: border-box;
}

.time-note, .time-meta, .activity-body {
    overflow-wrap: anywhere;
}

.profile-wrap {
    width: calc(100% - 32px);
}

.profile-body {
    grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
}

.tool-wrap {
    width: calc(100% - 32px);
}

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

.sa-main, .sa-card, .sa-form {
    min-width: 0;
}

/* Keep dense tables legible without widening the entire page. */
@media (max-width: 1440px) {
    table.modern-table, table.sa-table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table.modern-table th, table.modern-table td,
    table.sa-table th, table.sa-table td {
        min-width: 90px;
        white-space: nowrap;
    }

    table.modern-table .ticket-summary-col,
    table.modern-table .ticket-summary-cell {
        min-width: 240px;
    }

    table.modern-table .ticket-person-col,
    table.modern-table .ticket-person-cell {
        min-width: 135px;
    }

    table.modern-table .ticket-status-col,
    table.modern-table .ticket-status-cell {
        min-width: 120px;
    }

    table.modern-table .priority-col {
        min-width: 42px;
    }

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

@media (max-width: 1250px) {
    .topbar {
        flex-wrap: wrap;
        padding: 16px 20px;
        gap: 14px;
    }

    .topbar .search-group {
        flex: 1 1 100%;
    }

    .topbar .user-info {
        margin-left: auto;
    }

    body .issue-container {
        grid-template-columns: minmax(0, 1fr);
        padding: 20px;
    }

    body .issue-meta {
        grid-column: 1;
        grid-row: auto;
    }

    body .issue-description, body .attachments-box, body .upload-box {
        grid-column: 1;
    }

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

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

    body .time-list-head {
        display: none;
    }

    body .time-item {
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    body .time-minutes {
        flex-wrap: wrap;
    }

    .settings-wrapper {
        padding: 20px 0;
    }

    .sa-main {
        padding: 24px;
    }
}

/* Navigation remains visible and usable without adding a JavaScript menu. */
@media (max-width: 900px) {
    body .layout {
        flex-direction: column;
    }

    body .layout > .sidebar {
        flex: 0 0 auto;
        width: 100%;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px;
        padding: 16px;
    }

    .sidebar .logo {
        flex: 1 1 100%;
        margin: 0 0 6px;
    }

    .sidebar .logo img {
        width: auto !important;
        max-width: 180px;
        max-height: 60px;
    }

    .sidebar > .sidebar-nav-link {
        flex: 1 1 140px;
    }

    .sidebar .queue-block {
        flex: 1 1 100%;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
        gap: 6px;
        margin: 4px 0;
        padding: 12px 0;
    }

    .sidebar .queue-title {
        grid-column: 1 / -1;
        margin-bottom: 4px;
    }

    .sidebar .queue-link {
        box-sizing: border-box;
        min-width: 0;
        margin-bottom: 0;
    }

    .sidebar .queue-link > span:first-child {
        overflow-wrap: anywhere;
    }

    .sidebar .queue-count {
        flex-shrink: 0;
    }

    .sidebar .queue-create-btn {
        margin-top: 0;
    }

    .content {
        padding: 20px;
    }

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

    .sa-sidebar {
        padding: 20px;
    }

    .sa-nav {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 16px;
    }

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

    .sa-form-row {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 600px) {
    .sidebar .logo img {
        max-height: 44px;
    }

    .sidebar > .sidebar-nav-link {
        min-height: 36px;
        padding: 8px;
        font-size: 13px;
    }

    .sidebar .queue-block {
        padding: 8px 0;
        gap: 4px;
    }

    .sidebar a.queue-link {
        padding: 7px 8px;
        font-size: 13px;
    }

    .content, body .issue-container, .sa-main {
        padding: 12px;
    }

    .topbar {
        padding: 12px;
        gap: 12px;
    }

    .topbar .search-group, .topbar .filter-bar {
        width: 100%;
        gap: 8px;
    }

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

    .filter-bar > select, .filter-bar > .select2-container,
    .filter-bar .status-filter-wrap, .filter-bar .created-filter-wrap {
        flex: 1 1 calc(50% - 8px);
        width: calc(50% - 8px) !important;
        min-width: 0 !important;
        max-width: 100%;
    }

    /* Native selects enhanced by Select2 must stay hidden. */
    .filter-bar > .select2-hidden-accessible {
        width: 1px !important;
        flex: 0 0 auto;
    }

    .filter-bar .status-filter-select + .select2-container {
        width: 100% !important;
        min-width: 0;
    }

    .created-filter-panel {
        position: fixed;
        left: 12px;
        right: 12px;
        top: 50%;
        transform: translateY(-50%);
        width: auto;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        overflow-y: auto;
        box-sizing: border-box;
        z-index: 3500;
    }

    .created-filter-option {
        grid-template-columns: 18px minmax(0, 1fr);
        gap: 8px;
    }

    .created-between-fields, .created-relative-fields, .created-range-fields {
        grid-column: 2;
        flex-wrap: wrap;
        min-width: 0;
    }

    .created-filter-panel input, .created-filter-panel select {
        max-width: 100%;
    }

    .notification-panel {
        position: fixed;
        top: 12px;
        top: max(12px, env(safe-area-inset-top));
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
        margin-top: 0;
        max-height: min(560px, 70vh);
        max-height: min(560px, 70dvh);
        overflow-y: auto;
    }

    .notification-copy em {
        display: flex;
        flex-wrap: wrap;
    }

    body .issue-meta .top-worklog-menu {
        position: fixed;
        top: 50%;
        left: 12px;
        right: 12px;
        width: auto;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        transform: translateY(-50%);
        overflow-y: auto;
        z-index: 3500;
    }

    .account-dropdown {
        max-width: calc(100vw - 24px);
    }

    .content-header > div:last-child, .content-header .create-btn {
        max-width: 100%;
    }

    .modern-modal {
        padding: 8px;
    }

    .modern-modal-content {
        padding: 20px 16px;
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
    }

    .modal-box {
        padding: 20px 16px;
        margin: 8px auto;
    }

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

    .modern-modal-header {
        gap: 12px;
    }

    .modern-modal-header h2 {
        font-size: 22px;
        overflow-wrap: anywhere;
    }

    .modern-actions, .editor-actions, .report-actions {
        display: flex;
        gap: 8px;
    }

    .modern-actions > *, .editor-actions > *, .report-actions > * {
        margin: 0;
    }

    .form-row {
        flex-direction: column;
        gap: 12px;
    }

    .settings-card, .report-panel, .jira-card, .dashboard-card,
    .issue-description, .attachments-box, .activity-box {
        padding: 16px;
    }

    .settings-wrapper {
        padding: 0;
    }

    body .report-filters {
        grid-template-columns: minmax(0, 1fr);
    }

    body .report-field.wide {
        grid-column: auto;
    }

    .period-form, .report-actions {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .jira-card {
        min-height: 0;
    }

    .chart-wrap {
        height: 280px;
    }

    .chart-wrap.compact {
        height: 300px;
    }

    .chart-tooltip, .chart-tooltip.click-tip, .bubble-detail-tip {
        box-sizing: border-box;
        min-width: 0;
        width: min(300px, calc(100vw - 80px));
        max-width: calc(100% - 16px);
        overflow-wrap: anywhere;
    }

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

    .stats-table .stat-label {
        width: auto;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .stats-table .stat-count, .stats-table .stat-percent {
        width: auto;
    }

    .profile-wrap {
        margin: 16px auto;
    }

    .profile-body {
        grid-template-columns: minmax(0, 1fr);
        padding: 0 16px 20px;
        gap: 24px;
    }

    .tool-wrap {
        margin: 16px auto;
        padding: 20px 16px;
    }

    .auth-container {
        margin: 32px auto;
        padding: 24px 20px;
    }

    .login-brand-panel {
        padding: 24px 20px;
    }

    .login-brand-content h1 {
        font-size: clamp(24px, 6vw, 30px);
    }

    .login-brand-logo {
        margin-bottom: 16px;
    }

    .reset-card {
        padding: 24px 20px;
        margin: 16px auto;
    }

    body:has(> .reset-card) {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        padding: 16px 0;
        box-sizing: border-box;
    }

    .comment-item {
        flex-direction: column;
        gap: 8px;
    }

    .comment-author, .comment-content {
        width: 100%;
        box-sizing: border-box;
    }

    .comment-attachment-row {
        box-sizing: border-box;
        flex-wrap: wrap;
        gap: 6px;
    }

    .comment-attachment-name {
        flex-basis: calc(100% - 36px);
    }

    .tab-head, .activity-meta {
        flex-wrap: wrap;
        gap: 8px;
    }

    .activity-body {
        margin-left: 0;
    }

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

    .description-change-arrow {
        padding: 0;
        justify-self: center;
        transform: rotate(90deg);
    }

    .time-form, .time-edit {
        flex-direction: column;
        align-items: stretch;
    }

    .time-form input, .time-edit input {
        width: 100% !important;
        min-width: 0 !important;
        flex: 0 0 auto;
    }

    .msw-filter-bar > input, .msw-filter-bar > select,
    .msw-filter-bar > button, .msw-filter-bar > .msw-filter-btn {
        box-sizing: border-box;
        min-width: 0;
        max-width: 100%;
    }

    .msw-filter-right {
        width: 100%;
        margin-left: 0;
    }

    .msw-tabs {
        flex-wrap: wrap;
    }

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

    .lightbox {
        padding: 72px 12px 12px;
    }

    .lightbox-toolbar {
        right: 12px;
        left: 12px;
        justify-content: center;
        flex-wrap: wrap;
    }

    .ticket-toast {
        left: 12px;
        right: 12px;
        bottom: max(12px, env(safe-area-inset-bottom));
        min-width: 0;
        max-width: none;
        flex-wrap: wrap;
    }

    /* Avoid automatic input zoom on touch devices. */
    input:not([type="checkbox"]):not([type="radio"]), select, textarea,
    .login-page .auth-container input, .form-group input,
    .form-group select, .form-group textarea, .filter-select, .meta-select,
    .report-field input, .report-field select, .modal-form input,
    .modal-form select, .form-row input, .form-row select,
    .time-form input, .time-edit input, .top-worklog-grid input,
    .sa-form input, .sa-form select, .sa-form textarea {
        font-size: 16px;
    }
}

@media (max-width: 420px) {
    body .meta-row, body .watcher-row {
        grid-template-columns: 24px minmax(0, 1fr);
        row-gap: 8px;
    }

    .meta-row > :not(.detail-icon):not(strong), .watcher-row > .watcher-input {
        grid-column: 2;
        min-width: 0;
    }

    .watcher-wrapper .meta-hint {
        margin-left: 34px;
    }

    .watcher-dropdown {
        max-width: 100%;
    }

    .watcher-input input {
        min-width: 0;
        width: 100%;
    }

    .created-between-fields input[type="date"],
    .created-range-fields input[type="text"] {
        width: 100%;
    }
}

/* Also fit dialogs when a phone keyboard or a landscape screen reduces height. */
@media (max-height: 600px) {
    .modern-modal {
        align-items: flex-start;
    }

    .auth-container {
        margin-top: 20px;
        margin-bottom: 20px;
    }

    .notification-panel, .created-filter-panel,
    body .issue-meta .top-worklog-menu {
        box-sizing: border-box;
        position: fixed;
        top: 12px;
        left: auto;
        right: 12px;
        width: min(430px, calc(100% - 24px));
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        margin: 0;
        transform: none;
        overflow-y: auto;
        z-index: 3500;
    }

    .created-filter-panel {
        width: min(520px, calc(100% - 24px));
    }

    body .issue-meta .top-worklog-menu {
        width: min(320px, calc(100% - 24px));
    }
}

/* Standalone CSV utilities have their own styles rather than style.css. */
@media (max-width: 600px) {
    body:has(> .container) {
        box-sizing: border-box;
        padding: 16px 12px;
    }

    body > .container {
        box-sizing: border-box;
        width: 100%;
        max-width: 100%;
        padding: 20px 16px;
        overflow-wrap: anywhere;
    }

    body > .container form {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }

    body > .container input[type="file"] {
        box-sizing: border-box;
        width: 100%;
    }

    body > .container pre {
        max-width: 100%;
        overflow-x: auto;
    }
}
