/* ==========================================================================
   KRIN — Layout layer
   Application shell: configurable sidebar, dynamic header, breadcrumb, content.
   ========================================================================== */

.ds-app {
    display: grid;
    grid-template-columns: var(--ds-sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns var(--ds-duration-base) var(--ds-ease-standard);
}

.ds-app[data-sidebar="collapsed"] { grid-template-columns: var(--ds-sidebar-collapsed-width) minmax(0, 1fr); }
.ds-app[data-sidebar="hidden"] { grid-template-columns: 0 minmax(0, 1fr); }

/* ---------- Sidebar ---------- */
.ds-sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-4);
    padding: var(--ds-space-5) var(--ds-space-3);
    background: var(--ds-surface-sidebar);
    border-inline-end: 1px solid var(--ds-border-subtle);
    z-index: var(--ds-z-sidebar);
    overflow: hidden auto;
}

.ds-sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--ds-space-3);
    padding: var(--ds-space-1) var(--ds-space-3);
    color: var(--ds-text-strong);
}
.ds-sidebar__brand:hover { color: var(--ds-text-strong); text-decoration: none; }

.ds-brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: var(--ds-radius-md);
    background: linear-gradient(150deg, var(--ds-brand-400), var(--ds-brand-700));
    color: #fff;
    font-weight: var(--ds-font-weight-bold);
    font-size: var(--ds-font-size-lg);
    box-shadow: var(--ds-shadow-sm);
}

.ds-brand-copy { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.ds-brand-copy strong { font-size: var(--ds-font-size-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-brand-copy small { color: var(--ds-text-muted); font-size: var(--ds-font-size-xs); letter-spacing: 0.08em; }

.ds-sidebar__section { display: flex; flex-direction: column; gap: 2px; }
.ds-sidebar__label {
    padding: var(--ds-space-4) var(--ds-space-3) var(--ds-space-1);
    color: var(--ds-text-subtle);
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
    letter-spacing: 0.06em;
}

.ds-nav-link {
    display: flex;
    align-items: center;
    gap: var(--ds-space-3);
    padding: 0.62rem 0.75rem;
    border-radius: var(--ds-radius-sm);
    color: var(--ds-text-muted);
    font-size: var(--ds-font-size-sm);
    font-weight: var(--ds-font-weight-medium);
    white-space: nowrap;
    transition: background var(--ds-duration-fast) var(--ds-ease-standard),
                color var(--ds-duration-fast) var(--ds-ease-standard);
}
.ds-nav-link:hover { background: var(--ds-surface-hover); color: var(--ds-text-strong); text-decoration: none; }
.ds-nav-link.is-active { background: var(--ds-surface-active); color: var(--ds-brand-700); font-weight: var(--ds-font-weight-bold); }
.ds-nav-link__icon { flex: 0 0 auto; width: 20px; height: 20px; }
.ds-nav-link__badge {
    margin-inline-start: auto;
    background: var(--ds-brand-100);
    color: var(--ds-brand-700);
    border-radius: var(--ds-radius-pill);
    padding: 0 0.45rem;
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
}

.ds-app[data-sidebar="collapsed"] .ds-sidebar__label,
.ds-app[data-sidebar="collapsed"] .ds-nav-link__text,
.ds-app[data-sidebar="collapsed"] .ds-brand-copy,
.ds-app[data-sidebar="collapsed"] .ds-nav-link__badge { display: none; }
.ds-app[data-sidebar="collapsed"] .ds-nav-link { justify-content: center; }

.ds-sidebar__footer { margin-top: auto; padding: var(--ds-space-3); }

/* ---------- Main column ---------- */
.ds-main { display: flex; flex-direction: column; min-width: 0; }

.ds-header {
    position: sticky;
    top: 0;
    z-index: var(--ds-z-header);
    display: flex;
    align-items: center;
    gap: var(--ds-space-3);
    min-height: var(--ds-header-height);
    padding: 0 var(--ds-space-6);
    background: var(--ds-surface-header);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--ds-border-subtle);
}

.ds-header__title { display: flex; flex-direction: column; min-width: 0; }
.ds-header__title strong { font-size: var(--ds-font-size-md); color: var(--ds-text-strong); }
.ds-header__spacer { flex: 1 1 auto; }

.ds-icon-btn {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--ds-radius-sm);
    background: transparent;
    color: var(--ds-text-muted);
    cursor: pointer;
    transition: background var(--ds-duration-fast) var(--ds-ease-standard),
                color var(--ds-duration-fast) var(--ds-ease-standard);
}
.ds-icon-btn:hover { background: var(--ds-surface-hover); color: var(--ds-text-strong); }
.ds-icon-btn svg { width: 20px; height: 20px; }

.ds-content {
    flex: 1 1 auto;
    padding: var(--ds-space-6);
    min-width: 0;
}
.ds-content__inner { width: min(var(--ds-content-max), 100%); margin-inline: auto; }

/* ---------- Breadcrumb ---------- */
.ds-breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); font-size: var(--ds-font-size-sm); }
.ds-breadcrumb a { color: var(--ds-text-muted); }
.ds-breadcrumb a:hover { color: var(--ds-brand-600); }
.ds-breadcrumb__current { color: var(--ds-text-strong); font-weight: var(--ds-font-weight-semibold); }
.ds-breadcrumb__sep { color: var(--ds-text-subtle); user-select: none; }

/* ---------- Page heading ---------- */
.ds-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--ds-space-4);
    margin-bottom: var(--ds-space-5);
}
.ds-page-head h1 { margin-block: 0.15rem 0.3rem; }
.ds-page-head p { color: var(--ds-text-muted); font-size: var(--ds-font-size-sm); }

/* ---------- Footer ---------- */
.ds-footer {
    border-top: 1px solid var(--ds-border-subtle);
    padding: var(--ds-space-4) var(--ds-space-6);
    color: var(--ds-text-muted);
    font-size: var(--ds-font-size-xs);
}
.ds-footer__inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--ds-space-3); width: min(var(--ds-content-max), 100%); margin-inline: auto; }

/* ---------- Mobile sidebar ---------- */
.ds-sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--ds-surface-overlay);
    z-index: calc(var(--ds-z-sidebar) - 1);
    animation: ds-fade-in var(--ds-duration-fast) var(--ds-ease-standard) both;
}

@media (max-width: 1024px) {
    .ds-app { grid-template-columns: minmax(0, 1fr); }
    .ds-sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        width: var(--ds-sidebar-width);
        transform: translateX(100%);
        transition: transform var(--ds-duration-base) var(--ds-ease-standard);
        box-shadow: var(--ds-shadow-lg);
    }
    .ds-app[data-mobile-nav="open"] .ds-sidebar { transform: translateX(0); }
    .ds-app[data-mobile-nav="open"] .ds-sidebar-scrim { display: block; }
    .ds-header { padding-inline: var(--ds-space-4); }
    .ds-content { padding: var(--ds-space-4); }
}

/* ==========================================================================
   Legacy compatibility: old app-header / admin shell render inside new shell
   ========================================================================== */
.app-header { display: none; }

.admin-shell { display: block; }
.admin-content { min-width: 0; }

/* Admin sub-navigation becomes a horizontal chip bar under the header */
.admin-nav {
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: var(--ds-space-2);
    padding: var(--ds-space-2);
    margin-bottom: var(--ds-space-5);
    background: var(--ds-surface-base);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--ds-radius-md);
    overflow-x: auto;
}
.admin-nav a {
    padding: 0.45rem 0.8rem;
    border-radius: var(--ds-radius-pill);
    color: var(--ds-text-muted);
    font-size: var(--ds-font-size-sm);
    white-space: nowrap;
}
.admin-nav a:hover, .admin-nav a.active { background: var(--ds-surface-active); color: var(--ds-brand-700); text-decoration: none; }
.admin-nav .group-label { display: none; }

.public-shell { display: flex; flex-direction: column; min-height: 100vh; }

.ds-skip-link { position: absolute; top: -120px; right: 1rem; z-index: 10000; background: #0F2A43; color: #fff; padding: 0.6rem 1.1rem; border-radius: 0.6rem; font-weight: 700; transition: top 0.15s ease; }
.ds-skip-link:focus { top: 1rem; outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- Responsive hardening (admin shell / mobile header) ---------- */
@media (min-width: 1025px) {
    [data-mobile-nav-toggle] { display: none; }
}
@media (max-width: 1024px) {
    [data-sidebar-toggle] { display: none; }
    .ds-sidebar { width: min(var(--ds-sidebar-width), 86vw); }
}
@media (max-width: 860px) {
    .ds-header { flex-wrap: nowrap; gap: var(--ds-space-2); padding-inline: var(--ds-space-3); }
    .ds-header__title { flex: 1 1 auto; min-width: 0; }
    .ds-header__spacer { display: none; }
    .ds-search { display: none; }
    .ds-header .ds-icon-btn { width: 36px; height: 36px; }
    .ds-header .ds-avatar { width: 32px; height: 32px; }
    .ds-breadcrumb { flex-wrap: nowrap; overflow: hidden; }
    .ds-breadcrumb a, .ds-breadcrumb__current { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .ds-page-head { gap: var(--ds-space-3); }
    .ds-page-head h1 { font-size: var(--ds-font-size-xl); }
}
@media (max-width: 560px) {
    .ds-content { padding: var(--ds-space-3); }
    .ds-card__body { padding: var(--ds-space-4); }
    .ds-header__title .ds-breadcrumb a:first-child,
    .ds-header__title .ds-breadcrumb__sep:first-of-type { display: none; }
    .ds-page-head .ds-cluster { width: 100%; justify-content: space-between; }
    .ds-page-head .ds-cluster .btn { flex: 1 1 auto; text-align: center; }
    .ds-stat__value { font-size: var(--ds-font-size-xl); }
    .ds-table th, .ds-table td { padding: 0.5rem; font-size: var(--ds-font-size-xs); }
    .ds-footer { padding-inline: var(--ds-space-3); }
}
