@import url('css/nadis-tokens.css');

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--nadis-font-body);
    color: var(--nadis-body-text);
    background: var(--nadis-page-bg);
}

.nadis-loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.nadis-appbar-brand {
    font-family: var(--nadis-font-display) !important;
    font-weight: 800 !important;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.nadis-appbar-subtitle {
    opacity: 0.92;
    font-weight: 500 !important;
    line-height: 1.15 !important;
}

.nadis-appbar-user {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 40vw;
}

@media (max-width: 960px) {
    .nadis-appbar-subtitle {
        margin-left: 0.5rem !important;
        font-size: 0.875rem !important;
        line-height: 1.1 !important;
        max-width: 4.75rem;
    }

    .nadis-appbar-user,
    .mud-appbar .nadis-appbar-user {
        display: none !important;
    }

    .nadis-page {
        padding: 1rem;
    }

    /* Mobile card tables: keep labels compact and stop values clipping */
    .nadis-practice-table-host .mud-table-row {
        padding: 0.65rem 1rem !important;
    }

    .nadis-practice-table-host .mud-table-cell {
        display: flex !important;
        align-items: flex-start;
        justify-content: flex-start;
        gap: 0.5rem;
        text-align: left !important;
        padding-left: 0.25rem !important;
        padding-right: 0.25rem !important;
        overflow: visible !important;
        white-space: normal !important;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .nadis-practice-table-host .mud-table-cell::before {
        float: none !important;
        flex: 0 0 5.5rem;
        max-width: 5.5rem;
        margin-right: 0 !important;
        padding-right: 0 !important;
        padding-left: 0.15rem;
        white-space: normal;
        line-height: 1.25;
    }

    .nadis-practice-table-host .mud-table-cell > * {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
        overflow: visible !important;
        white-space: normal !important;
        word-break: break-word;
        overflow-wrap: anywhere;
        text-align: left !important;
        justify-content: flex-start !important;
    }

    /* Edit (and similar) actions: do not stretch full card width */
    .nadis-practice-table-host .mud-table-cell .mud-button-root,
    .nadis-practice-table-host .mud-table-cell .mud-button {
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: max-content !important;
        align-self: flex-start;
    }

    .nadis-import-panel {
        padding: 1rem !important;
    }

    .nadis-import-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem;
    }

    .nadis-import-header .mud-chip {
        align-self: flex-start;
    }
}

.nadis-main-content {
    background: var(--nadis-page-bg);
}

.nadis-page {
    padding: 1.5rem 2rem;
}

.nadis-main-content:has(.hangfire-page),
.nadis-main-content:has(.nadis-practices-page),
.nadis-main-content:has(.nadis-members-page),
.nadis-main-content:has(.nadis-media-page) {
    display: flex;
    flex-direction: column;
    /* Include MudAppBar padding-top in the height so content is not clipped under the bar */
    height: 100vh;
    max-height: 100vh;
    box-sizing: border-box;
    overflow: hidden;
    padding-bottom: 0;
}

.nadis-main-content:has(.hangfire-page) .nadis-page {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    padding: 0.75rem 1.25rem 0.75rem;
    overflow: hidden;
}

.nadis-main-content:has(.nadis-practices-page) .nadis-page,
.nadis-main-content:has(.nadis-members-page) .nadis-page,
.nadis-main-content:has(.nadis-media-page) .nadis-page {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.nadis-practices-page,
.nadis-members-page,
.nadis-media-page {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    gap: 0.75rem;
}

.nadis-practices-page-header,
.nadis-members-page-header,
.nadis-media-page-header {
    flex: 0 0 auto;
}

.nadis-practices-panel,
.nadis-members-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.nadis-practices-toolbar,
.nadis-members-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.75rem 1rem 0.5rem;
}

.nadis-practices-footer,
.nadis-members-footer {
    flex: 0 0 auto;
}

.nadis-login-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background:
        radial-gradient(ellipse at top left, rgba(13, 110, 17, 0.08), transparent 55%),
        var(--nadis-page-bg);
}

.nadis-login-card {
    width: 100%;
    max-width: 420px;
}

.nadis-login-brand {
    font-family: var(--nadis-font-display) !important;
    font-weight: 800 !important;
    color: var(--nadis-brand-green) !important;
    letter-spacing: 0.04em;
}

.nadis-stat-label {
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.nadis-file-input {
    display: block;
    max-width: 100%;
}

/* Practice add/edit dialog: fixed body height so tab switches don't shrink the popup */
.nadis-practice-dialog.mud-dialog {
    width: min(960px, 96vw);
}

.nadis-practice-dialog-content {
    height: min(78vh, 720px) !important;
    max-height: min(78vh, 720px) !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column;
    padding-top: 0.75rem !important;
    padding-bottom: 0.5rem !important;
}

.nadis-practice-dialog-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.nadis-practice-tabs {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.nadis-practice-tabs .mud-tabs-panels {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.nadis-practice-tabs .mud-tab-panel {
    height: 100%;
}

.nadis-practice-tab-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 1rem;
    overflow: hidden;
    min-height: 0;
}

.nadis-practice-tab-toolbar {
    flex: 0 0 auto;
}

/* Scroll the host; sticky header via CSS (dialog + practices list) */
.nadis-practice-table-host {
    flex: 1 1 auto;
    height: 0;
    min-height: 180px;
    overflow: auto;
    border: 1px solid var(--nadis-border, #d4e8d0);
    border-radius: 8px;
    background: var(--mud-palette-surface, #fff);
}

.nadis-practices-panel > .nadis-practice-table-host,
.nadis-members-panel > .nadis-practice-table-host {
    border: none;
    border-radius: 0;
    min-height: 0;
}

.nadis-practice-table-host .mud-table-container {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
}

.nadis-practice-table-host .mud-table-root {
    height: auto !important;
}

.nadis-practice-table-host thead th,
.nadis-practice-table-host .mud-table-cell.mud-table-head {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--mud-palette-surface, #fff);
    box-shadow: 0 1px 0 var(--nadis-border, #d4e8d0);
}

.nadis-alert-editor {
    min-height: 180px;
    margin-bottom: 0.75rem;
}

.nadis-alert-editor .ql-editor {
    min-height: 140px;
    font-family: var(--nadis-font-body);
}

.hangfire-page {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.hangfire-page-header {
    flex: 0 0 auto;
}

.hangfire-frame-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding: 0 !important;
    display: flex;
}

.hangfire-frame {
    display: block;
    width: 100%;
    height: 100%;
    flex: 1;
    border: 0;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.nadis-media-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

.nadis-media-sidebar {
    width: 320px;
    max-width: 40%;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--nadis-border, #d4e8d0);
    min-height: 0;
}

.nadis-media-toolbar {
    flex: 0 0 auto;
    padding: 0.75rem;
}

.nadis-media-tree {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding-bottom: 0.75rem;
}

.nadis-media-tree-item {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    user-select: none;
}

.nadis-media-tree-item:hover {
    background: rgba(13, 110, 17, 0.06);
}

.nadis-media-tree-item.mud-selected-item {
    background: rgba(13, 110, 17, 0.12);
}

.nadis-media-detail {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}

.nadis-media-preview {
    max-width: 100%;
    max-height: 280px;
    display: block;
    margin: 0 auto;
    object-fit: contain;
}

.nadis-media-list-thumb {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}

.nadis-media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}

.nadis-media-grid-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    border: 1px solid var(--nadis-border, #d4e8d0);
    border-radius: 8px;
    background: var(--mud-palette-surface, #fff);
    padding: 0.5rem;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
}

.nadis-media-grid-item:hover {
    border-color: var(--nadis-brand-green, #0D6E11);
    background: rgba(13, 110, 17, 0.04);
}

.nadis-media-grid-thumb {
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f3f7f2;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.nadis-media-grid-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.nadis-media-grid-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.nadis-file-input {
    display: block;
    max-width: 100%;
}

.nadis-file-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}

.nadis-upload-label {
    position: relative;
    display: inline-flex;
    cursor: pointer;
    margin: 0;
}

.nadis-upload-label .nadis-file-input-hidden {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}
