html,
body {
    height: 100%;
    margin: 0;
}

.app-layout {
    height: 100%;
    min-height: 100vh;
    overflow: hidden;
}

html.is-embed .app-layout {
    min-height: 0;
}

.app-sidebar {
    width: 16rem;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
}

.app-sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.app-sidebar-brand {
    padding: 1.25rem;
    border-bottom: 1px solid #e2e8f0;
}

.app-sidebar-logo {
    font-size: 1.125rem;
    font-weight: 600;
    color: #0f172a;
}

.app-sidebar-tagline {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: #94a3b8;
}

.app-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.app-nav-section-top {
    margin-top: 0;
    margin-bottom: 0;
    padding-bottom: 0;
}

.app-nav-link-top {
    margin-bottom: 0;
}

.app-nav-section {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    margin-bottom: 0;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: #475569;
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
}

.app-nav-link:hover {
    background: #f8fafc;
    color: #0f172a;
}

.app-nav-link.is-active {
    background: #eff6ff;
    color: #2563eb;
    font-weight: 500;
}

.app-nav-icon {
    width: 1.125rem;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.8125rem;
    opacity: 0.85;
}

.app-nav-dot {
    margin-left: auto;
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 9999px;
    background: #2563eb;
    flex-shrink: 0;
}

.app-nav-subheader {
    padding: 0.5rem 0.75rem 0.25rem;
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #475569;
}

.app-nav-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    margin-bottom: 0;
}

.app-nav-group-toggle {
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    line-height: inherit;
}

.app-nav-group.is-active > .app-nav-group-toggle {
    color: #2563eb;
    font-weight: 500;
}

.app-nav-chevron {
    margin-left: auto;
    font-size: 0.75rem;
    color: #94a3b8;
    transition: transform 0.15s ease;
}

.app-nav-group-toggle:hover {
    background: #f8fafc;
    color: #0f172a;
}

.app-nav-group.is-expanded .app-nav-chevron {
    transform: rotate(0deg);
}

.app-nav-group:not(.is-expanded) .app-nav-chevron {
    transform: rotate(-90deg);
}

.app-nav-children {
    display: none;
    margin-top: 0;
    padding-left: 0.5rem;
    border-left: 1px solid #e2e8f0;
    margin-left: 1.125rem;
    flex-direction: column;
    gap: 0.375rem;
}

.app-nav-group.is-expanded .app-nav-children {
    display: flex;
}

.app-nav-link-child {
    font-size: 0.875rem;
}

.app-sidebar-footer {
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
}

.app-sidebar-user-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #334155;
}

.app-sidebar-credits {
    margin-top: 0;
    padding: 0.625rem 0.75rem;
    border-radius: 0.625rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.app-sidebar-credits-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.app-sidebar-credits-label {
    color: #64748b;
    font-weight: 500;
}

.app-sidebar-credits-value {
    color: #0f172a;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.app-sidebar-credits-reset {
    margin-top: 0.375rem;
    font-size: 0.6875rem;
    color: #94a3b8;
}

.app-sidebar-user-plan {
    margin-top: 0.625rem;
    font-size: 0.75rem;
    color: #94a3b8;
}

.app-sidebar-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.75rem;
    background: #0f172a;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 500;
}

.app-sidebar-status:first-child {
    margin-top: 0;
}

.app-status-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 9999px;
    background: #34d399;
    flex-shrink: 0;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-subnav {
    display: flex;
    gap: 0.25rem;
    padding: 0 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
    overflow-x: auto;
}

.app-subnav-link {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: #64748b;
    border: none;
    background: transparent;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}

.app-subnav-link:hover {
    color: #0f172a;
}

.app-subnav-link.is-active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 500;
}

/* Documentation link (header, left of account menu) */
.app-header-docs-btn {
    display: inline-flex;
    align-items: center;
    padding: 0.4375rem 0.875rem;
    border: 1px solid #e2e8f0;
    border-radius: 9999px;
    background: #fff;
    color: #334155;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.app-header-docs-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
}

.app-header-docs-btn.is-active {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #2563eb;
}

/* Account menu (header, top-right) */
.app-account-menu {
    position: relative;
    flex-shrink: 0;
}

.app-account-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.625rem 0.375rem 0.375rem;
    border: 1px solid #e2e8f0;
    border-radius: 9999px;
    background: #fff;
    color: #0f172a;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    text-decoration: none;
    line-height: 1.25;
}

.app-account-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.app-account-btn--ghost {
    border-radius: 0.5rem;
    padding: 0.5rem 0.875rem;
}

.app-account-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 9999px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.app-account-label {
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-account-chevron {
    font-size: 0.625rem;
    color: #94a3b8;
    transition: transform 0.15s;
}

.app-account-menu.is-open .app-account-chevron {
    transform: rotate(180deg);
}

.app-account-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.375rem);
    right: 0;
    min-width: 14rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.12), 0 4px 6px -4px rgba(15, 23, 42, 0.08);
    z-index: 50;
    overflow: hidden;
}

.app-account-menu.is-open .app-account-dropdown {
    display: block;
}

.app-account-dropdown-head {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    background: #f8fafc;
}

.app-account-dropdown-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: #0f172a;
}

.app-account-dropdown-email {
    margin-top: 0.125rem;
    font-size: 0.75rem;
    color: #64748b;
    word-break: break-all;
}

.app-account-dropdown-plan {
    margin-top: 0.375rem;
    font-size: 0.6875rem;
    font-weight: 500;
    color: #2563eb;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.app-account-dropdown-item {
    display: block;
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    color: #334155;
    text-align: left;
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.12s;
}

.app-account-dropdown-item:hover {
    background: #f1f5f9;
}

.app-account-dropdown-item--danger {
    color: #dc2626;
    border-top: 1px solid #f1f5f9;
}

.app-account-dropdown-item--danger:hover {
    background: #fef2f2;
}

@media (max-width: 640px) {
    .app-account-label {
        display: none;
    }

    .app-account-btn {
        padding: 0.25rem;
        border-radius: 9999px;
    }
}
