/* D365 Attachments Archive - theme.
   Look inspired by the Finance & Operations shell (navy top bar, navigation pane,
   action pane, filter pane, dense grid, fact box), right-to-left by default, left-to-right in English (logical properties). Fluent-style colours;
   no Microsoft logos or product branding. Components use the d- prefix so they do not
   collide with Bootstrap classes. */

:root {
    --d-nav: #002050;
    --d-nav-hover: #0c3063;
    --d-primary: #0078d4;
    --d-primary-hover: #106ebe;
    --d-primary-pressed: #005a9e;
    --d-bg: #f8f8f8;
    --d-surface: #ffffff;
    --d-border: #e1dfdd;
    --d-border-strong: #c8c6c4;
    --d-text: #323130;
    --d-text-subtle: #605e5c;
    --d-text-disabled: #a19f9d;
    --d-hover: #f3f2f1;
    --d-selected: #deecf9;
    --d-danger: #a4262c;
    --d-danger-bg: #fde7e9;
    --d-success: #107c10;
    --d-success-bg: #dff6dd;
    --d-warning-bg: #fff4ce;
    --d-info-bg: #f3f9fd;
    --d-excel: #107c41;
    --d-font: "Segoe UI", "Segoe UI Web (Arabic)", Tahoma, Arial, sans-serif;
    --d-topbar-h: 48px;
    --d-nav-w: 220px;
    --d-nav-w-collapsed: 48px;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--d-font);
    font-size: 14px;
    color: var(--d-text);
    background: var(--d-bg);
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* ---------- Shell ---------- */
.d-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.d-topbar {
    height: var(--d-topbar-h);
    flex: 0 0 var(--d-topbar-h);
    background: var(--d-nav);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0 0.25rem;
}

.d-topbar-btn {
    width: var(--d-topbar-h);
    height: var(--d-topbar-h);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
}

.d-topbar-btn:hover {
    background: var(--d-nav-hover);
}

.d-app-name {
    font-size: 15px;
    font-weight: 600;
    padding: 0 0.5rem;
    white-space: nowrap;
}

.d-topbar-spacer {
    flex: 1;
}

.d-user {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.75rem;
    font-size: 13px;
    white-space: nowrap;
}

.d-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

.d-navpane {
    width: var(--d-nav-w);
    flex: 0 0 var(--d-nav-w);
    background: var(--d-surface);
    border-inline-end: 1px solid var(--d-border);
    overflow-y: auto;
    transition: width 0.15s ease, flex-basis 0.15s ease;
    padding-top: 0.5rem;
}

.nav-collapsed .d-navpane {
    width: var(--d-nav-w-collapsed);
    flex-basis: var(--d-nav-w-collapsed);
}

.nav-collapsed .d-nav-text {
    display: none;
}

.d-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.d-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: 40px;
    padding: 0 0.9rem;
    color: var(--d-text);
    text-decoration: none;
    border-inline-start: 3px solid transparent;
    white-space: nowrap;
}

.d-nav-item:hover {
    background: var(--d-hover);
    color: var(--d-text);
}

.d-nav-item.active {
    background: var(--d-selected);
    border-inline-start-color: var(--d-primary);
    font-weight: 600;
}

.d-content {
    flex: 1;
    min-width: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.d-content-plain {
    min-height: 100vh;
}

/* ---------- Page chrome ---------- */
.d-actionpane {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
    min-height: 44px;
    padding: 0 0.75rem;
    background: var(--d-surface);
    border-bottom: 1px solid var(--d-border);
}

.d-action {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 36px;
    padding: 0 0.7rem;
    background: transparent;
    border: none;
    border-radius: 2px;
    color: var(--d-text);
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.d-action:hover:not(:disabled) {
    background: var(--d-hover);
}

.d-action:disabled {
    color: var(--d-text-disabled);
    cursor: default;
}

.d-action .d-icon {
    color: var(--d-primary);
}

.d-action.excel .d-icon {
    color: var(--d-excel);
}

.d-page-header {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    padding: 1rem 1.25rem 0.5rem;
}

.d-page-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--d-text);
}

.d-page-subtitle {
    color: var(--d-text-subtle);
    font-size: 13px;
}

.d-page-body {
    padding: 0.5rem 1.25rem 1.25rem;
}

/* ---------- Controls ---------- */
.d-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    height: 32px;
    padding: 0 1rem;
    font: inherit;
    font-weight: 600;
    color: var(--d-text);
    background: var(--d-surface);
    border: 1px solid var(--d-border-strong);
    border-radius: 2px;
    cursor: pointer;
    white-space: nowrap;
}

.d-btn:hover:not(:disabled) {
    background: var(--d-hover);
}

.d-btn-primary {
    color: #fff;
    background: var(--d-primary);
    border-color: var(--d-primary);
}

.d-btn-primary:hover:not(:disabled) {
    background: var(--d-primary-hover);
    border-color: var(--d-primary-hover);
}

.d-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.d-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 2px;
    color: var(--d-primary);
    cursor: pointer;
}

.d-icon-btn:hover {
    background: var(--d-hover);
    border-color: var(--d-border);
}

.d-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

.d-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--d-text);
}

.d-input {
    width: 100%;
    height: 32px;
    padding: 0 0.5rem;
    font: inherit;
    color: var(--d-text);
    background: var(--d-surface);
    border: 1px solid var(--d-border-strong);
    border-radius: 2px;
}

.d-input:hover {
    border-color: var(--d-text-subtle);
}

.d-input:focus {
    outline: none;
    border-color: var(--d-primary);
    box-shadow: inset 0 0 0 1px var(--d-primary);
}

.d-input:disabled {
    background: var(--d-hover);
    color: var(--d-text-subtle);
}

.d-check {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

/* ---------- Messages ---------- */
.d-message {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 13px;
    border-inline-start: 3px solid transparent;
}

.d-message.info { background: var(--d-info-bg); border-inline-start-color: var(--d-primary); }
.d-message.success { background: var(--d-success-bg); border-inline-start-color: var(--d-success); }
.d-message.error { background: var(--d-danger-bg); border-inline-start-color: var(--d-danger); color: var(--d-danger); }
.d-message.warning { background: var(--d-warning-bg); border-inline-start-color: #c19c00; }

.d-empty {
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--d-text-subtle);
}

.d-badge {
    display: inline-block;
    padding: 0 0.5rem;
    line-height: 20px;
    font-size: 12px;
    border-radius: 10px;
}

.d-badge.ok { background: var(--d-success-bg); color: var(--d-success); }
.d-badge.off { background: var(--d-danger-bg); color: var(--d-danger); }

/* ---------- Section (FastTab-like) ---------- */
.d-section {
    background: var(--d-surface);
    border: 1px solid var(--d-border);
    margin-bottom: 1rem;
}

.d-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--d-border);
}

.d-section-body {
    padding: 1rem;
}

.d-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    column-gap: 1.5rem;
}

/* ---------- List page: filter pane / grid / fact box ---------- */
.d-listpage {
    flex: 1;
    display: flex;
    min-height: 0;
    gap: 0;
}

.d-filterpane {
    width: 260px;
    flex: 0 0 260px;
    background: var(--d-surface);
    border-inline-end: 1px solid var(--d-border);
    padding: 0.75rem 1rem;
    overflow-y: auto;
}

.d-filterpane-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.d-filterpane-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.d-listmain {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--d-surface);
}

.d-quickfilter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--d-border);
}

.d-quickfilter .d-input {
    max-width: 320px;
}

.d-factbox {
    width: 38%;
    min-width: 320px;
    max-width: 720px;
    flex: 0 0 auto;
    background: var(--d-surface);
    border-inline-start: 1px solid var(--d-border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ---------- Grid ---------- */
.d-grid-wrap {
    flex: 1;
    overflow: auto;
}

.d-datagrid {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.d-datagrid th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--d-surface);
    text-align: start;
    font-weight: 600;
    padding: 0 0.6rem;
    height: 36px;
    border-bottom: 1px solid var(--d-border-strong);
    white-space: nowrap;
}

.d-datagrid th.sortable {
    cursor: pointer;
    user-select: none;
}

.d-datagrid th.sortable:hover {
    background: var(--d-hover);
}

.d-datagrid th.sorted {
    color: var(--d-primary);
}

.d-datagrid td {
    padding: 0 0.6rem;
    height: 34px;
    border-bottom: 1px solid var(--d-border);
    text-align: start;
    vertical-align: middle;
}

.d-datagrid tbody tr {
    cursor: pointer;
}

.d-datagrid tbody tr:hover {
    background: var(--d-hover);
}

.d-datagrid tbody tr.selected {
    background: var(--d-selected);
}

.d-datagrid tbody tr.selected td:first-child {
    box-shadow: inset -3px 0 0 var(--d-primary);
}

.d-datagrid .cell-main {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.d-datagrid .cell-nowrap {
    white-space: nowrap;
}

.d-datagrid .cell-actions {
    white-space: nowrap;
    width: 1%;
}

.d-link {
    color: var(--d-primary);
}

.d-pager {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: nowrap;
    white-space: nowrap;
    overflow-x: auto;
    padding: 0.4rem 0.75rem;
    border-top: 1px solid var(--d-border);
    font-size: 13px;
    color: var(--d-text-subtle);
}

.d-pager .d-input {
    width: 70px;
    height: 28px;
    text-align: center;
}

.d-pager select.d-input {
    width: 70px;
}

.d-pager-spacer {
    flex: 1;
}

/* ---------- Loading / Blazor error ---------- */
.d-splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: var(--d-bg);
}

.d-splash-logo {
    animation: d-pulse 1.4s ease-in-out infinite;
}

@keyframes d-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.94); }
}

.loading-progress-text {
    color: var(--d-text-subtle);
    font-size: 14px;
}

.d-logo {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    margin-inline-start: 0.25rem;
}

#blazor-error-ui {
    background: var(--d-warning-bg);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.75rem 2.5rem;
    position: fixed;
    right: 0;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    inset-inline-end: 1rem;
}

@media (max-width: 900px) {
    .d-filterpane { display: none; }
    .d-listpage.show-filters .d-filterpane { display: block; position: absolute; z-index: 5; height: calc(100vh - var(--d-topbar-h) - 44px); }
    .d-factbox { position: fixed; inset: var(--d-topbar-h) 0 0 0; width: auto; max-width: none; min-width: 0; z-index: 10; }
    .d-navpane { width: var(--d-nav-w-collapsed); flex-basis: var(--d-nav-w-collapsed); }
    .d-nav-text { display: none; }
}

/* ---------- Direction-specific touches (left-to-right / English) ---------- */
[dir="ltr"] .d-datagrid tbody tr.selected td:first-child {
    box-shadow: inset 3px 0 0 var(--d-primary);
}

/* Pager arrows are drawn for right-to-left; mirror them in English. */
[dir="ltr"] .d-pager .d-icon {
    transform: scaleX(-1);
}

.d-lang-btn {
    height: 30px;
    padding: 0 0.75rem;
    margin: 0 0.25rem;
    font: inherit;
    font-size: 13px;
    color: #fff;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 2px;
    cursor: pointer;
}

.d-lang-btn:hover {
    background: var(--d-nav-hover);
}

/* ---------- Busy indicators (moving dots + spinner overlay) ---------- */
:root { --d-dir: 1; }
[dir="rtl"] { --d-dir: -1; }

.d-progress {
    position: relative;
    height: 4px;
    overflow: hidden;
    flex: 0 0 4px;
}

.d-progress span {
    position: absolute;
    top: 0;
    inset-inline-start: 0;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--d-primary);
    opacity: 0;
    animation: d-dots 2.6s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.d-progress span:nth-child(2) { animation-delay: 0.15s; }
.d-progress span:nth-child(3) { animation-delay: 0.3s; }
.d-progress span:nth-child(4) { animation-delay: 0.45s; }
.d-progress span:nth-child(5) { animation-delay: 0.6s; }

/* Fast in, slow through the middle, fast out - like the Fluent "loading dots". */
@keyframes d-dots {
    0% { opacity: 0; transform: translateX(0); }
    8% { opacity: 1; }
    35% { transform: translateX(calc(var(--d-dir) * 40cqw)); }
    65% { transform: translateX(calc(var(--d-dir) * 60cqw)); }
    92% { opacity: 1; }
    100% { opacity: 0; transform: translateX(calc(var(--d-dir) * 100cqw)); }
}

.d-listmain {
    position: relative;
    container-type: inline-size;
}

.d-busy-overlay {
    position: absolute;
    inset: 4px 0 0 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 12vh;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.7);
    color: var(--d-text);
    font-size: 14px;
}

.d-busy-sub {
    color: var(--d-text-subtle);
    font-size: 13px;
}

.d-spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid var(--d-selected);
    border-top-color: var(--d-primary);
    animation: d-spin 0.9s linear infinite;
}

.d-spinner.small {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

@keyframes d-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .d-progress span, .d-spinner, .d-splash-logo { animation-duration: 3s; }
}

.search-start {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding-top: 15vh;
}

.search-start .d-icon {
    color: var(--d-border-strong);
}
