/* Application shell: topbar + sidebar + content. Mobile-first, sidebar
   collapses to an offcanvas drawer below the tablet breakpoint. */

.app-shell {
    min-height: 100vh;
    display: flex;
}

/* ---------- Sidebar ----------
 * Phase 13 internal-UI reference: a dark navy sidebar, deliberately using
 * the --sidebar-* tokens (tokens.css) instead of --surface/--text, so it
 * reads the same across all 8 color x 4 visual theme combinations — only
 * the active-item highlight and icon accents pull from --primary. */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transition: transform var(--duration-base) var(--ease-standard);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5);
    border-bottom: 1px solid var(--sidebar-border);
    height: var(--topbar-height);
}
.sidebar-brand .brand-mark {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-bold);
    font-size: var(--text-sm);
    flex-shrink: 0;
}
.sidebar-brand .brand-text { font-weight: var(--font-semibold); font-size: var(--text-sm); line-height: 1.3; color: var(--sidebar-text-strong); }
.sidebar-brand .brand-text small { display: block; color: var(--sidebar-text); font-weight: var(--font-normal); font-size: var(--text-xs); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--space-3); }
.sidebar-section {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--sidebar-text);
    opacity: 0.7;
    padding: var(--space-4) var(--space-3) var(--space-2);
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0.6rem var(--space-3);
    border-radius: var(--radius-md);
    color: var(--sidebar-text);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    margin-bottom: 2px;
    transition: background-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.sidebar-link:hover { background: var(--sidebar-bg-elevated); color: var(--sidebar-text-strong); text-decoration: none; }
.sidebar-link.is-active { background: var(--primary); color: var(--sidebar-active-text); }
.sidebar-link .icon { width: 1.1rem; height: 1.1rem; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-link .icon svg { width: 100%; height: 100%; }
.sidebar-link.is-disabled { color: var(--sidebar-text); opacity: 0.4; cursor: not-allowed; }
.sidebar-link.is-disabled:hover { background: none; }

.sidebar-footer {
    padding: var(--space-3);
    border-top: 1px solid var(--sidebar-border);
}
.sidebar-footer .sidebar-link { color: var(--sidebar-text); margin-bottom: 0; }
.sidebar-footer .sidebar-link:hover { background: var(--sidebar-bg-elevated); color: var(--danger); }
.sidebar-footer form { margin: 0; }
.sidebar-footer button.sidebar-link {
    width: 100%;
    background: none;
    border: none;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 45;
    opacity: 0;
    transition: opacity var(--duration-base) var(--ease-standard);
}

/* ---------- Topbar ---------- */
.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-5);
    gap: var(--space-4);
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: var(--space-2);
    border-radius: var(--radius-sm);
}
.topbar-menu-btn:hover { background: var(--border-subtle); }
.topbar-menu-btn .icon svg,
.topbar-menu-btn svg { width: 1.35rem; height: 1.35rem; }
.topbar-identity { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.topbar-identity .icon { width: 2rem; height: 2rem; border-radius: var(--radius-md); background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.topbar-identity .icon svg { width: 1.15rem; height: 1.15rem; }
.topbar-identity-text { min-width: 0; }
.topbar-title { font-weight: var(--font-semibold); font-size: var(--text-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-subtitle { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.topbar-notify {
    position: relative;
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
}
.topbar-notify:hover { background: var(--border-subtle); color: var(--text); }
.topbar-notify svg { width: 1.2rem; height: 1.2rem; }
.topbar-notify .notify-dot {
    position: absolute;
    top: 4px;
    right: 5px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--surface);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
}
.topbar-user:hover { background: var(--border-subtle); }
.topbar-user .avatar {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
    flex-shrink: 0;
}
.topbar-user-text { text-align: left; line-height: 1.25; }
.topbar-user-name { font-size: var(--text-sm); font-weight: var(--font-medium); color: var(--text); }
.topbar-user-role { font-size: var(--text-xs); color: var(--text-muted); }

/* ---------- Content ---------- */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left var(--duration-base) var(--ease-standard);
}
.app-content {
    flex: 1;
    padding: var(--space-6) var(--space-8);
    width: 100%;
}

/* ---------- Sidebar collapse (Phase 14: desktop icon-only mode) ----------
 * Independent of the off-canvas drawer below — that's mobile/tablet-only
 * (<1024px, driven by .is-open); this is a DESKTOP-only (>=1024px)
 * preference, driven by .is-collapsed on the same [data-sidebar] element,
 * toggled by app.js and persisted in localStorage. Below 1024px the
 * collapsed state is ignored entirely (the drawer takes over), so the two
 * never conflict. */
.sidebar-collapse-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}
.sidebar-collapse-toggle:hover { background: var(--border-subtle); color: var(--text); }
/* Base icon is chevron-right; rotated 180° (pointing left, "collapse
   leftward") whenever the sidebar is currently expanded, and left
   un-rotated (pointing right, "expand rightward") once collapsed — see
   the >=1024px block below for the collapsed-state override. */
.sidebar-collapse-toggle svg { width: 1.2rem; height: 1.2rem; transition: transform var(--duration-base) var(--ease-standard); transform: rotate(180deg); }

/* Guarded to >=1024px only: below that, .is-collapsed must never affect
   the off-canvas drawer's own width/open-close behavior — a user who
   collapsed the sidebar on desktop and then opens the mobile drawer still
   gets the full, readable drawer, not an icon-only sliver. */
@media (min-width: 1024px) {
    .sidebar-collapse-toggle { display: inline-flex; }
    .sidebar.is-collapsed { width: var(--sidebar-width-collapsed); }
    .sidebar.is-collapsed .sidebar-brand { padding-left: var(--space-4); padding-right: var(--space-4); }
    .sidebar.is-collapsed .brand-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
    .sidebar.is-collapsed .sidebar-section { display: none; }
    /* sidebar-link text is a plain text node next to the .icon span, not
       its own element (see partials/sidebar.php) — font-size:0 hides it
       visually (the icon's own width/height are explicit rem units, not
       font-relative, so it stays full size) while leaving it in the DOM
       for assistive tech, same end result as a visually-hidden span
       without touching every link's markup individually. */
    .sidebar.is-collapsed .sidebar-link { justify-content: center; padding-left: 0; padding-right: 0; font-size: 0; }
    .sidebar.is-collapsed ~ .app-main { margin-left: var(--sidebar-width-collapsed); }
    .sidebar.is-collapsed ~ .app-main .sidebar-collapse-toggle svg { transform: none; }
}

/* ---------- Bottom navigation (mobile only) ---------- */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-list {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
}
.bottom-nav-list li {
    flex: 1;
    min-width: 0;
    display: flex;
}
.bottom-nav-link {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-2) 0;
    font-size: var(--text-xs);
    color: var(--text-muted);
    min-height: 44px;
    justify-content: center;
}
.bottom-nav-link .icon { font-size: var(--text-lg); }
.bottom-nav-link.is-active { color: var(--primary); }
.bottom-nav-link:hover { text-decoration: none; }

/* ---------- Auth (login) layout ---------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}
.auth-card {
    width: 100%;
    max-width: 24rem;
}
.auth-card .brand-mark {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-bold);
    margin: 0 auto var(--space-4);
}

/* ---------- Public result layout (Phase 8) ---------- */
.public-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--background);
}
.public-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.public-header .brand-mark {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-bold);
    flex-shrink: 0;
}
.public-content {
    flex: 1;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-5) var(--space-10);
}
@media (max-width: 639px) {
    .public-content { padding: var(--space-5) var(--space-4) var(--space-8); }
}

/* ---------- Settings tabs (Phase 13) ----------
 * Institusi and Tampilan are separate routes/pages, not a client-side
 * tab switch — each .settings-tab is a plain link; this is styling only. */
.settings-tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-6);
}
.settings-tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.settings-tab:hover { color: var(--text); text-decoration: none; }
.settings-tab.is-active { color: var(--primary); border-bottom-color: var(--primary); font-weight: var(--font-semibold); }

/* ---------- Settings two-column layout (institution / appearance) ---------- */
.settings-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--space-6);
    align-items: start;
}
.settings-preview { position: sticky; top: calc(var(--topbar-height) + var(--space-4)); }
.settings-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

@media (max-width: 899px) {
    .settings-layout { grid-template-columns: 1fr; }
    .settings-preview { position: static; }
}
@media (max-width: 479px) {
    .settings-grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
    .sidebar {
        transform: translateX(-100%);
        width: min(var(--sidebar-width), 85vw);
    }
    .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-backdrop.is-open { display: block; opacity: 1; }
    .app-main { margin-left: 0; }
    .topbar-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
}

@media (max-width: 639px) {
    .app-content { padding: var(--space-4) var(--space-4) calc(var(--space-4) + 64px); }
    .bottom-nav { display: block; }
    .page-header h1 { font-size: var(--text-xl); }
}

@media (min-width: 640px) and (max-width: 1023px) {
    .app-content { padding: var(--space-5); }
}
