/* Phase 2 shared UI components and application shell. */

#wrapper {
    display: flex !important;
    align-items: stretch;
    width: 100%;
    min-height: 100vh;
}

.ui-skip-link {
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 2000;
    padding: 0.7rem 1rem;
    color: var(--primary-contrast);
    background: var(--primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-weight: 700;
    transform: translateY(-160%);
    transition: transform 0.15s ease;
}

.ui-skip-link:focus { color: var(--primary-contrast); transform: translateY(0); }
#main-content:focus { outline: 0; }

#loading.loading {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: grid;
    place-items: center;
    background: color-mix(in srgb, var(--app-bg) 72%, transparent);
    backdrop-filter: blur(3px);
}

#loading.loading #loading-content { position: static; width: 46px; height: 46px; border-width: 4px; border-color: var(--border); border-top-color: var(--primary); }

#wrapper #content-wrapper {
    display: flex !important;
    flex: 1 1 auto;
    flex-direction: column !important;
    width: auto !important;
    min-width: 0;
    min-height: 100vh;
    background: var(--app-bg) !important;
}

#wrapper #content-wrapper #content {
    flex: 1 0 auto;
    width: 100%;
    min-width: 0;
}

#content > .container-fluid {
    width: 100%;
    max-width: 1680px;
    padding: 1.75rem 2rem 2.5rem;
    margin-inline: auto;
}

.app-topbar {
    min-height: 68px;
    padding: 0.75rem 2rem;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 1030;
}

.app-topbar__mobile-brand {
    color: var(--text-primary);
    font-weight: 750;
    letter-spacing: -0.02em;
}

.sidebar-brand-wrapper { justify-content: flex-start; }
.sidebar-brand { gap: 0.7rem; min-width: 0; }
.sidebar-brand-logo { width: 42px; max-height: 42px; }
.sidebar-brand-copy { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.sidebar-brand-copy strong { overflow: hidden; color: var(--sidebar-strong); font-size: 0.9rem; font-weight: 750; letter-spacing: -0.015em; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-brand-copy small { margin-top: 0.18rem; color: var(--sidebar-muted); font-size: 0.62rem; letter-spacing: 0.035em; text-transform: uppercase; }
#accordionSidebar.toggled .sidebar-brand-copy { display: none; }
#accordionSidebar.toggled .sidebar-brand-logo { width: 34px; }

#accordionSidebar .sidebar-link.active,
#accordionSidebar .sidebar-sublink.active {
    background: color-mix(in srgb, var(--primary) 20%, var(--sidebar-surface)) !important;
    color: var(--sidebar-strong) !important;
    box-shadow: inset 3px 0 0 var(--primary);
}

#accordionSidebar .sidebar-link.active .sidebar-icon {
    background: color-mix(in srgb, var(--primary) 24%, transparent);
    color: var(--primary);
}

/* The sidebar stays dark in light mode and therefore uses a dedicated,
   brighter foreground scale than the light workspace. */
body.theme-light #accordionSidebar { --sidebar-muted: #d5e3e2; --sidebar-strong: #ffffff; }
body.theme-light #accordionSidebar .sidebar-section-label { color: #eef7f6 !important; }
body.theme-light #accordionSidebar .sidebar-link,
body.theme-light #accordionSidebar .sidebar-sublink { color: #cfdfde !important; }
body.theme-light #accordionSidebar .sidebar-link .sidebar-icon { color: #c4d9d7; background: rgba(255, 255, 255, 0.09); }
body.theme-light #accordionSidebar .sidebar-link.active,
body.theme-light #accordionSidebar .sidebar-sublink.active { color: #ffffff !important; }
body.theme-light #accordionSidebar .sidebar-link.active .sidebar-icon { color: #ffffff; background: rgba(255, 255, 255, 0.14); }
body.theme-light #accordionSidebar .sidebar-link:hover,
body.theme-light #accordionSidebar .sidebar-sublink:hover { color: #ffffff !important; background: rgba(255, 255, 255, 0.09) !important; border-color: rgba(255, 255, 255, 0.11); }
body.theme-light #accordionSidebar .sidebar-link:hover .sidebar-icon { color: #ffffff; background: rgba(255, 255, 255, 0.14); }
body.theme-light #accordionSidebar .quick-action { color: #6fddd5; background: rgba(255, 255, 255, 0.055); border-color: rgba(111, 221, 213, 0.24); box-shadow: none; }
body.theme-light #accordionSidebar .quick-action:hover { color: #a6eee9; background: rgba(111, 221, 213, 0.12); border-color: rgba(111, 221, 213, 0.38); }
body.theme-light #accordionSidebar .quick-action kbd { color: #e8fbfa; background: rgba(111, 221, 213, 0.16); }
body.theme-light #accordionSidebar .sidebar-brand-logo { padding: 0.2rem; background: rgba(255, 255, 255, 0.055); border-radius: 0.65rem; filter: brightness(1.2) saturate(1.08); }
body.theme-light #accordionSidebar .sidebar-badge.badge-neutral { color: #e5f0ef; background: rgba(213, 227, 226, 0.18); }
body.theme-light #accordionSidebar .sidebar-nav { scrollbar-color: rgba(213, 227, 226, 0.6) transparent; }
body.theme-light #accordionSidebar .sidebar-nav::-webkit-scrollbar-thumb { background: rgba(213, 227, 226, 0.6); }

.ws-icon-badge {
    background: var(--primary-soft) !important;
    color: var(--primary) !important;
}

.app-topbar__search {
    position: relative;
    flex: 0 1 520px;
    min-width: 300px;
}

.app-topbar__search > i {
    position: absolute;
    left: 0.95rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-subtle);
    pointer-events: none;
    z-index: 2;
}

.app-topbar__search .form-control {
    height: 42px;
    padding-left: 2.65rem;
    padding-right: 5.5rem;
    border-radius: 0.75rem;
    background: var(--surface-alt) !important;
    border-color: transparent !important;
}

.app-topbar__search .form-control:focus {
    background: var(--surface) !important;
    border-color: var(--primary) !important;
}

.app-topbar__shortcut {
    position: absolute;
    right: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.12rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    background: var(--surface);
    color: var(--text-subtle);
    font-size: 0.68rem;
    box-shadow: none;
}

.app-topbar__date {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    color: var(--text-muted);
}

.app-topbar__date strong {
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 650;
}

.app-topbar__date span {
    margin-top: 0.2rem;
    font-size: 0.72rem;
}

.app-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    background: var(--surface);
    color: var(--text-muted);
}

.app-icon-button:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

.ui-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.ui-page-header__title-row {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
}

.ui-page-header__icon,
.ui-card__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background: var(--primary-soft);
    color: var(--primary);
}

.ui-page-header__icon {
    width: 44px;
    height: 44px;
    border-radius: 0.8rem;
    font-size: 1rem;
}

.ui-page-header h1 {
    margin: 0;
    color: var(--text-primary);
    font-size: clamp(1.35rem, 2vw, 1.65rem);
    font-weight: 750;
    line-height: 1.25;
    letter-spacing: -0.025em;
}

.ui-page-header p {
    max-width: 720px;
    margin: 0.35rem 0 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.ui-page-header__actions,
.ui-card__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.ui-eyebrow {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--primary);
    font-size: 0.7rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.ui-card {
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.ui-card__header,
.ui-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-color: var(--border);
}

.ui-card__header { border-bottom: 1px solid var(--border); }
.ui-card__footer { border-top: 1px solid var(--border); background: var(--surface-alt); }
.ui-card__heading { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.ui-card__icon { width: 32px; height: 32px; border-radius: 0.6rem; font-size: 0.8rem; }
.ui-card__heading h2 { margin: 0; font-size: 0.95rem; font-weight: 700; }
.ui-card__heading p { margin: 0.15rem 0 0; color: var(--text-muted); font-size: 0.76rem; }
.ui-card__body { padding: 1.25rem; }
.ui-card__body--flush { padding: 0; }

.ui-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.28rem 0.65rem;
    border-radius: 50rem;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
}

.ui-status__dot { width: 0.4rem; height: 0.4rem; border-radius: 50%; background: currentColor; }
.ui-status--neutral { color: var(--text-muted); background: var(--surface-alt); }
.ui-status--primary { color: var(--primary); background: var(--primary-soft); }
.ui-status--success { color: var(--success); background: color-mix(in srgb, var(--success) 13%, transparent); }
.ui-status--warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent); }
.ui-status--danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 13%, transparent); }
.ui-status--info { color: var(--info); background: color-mix(in srgb, var(--info) 13%, transparent); }

.ui-field { margin-bottom: 1rem; }
.ui-field__label { display: block; margin-bottom: 0.4rem; color: var(--text-primary); font-size: 0.8rem; font-weight: 650; }
.ui-field__required { color: var(--danger); }
.ui-field__hint { display: block; margin-top: 0.35rem; color: var(--text-subtle); font-size: 0.73rem; }

.ui-empty-state { max-width: 520px; margin: auto; padding: 3rem 1.5rem; text-align: center; }
.ui-empty-state__icon { display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; margin-bottom: 1rem; border-radius: 1rem; background: var(--surface-alt); color: var(--text-subtle); font-size: 1.15rem; }
.ui-empty-state h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.ui-empty-state p { margin: 0.45rem auto 0; color: var(--text-muted); font-size: 0.84rem; }
.ui-empty-state__action { margin-top: 1rem; }

.ui-sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.5rem -1.25rem -1.25rem;
    padding: 0.9rem 1.25rem;
    background: color-mix(in srgb, var(--surface) 95%, transparent);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(12px);
}
.ui-sticky-actions__summary { color: var(--text-muted); font-size: 0.78rem; }
.ui-sticky-actions__buttons { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 0.55rem; margin-left: auto; }

.ui-flash-stack { display: grid; gap: 0.65rem; margin-bottom: 1rem; }
.ui-flash { display: flex; align-items: flex-start; gap: 0.7rem; padding: 0.8rem 0.95rem; border: 1px solid; border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.ui-flash > i { margin-top: 0.15rem; }
.ui-flash > div { display: flex; flex-direction: column; flex: 1; }
.ui-flash strong { font-size: 0.8rem; }
.ui-flash span { color: var(--text-muted); font-size: 0.8rem; }
.ui-flash--success { border-color: color-mix(in srgb, var(--success) 35%, var(--border)); color: var(--success); }
.ui-flash--info { border-color: color-mix(in srgb, var(--info) 35%, var(--border)); color: var(--info); }
.ui-flash--danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); color: var(--danger); }
.ui-flash__close { border: 0; background: transparent; color: var(--text-subtle); }

.list-page .list-toolbar { margin-bottom: 1.5rem; }
.list-page .list-card { overflow: hidden; background: var(--surface); border: 1px solid var(--border) !important; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm) !important; }
.list-page .list-card .card-body { padding: 1.15rem; }

table.dataTable,
.table {
    color: var(--text-primary) !important;
}
.table-responsive[tabindex="0"]:focus-visible { border-radius: var(--radius-md); box-shadow: var(--focus-ring); outline: 1px solid var(--primary); }
.table-responsive { scrollbar-color: var(--border-strong) transparent; }
.table-responsive::-webkit-scrollbar { height: 8px; }
.table-responsive::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 50rem; }
.table thead th,
table.dataTable thead th {
    padding: 0.8rem 0.75rem !important;
    background: var(--surface-alt) !important;
    color: var(--text-muted) !important;
    border-bottom: 1px solid var(--border) !important;
    font-size: 0.7rem;
    font-weight: 750;
    letter-spacing: 0.045em;
    text-transform: uppercase;
}
.table tbody td,
table.dataTable tbody td {
    padding: 0.8rem 0.75rem !important;
    border-color: var(--border) !important;
    vertical-align: middle;
}
.table-hover tbody tr:hover,
table.dataTable.hover tbody tr:hover {
    background: var(--surface-selected) !important;
}
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--input-border) !important;
    border-radius: 0.55rem;
    background: var(--input-bg) !important;
    color: var(--input-text) !important;
}

.btn {
    border-radius: 0.6rem;
    font-weight: 650;
}
.btn-sm { border-radius: 0.5rem; }

@media (max-width: 991.98px) {
    #content > .container-fluid { padding: 1.25rem 1rem 2rem; }
    .app-topbar { min-height: 60px; padding: 0.6rem 1rem; }
    .ui-page-header { flex-direction: column; gap: 1rem; }
    .ui-page-header__actions { width: 100%; justify-content: flex-start; }
}

@media (max-width: 575.98px) {
    .ui-page-header__actions > .btn,
    .ui-page-header__actions > a { flex: 1 1 auto; }
    .ui-card__body { padding: 1rem; }
    .ui-sticky-actions { align-items: stretch; flex-direction: column; margin-inline: -1rem; margin-bottom: -1rem; padding: 0.85rem 1rem; }
    .ui-sticky-actions__buttons { width: 100%; }
    .ui-sticky-actions__buttons .btn { flex: 1 1 auto; }
    .table-responsive > .table { min-width: 680px; }
    .dataTables_wrapper { overflow-x: auto; overscroll-behavior-inline: contain; }
    .dataTables_wrapper table.dataTable { min-width: 680px; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto !important; }
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
