/* Blazor route navigation focuses headings programmatically. Keep that focus
   from drawing a visible outline while preserving keyboard focus indicators
   for interactive controls. */
h1[tabindex="-1"]:focus {
    outline: none !important;
}

/* Shared app shell: flex children must be allowed to shrink with the viewport. */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    min-width: 0;
}

.app-shell,
.app-main,
.app-content,
.admin-page,
.history-page,
.settings-page,
.upload-page {
    min-width: 0;
    max-width: 100%;
}

.app-main {
    flex: 1 1 0%;
}

.app-content {
    overscroll-behavior-x: none;
}

.header-icon-button {
    min-width: 2.75rem !important;
    min-height: 2.75rem !important;
}

.app-shell nav a {
    min-height: 2.75rem;
}

.admin-page-header.flex {
    min-width: 0;
    gap: 1rem;
}

.admin-page-header.flex > :first-child {
    min-width: 0;
    flex: 1 1 auto;
}

.admin-page-header h1,
.admin-page-header p {
    max-width: 100%;
    overflow-wrap: anywhere;
}

.admin-page-actions {
    min-width: 0;
    flex-wrap: wrap;
}

.admin-page-action,
.admin-page-actions > *,
.history-clear-button {
    min-height: 2.75rem;
}

/* Tables become labelled, stacked records before the desktop sidebar leaves
   enough room for a multi-column table. This keeps all fields available
   without making the page itself horizontally scroll. */
.responsive-table-shell {
    width: 100%;
    min-width: 0;
}

.responsive-table-shell > .overflow-x-auto {
    min-width: 0;
    max-width: 100%;
}

.responsive-table {
    min-width: 100%;
}

.responsive-table img {
    max-width: 100%;
}

.responsive-table-actions {
    min-width: 0;
}

.table-action-button {
    min-width: 2.75rem;
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* The history grid sizes itself from the available content column. At tablet
   widths the sidebar is still present, so auto-fit avoids two unusably narrow
   horizontal cards. */
.history-grid {
    grid-template-columns: 1fr;
}

.history-card {
    min-width: 0;
    align-items: flex-start;
}

.history-thumb {
    width: clamp(8rem, 32%, 10rem);
    min-width: 7.5rem;
    flex: 0 1 clamp(8rem, 32%, 10rem);
}

.history-card-content {
    min-width: 0;
}

.history-card h4,
.history-card p {
    max-width: 100%;
    overflow-wrap: anywhere;
}

.history-remove-button {
    flex-shrink: 0;
}

.settings-tabs,
.settings-panel,
.settings-panel input,
.settings-panel select,
.settings-panel textarea {
    min-width: 0;
    max-width: 100%;
}

.settings-tabs button {
    min-height: 2.75rem;
}

.settings-toggle-row {
    min-width: 0;
}

.settings-toggle-row > :first-child {
    min-width: 0;
    overflow-wrap: anywhere;
}

.settings-toggle-control {
    flex-shrink: 0;
}

.upload-form {
    min-width: 0;
    max-width: 100%;
}

.upload-dropzone {
    min-width: 0;
    padding: clamp(1.5rem, 6vw, 2.5rem) 1rem;
}

.upload-dropzone h3,
.upload-dropzone p {
    overflow-wrap: anywhere;
}

.upload-form-actions {
    min-width: 0;
    flex-wrap: wrap;
}

.notification-popover {
    min-width: 0;
}

@media (min-width: 48rem) {
    .history-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
    }
}

@media (max-width: 63.999rem) {
    .responsive-table-shell {
        overflow: hidden;
    }

    .responsive-table-shell > .overflow-x-auto {
        overflow: visible;
    }

    .responsive-table {
        display: block;
        width: 100%;
        white-space: normal !important;
    }

    .responsive-table > thead {
        display: none;
    }

    .responsive-table > tbody {
        display: grid;
        gap: 0.75rem;
        padding: 0.75rem;
    }

    .responsive-table > tbody > tr {
        display: grid;
        gap: 0.25rem;
        min-width: 0;
        padding: 0.875rem 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.875rem;
        background: #ffffff;
        border-top-width: 1px !important;
    }

    .dark .responsive-table > tbody > tr {
        border-color: #2a2a2a;
        background: #1f1f1f;
    }

    .responsive-table > tbody > tr > td {
        display: grid;
        grid-template-columns: minmax(6.5rem, 36%) minmax(0, 1fr);
        align-items: start;
        gap: 0.75rem;
        min-width: 0;
        padding: 0.45rem 0;
        border: 0 !important;
        text-align: left;
        white-space: normal !important;
        overflow-wrap: anywhere;
    }

    .responsive-table > tbody > tr > td::before {
        content: attr(data-label);
        min-width: 0;
        color: #64748b;
        font-size: 0.6875rem;
        font-weight: 700;
        letter-spacing: 0.06em;
        line-height: 1.25rem;
        text-transform: uppercase;
    }

    .dark .responsive-table > tbody > tr > td::before {
        color: #94a3b8;
    }

    .responsive-table > tbody > tr > td[colspan],
    .responsive-table > tbody > tr > td:not([data-label]) {
        display: block;
        text-align: center;
    }

    .responsive-table > tbody > tr > td[colspan]::before,
    .responsive-table > tbody > tr > td:not([data-label])::before {
        display: none;
    }

    .responsive-table > tbody > tr > td[data-label="Video"] {
        display: block;
    }

    .responsive-table > tbody > tr > td[data-label="Video"]::before {
        display: block;
        margin-bottom: 0.5rem;
    }

    .responsive-table > tbody > tr > td[data-label="Video"] > div {
        display: flex;
        width: 100%;
        min-width: 0;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .responsive-table > tbody > tr > td[data-label="Video"] > div > div:last-child {
        min-width: 0;
    }

    .responsive-table > tbody > tr > td[data-label="Kullanıcı"] > div,
    .responsive-table > tbody > tr > td[data-label="Kullanıcı"] > div > div:last-child {
        min-width: 0;
    }

    .responsive-table-actions {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 0.5rem;
        opacity: 1 !important;
    }

    .responsive-table-actions button {
        flex: 0 0 2.75rem;
    }

    .settings-panel {
        padding: 1rem;
    }

    .settings-toggle-row {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .settings-toggle-row > :first-child {
        flex: 1 1 12rem;
    }

    .settings-toggle-control {
        margin-left: auto;
    }
}

@media (max-width: 47.999rem) {
    .admin-page-header.flex {
        flex-direction: column;
        align-items: stretch;
    }

    .admin-page-header.flex > .admin-page-action,
    .admin-page-actions,
    .history-page-header .history-clear-button {
        width: 100%;
    }

    .admin-page-action,
    .admin-page-actions > *,
    .history-page-header .history-clear-button {
        justify-content: center;
    }

    .admin-page-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .history-card {
        display: grid;
        grid-template-columns: minmax(6.5rem, 30%) minmax(0, 1fr) 2.75rem;
        gap: 0.75rem;
        padding: 0.5rem;
    }

    .history-thumb {
        width: 100%;
        min-width: 0;
        flex: none;
    }

    .history-card-content {
        grid-column: 2;
    }

    .history-remove-button {
        grid-column: 3;
        grid-row: 1;
    }

    .upload-form {
        padding: 1rem;
    }

    .upload-form-actions {
        flex-direction: column-reverse;
        align-items: stretch;
        gap: 0.5rem;
    }

    .upload-form-actions > button {
        width: 100%;
        min-height: 2.75rem;
    }

    .notification-popover {
        position: fixed;
        top: 4.5rem;
        right: 0.75rem;
        left: 0.75rem;
        width: auto;
        max-width: none;
        margin-top: 0;
    }
}

@media (max-width: 63.999rem) {
    .users-page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .users-page-header .admin-page-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
    }

    .users-page-header .admin-page-actions > * {
        width: 100%;
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .page-transition,
    .history-card,
    .table-action-button {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Keep the home category section compact on mobile and restore its original
   spacing once the desktop content column has enough room. */
@media (min-width: 48rem) {
    .home-category-section {
        margin-top: 7rem;
        padding-top: 4rem;
    }
}

/* Center only the final home category action on narrow portrait layouts. */
@media (max-width: 47.999rem) {
    .home-category-section .home-category-all-link {
        grid-column: 1 / -1;
        justify-self: center;
        width: max-content;
        max-width: 100%;
    }
}

/* Premium account treatment for the portrait mobile drawer only. */
@media (max-width: 47.999rem) and (orientation: portrait) {
    .mobile-sidebar-user-card {
        display: flex;
        width: 100%;
        min-width: 0;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.75rem;
        border-radius: 1rem;
        background: linear-gradient(135deg, oklch(0.98 0.018 230), oklch(1 0 0));
        box-shadow:
            0 0 0 1px oklch(0 0 0 / 0.06),
            0 8px 18px -12px oklch(0 0 0 / 0.2);
    }

    .mobile-sidebar-user-identity {
        display: flex;
        min-width: 0;
        align-items: center;
        gap: 0.75rem;
    }

    .mobile-sidebar-user-avatar {
        display: flex;
        width: 2.75rem;
        height: 2.75rem;
        flex: 0 0 2.75rem;
        align-items: center;
        justify-content: center;
        border-radius: 0.875rem;
        background: linear-gradient(135deg, var(--color-brand-500), var(--color-brand-600));
        color: oklch(1 0 0);
        font-size: 0.75rem;
        font-weight: 800;
        letter-spacing: 0.04em;
        box-shadow:
            0 0 0 3px oklch(1 0 0 / 0.9),
            0 7px 14px -8px oklch(0.55 0.15 230 / 0.55);
    }

    .mobile-sidebar-user-copy {
        display: flex;
        min-width: 0;
        flex-direction: column;
        gap: 0.125rem;
    }

    .mobile-sidebar-user-label {
        overflow: hidden;
        color: oklch(0.5 0.04 260);
        font-size: 0.625rem;
        font-weight: 700;
        letter-spacing: 0.1em;
        line-height: 1rem;
        text-overflow: ellipsis;
        text-transform: uppercase;
        white-space: nowrap;
    }

    .mobile-sidebar-user-name {
        display: block;
        max-width: 9rem;
        overflow: hidden;
        color: oklch(0.22 0.03 260);
        font-size: 0.9375rem;
        font-weight: 700;
        line-height: 1.25rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-sidebar-logout-button {
        display: flex;
        width: 2.75rem;
        height: 2.75rem;
        flex: 0 0 2.75rem;
        align-items: center;
        justify-content: center;
        border-radius: 0.875rem;
        background: oklch(1 0 0 / 0.78);
        box-shadow: 0 0 0 1px oklch(0 0 0 / 0.06);
        color: oklch(0.52 0.04 260);
        transition-property: background-color, color, box-shadow, scale;
        transition-duration: 150ms;
        transition-timing-function: ease-out;
    }

    .mobile-sidebar-logout-button:hover {
        background: oklch(0.98 0.02 25);
        box-shadow:
            0 0 0 1px oklch(0.63 0.2 25 / 0.16),
            0 6px 14px -10px oklch(0.5 0.18 25 / 0.42);
        color: var(--color-red-600);
    }

    .mobile-sidebar-logout-button:active {
        scale: 0.96;
    }

    .dark .mobile-sidebar-user-card {
        background: linear-gradient(135deg, oklch(0.24 0.035 245), oklch(0.17 0.012 260));
        box-shadow:
            0 0 0 1px oklch(1 0 0 / 0.08),
            0 10px 20px -14px oklch(0 0 0 / 0.65);
    }

    .dark .mobile-sidebar-user-avatar {
        box-shadow:
            0 0 0 3px oklch(0.18 0.01 260),
            0 7px 14px -8px oklch(0.55 0.15 230 / 0.5);
    }

    .dark .mobile-sidebar-user-label {
        color: oklch(0.72 0.03 250);
    }

    .dark .mobile-sidebar-user-name {
        color: oklch(0.98 0.01 260);
    }

    .dark .mobile-sidebar-logout-button {
        background: oklch(1 0 0 / 0.06);
        box-shadow: 0 0 0 1px oklch(1 0 0 / 0.1);
        color: oklch(0.76 0.03 250);
    }

    .dark .mobile-sidebar-logout-button:hover {
        background: oklch(0.34 0.035 25);
        box-shadow: 0 0 0 1px oklch(0.7 0.16 25 / 0.24);
        color: var(--color-red-400);
    }
}
